Skip to content

Commit 0977bc0

Browse files
committed
fix(config):修复require引用问题
1 parent 13925cb commit 0977bc0

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@
3737
"build:plugins": "lerna exec --scope @uiw-admin/plugins -- tsbb build --no-esm",
3838
"watch:plugins": "lerna exec --scope @uiw-admin/plugins -- tsbb watch",
3939
"-----config-----": "----------",
40-
"build:config": "lerna exec --scope @uiw-admin/models -- tsbb build",
41-
"watch:config": "lerna exec --scope @uiw-admin/models -- tsbb watch",
40+
"build:config": "lerna exec --scope @uiw-admin/config -- tsbb build",
41+
"watch:config": "lerna exec --scope @uiw-admin/config -- tsbb watch",
4242
"-----create-uiw-admin-----": "----------",
4343
"build:create": "lerna exec --scope create-uiw-admin -- npm run build",
4444
"-----------": "--------------",

packages/config/src/index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import webpack from 'webpack';
22
import { LoaderConfOptions, WebpackConfiguration } from 'kkt';
33
import path from 'path';
4-
import { transformationDefineString } from './uitls';
4+
import { transformationDefineString, getFunDefault } from './uitls';
55

66
export * from 'kkt';
77

@@ -142,10 +142,10 @@ export default (props: ConfigProps) => {
142142
if (newLoader) {
143143
newLoader.forEach((fun) => {
144144
if (typeof fun === 'string') {
145-
conf = require(fun)(conf, env, options);
145+
conf = getFunDefault(fun)(conf, env, options);
146146
} else if (Array.isArray(fun)) {
147147
const [paths, rest] = fun;
148-
conf = require(paths)(conf, env, { ...options, ...rest });
148+
conf = getFunDefault(paths)(conf, env, { ...options, ...rest });
149149
} else if (typeof fun === 'function') {
150150
conf = fun(conf, env, options);
151151
} else if (fun && fun.loader) {
@@ -159,11 +159,11 @@ export default (props: ConfigProps) => {
159159
if (Array.isArray(newPlugins)) {
160160
newPlugins.forEach((pathArr) => {
161161
if (typeof pathArr === 'string') {
162-
const Cls = require(pathArr);
162+
const Cls = getFunDefault(pathArr);
163163
plugin.push(new Cls());
164164
} else if (Array.isArray(pathArr)) {
165165
const [paths, rest] = pathArr;
166-
const Cls = require(paths);
166+
const Cls = getFunDefault(paths);
167167
plugin.push(new Cls(rest));
168168
} else {
169169
plugin.push(pathArr);

packages/config/src/uitls.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,11 @@ export const transformationDefineString = (obj: Record<string, any>) => {
55
});
66
return result;
77
};
8+
9+
export const getFunDefault = (path?: string) => {
10+
if (path) {
11+
const fun = require(path);
12+
return fun.default || fun;
13+
}
14+
return () => {};
15+
};

0 commit comments

Comments
 (0)