Skip to content

Commit

Permalink
feat(builder): use jiti to load config (#4754)
Browse files Browse the repository at this point in the history
  • Loading branch information
chenjiahan authored Oct 8, 2023
1 parent 3473bee commit d90d83a
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 11 deletions.
7 changes: 7 additions & 0 deletions .changeset/five-suits-learn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@modern-js/builder': patch
---

feat(builder): use jiti to load config

feat(builder): 使用 jiti 来加载配置
4 changes: 2 additions & 2 deletions packages/builder/builder/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@
"dependencies": {
"@modern-js/builder-shared": "workspace:*",
"@modern-js/monorepo-utils": "workspace:*",
"@modern-js/node-bundle-require": "workspace:*",
"@modern-js/utils": "workspace:*",
"@svgr/webpack": "8.0.1",
"@swc/helpers": "0.5.1"
"@swc/helpers": "0.5.1",
"jiti": "^1.20.0"
},
"devDependencies": {
"@modern-js/builder-webpack-provider": "workspace:*",
Expand Down
6 changes: 3 additions & 3 deletions packages/builder/builder/src/cli/config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import jiti from 'jiti';
import { join } from 'path';
import { findExists } from '@modern-js/utils';
import { existsSync } from '@modern-js/utils/fs-extra';
import { bundleRequire } from '@modern-js/node-bundle-require';
import type { BuilderEntry, BuilderPlugin } from '@modern-js/builder-shared';
import type { BuilderConfig as WebpackBuilderConfig } from '@modern-js/builder-webpack-provider';
import type { BuilderConfig as RspackBuilderConfig } from '@modern-js/builder-rspack-provider';
Expand All @@ -22,8 +22,8 @@ export async function loadConfig(): Promise<BuilderConfig> {
const configFile = join(process.cwd(), 'builder.config.ts');

if (existsSync(configFile)) {
const mod = await bundleRequire(configFile);
return mod.default || mod;
const loadConfig = jiti(__filename, { interopDefault: true });
return loadConfig(configFile);
}

return {};
Expand Down
12 changes: 6 additions & 6 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d90d83a

Please sign in to comment.