diff --git a/.vscode/launch.json b/.vscode/launch.json index 77330e222..2e724d08b 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -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" diff --git a/packages/webpack/src/ember-webpack.ts b/packages/webpack/src/ember-webpack.ts index 05739b959..0ad42979d 100644 --- a/packages/webpack/src/ember-webpack.ts +++ b/packages/webpack/src/ember-webpack.ts @@ -497,8 +497,12 @@ 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', @@ -506,4 +510,10 @@ function babelLoaderOptions(majorVersion: 6 | 7, variant: Variant, appBabelConfi }; } +function pluginMatches(pattern: RegExp) { + return function(plugin: string | [string] | undefined) { + return plugin && pattern.test(Array.isArray(plugin) ? plugin[0] : plugin); + }; +} + export { Webpack };