Skip to content

Commit 29d1cb4

Browse files
committed
Allow to overwrite pre-defined aliases using addAliases()
1 parent 5640271 commit 29d1cb4

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

lib/config-generator.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ class ConfigGenerator {
9696

9797
config.resolve = {
9898
extensions: ['.wasm', '.mjs', '.js', '.json', '.jsx', '.vue', '.ts', '.tsx'],
99-
alias: Object.assign({}, this.webpackConfig.aliases)
99+
alias: {}
100100
};
101101

102102
if (this.webpackConfig.useVueLoader) {
@@ -108,6 +108,8 @@ class ConfigGenerator {
108108
config.resolve.alias['react-dom'] = 'preact-compat';
109109
}
110110

111+
Object.assign(config.resolve.alias, this.webpackConfig.aliases);
112+
111113
config.externals = [...this.webpackConfig.externals];
112114

113115
return config;

test/config-generator.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,28 @@ describe('The config-generator function', () => {
453453
'testB': 'src/testB'
454454
});
455455
});
456+
457+
it('with addAliases() that overwrites pre-defined aliases', () => {
458+
const config = createConfig();
459+
config.outputPath = '/tmp/output/public-path';
460+
config.publicPath = '/public-path';
461+
config.enableVueLoader(); // Adds the 'vue$' alias
462+
config.enablePreactPreset({ preactCompat: true }); // Adds the 'react' and 'react-dom' aliases
463+
config.addAliases({
464+
'foo': 'bar',
465+
'vue$': 'new-vue$',
466+
'react-dom': 'new-react-dom',
467+
});
468+
469+
const actualConfig = configGenerator(config);
470+
471+
expect(actualConfig.resolve.alias).to.deep.equals({
472+
'foo': 'bar',
473+
'vue$': 'new-vue$',
474+
'react-dom': 'new-react-dom',
475+
'react': 'preact-compat' // Keeps predefined aliases that are not overwritten
476+
});
477+
});
456478
});
457479

458480
describe('addExternals() adds new externals', () => {

0 commit comments

Comments
 (0)