Skip to content

Commit

Permalink
avoid duplicating nullish-coalescing and optional-chaining plugins
Browse files Browse the repository at this point in the history
Fix #453.
  • Loading branch information
ef4 committed Sep 15, 2020
1 parent a8ce70b commit 3d48872
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
6 changes: 3 additions & 3 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@
{
"type": "node",
"request": "launch",
"name": "Build fastboot-app",
"program": "${workspaceFolder}/node_modules/.bin/ember",
"cwd": "${workspaceFolder}/test-packages/fastboot-app",
"name": "Build sample",
"program": "/Users/edward/hacking/sample/node_modules/.bin/ember",
"cwd": "/Users/edward/hacking/sample",
"args": ["build"],
"env": {
"JOBS": "1"
Expand Down
14 changes: 12 additions & 2 deletions packages/webpack/src/ember-webpack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -497,13 +497,23 @@ function babelLoaderOptions(majorVersion: 6 | 7, variant: Variant, appBabelConfi
}
// webpack uses acorn and acorn doesn't parse these features yet, so we
// always tranpile them away regardless of what preset-env is doing
options.plugins.push(require.resolve('@babel/plugin-proposal-optional-chaining'));
options.plugins.push(require.resolve('@babel/plugin-proposal-nullish-coalescing-operator'));
if (!options.plugins.some(pluginMatches(/@babel\/plugin-proposal-optional-chaining/))) {
options.plugins.push(require.resolve('@babel/plugin-proposal-optional-chaining'));
}
if (!options.plugins.some(pluginMatches(/@babel\/plugin-proposal-nullish-coalescing-operator/))) {
options.plugins.push(require.resolve('@babel/plugin-proposal-nullish-coalescing-operator'));
}
}
return {
loader: majorVersion === 6 ? 'babel-loader-7' : 'babel-loader-8',
options,
};
}

function pluginMatches(pattern: RegExp) {
return function(plugin: string | [string] | undefined) {
return plugin && pattern.test(Array.isArray(plugin) ? plugin[0] : plugin);
};
}

export { Webpack };

0 comments on commit 3d48872

Please sign in to comment.