Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to overwrite pre-defined aliases using addAliases() #627

Merged
merged 1 commit into from
Oct 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/config-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class ConfigGenerator {

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

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

Object.assign(config.resolve.alias, this.webpackConfig.aliases);

config.externals = [...this.webpackConfig.externals];

return config;
Expand Down
22 changes: 22 additions & 0 deletions test/config-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,28 @@ describe('The config-generator function', () => {
'testB': 'src/testB'
});
});

it('with addAliases() that overwrites pre-defined aliases', () => {
const config = createConfig();
config.outputPath = '/tmp/output/public-path';
config.publicPath = '/public-path';
config.enableVueLoader(); // Adds the 'vue$' alias
config.enablePreactPreset({ preactCompat: true }); // Adds the 'react' and 'react-dom' aliases
config.addAliases({
'foo': 'bar',
'vue$': 'new-vue$',
'react-dom': 'new-react-dom',
});

const actualConfig = configGenerator(config);

expect(actualConfig.resolve.alias).to.deep.equals({
'foo': 'bar',
'vue$': 'new-vue$',
'react-dom': 'new-react-dom',
'react': 'preact-compat' // Keeps predefined aliases that are not overwritten
});
});
});

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