Skip to content

Commit 0f23d03

Browse files
feat: Support export default from configuration files.
This changes adds a `require` wrapper to the `config` group that allows it to detect and return the default export of ES modules. This is useful when your configuration is a TS(X) file or something that is being transpiled by babel.
1 parent cb216fc commit 0f23d03

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

lib/groups/config.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,22 +41,30 @@ class ConfigGroup extends GroupHelper {
4141
};
4242
}
4343

44+
require(path) {
45+
const result = require(path);
46+
if (result && result.__esModule && result.default) {
47+
return result.default;
48+
}
49+
return result;
50+
}
51+
4452
requireConfig(configPath) {
4553
const { register } = this.args;
4654

4755
this.configOptions = (() => {
4856
if (register && register.length) {
4957
module.paths.unshift(resolve(process.cwd(), 'node_modules'));
5058
register.forEach(dep => {
51-
const isRelative = ["./", "../", ".\\", "..\\"].some(start => dep.startsWith(start));
59+
const isRelative = ['./', '../', '.\\', '..\\'].some(start => dep.startsWith(start));
5260
if (isRelative) {
5361
require(resolve(process.cwd(), dep));
5462
} else {
5563
require(dep);
5664
}
5765
});
5866
}
59-
return require(configPath);
67+
return this.require(configPath);
6068
})();
6169
}
6270

@@ -110,7 +118,7 @@ class ConfigGroup extends GroupHelper {
110118
const { merge } = this.args;
111119
if (merge) {
112120
const newConfigPath = this.resolveFilePath(merge, 'webpack.base');
113-
const newConfig = newConfigPath ? require(newConfigPath) : null;
121+
const newConfig = newConfigPath ? this.require(newConfigPath) : null;
114122
this.opts['options'] = require('webpack-merge')(this.opts['options'], newConfig);
115123
}
116124
}

0 commit comments

Comments
 (0)