Skip to content

Commit 8360f1c

Browse files
committed
bug #627 Allow to overwrite pre-defined aliases using addAliases() (Lyrkan)
This PR was merged into the master branch. Discussion ---------- Allow to overwrite pre-defined aliases using addAliases() Currently pre-defined aliases (used by `vue` and `preact-compat`) are added after the ones from `Encore.addAliases(...)`, which prevents overwriting them using this method. It makes more sense to change that order so aliases from `Encore.addAliases(...)` are always added last (fixes #625). Commits ------- 29d1cb4 Allow to overwrite pre-defined aliases using addAliases()
2 parents 5640271 + 29d1cb4 commit 8360f1c

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)