diff --git a/fixtures/js/async_function.js b/fixtures/js/async_function.js new file mode 100644 index 00000000..f684caef --- /dev/null +++ b/fixtures/js/async_function.js @@ -0,0 +1,7 @@ +async function foo() { + console.log('foo'); +} + +foo().then(() => { + console.log('bar'); +}); diff --git a/lib/loaders/babel.js b/lib/loaders/babel.js index 6ed2e30b..0580d53c 100644 --- a/lib/loaders/babel.js +++ b/lib/loaders/babel.js @@ -42,7 +42,6 @@ module.exports = { // https://babeljs.io/docs/en/babel-preset-env#modules modules: false, targets: {}, - forceAllTransforms: webpackConfig.isProduction(), useBuiltIns: webpackConfig.babelOptions.useBuiltIns, corejs: webpackConfig.babelOptions.corejs, }; diff --git a/test/functional.js b/test/functional.js index 3cfd92ed..4fec7afd 100644 --- a/test/functional.js +++ b/test/functional.js @@ -1157,6 +1157,41 @@ module.exports = { }); }); + it('Babel does not force transforms if they are not needed', (done) => { + const cwd = process.cwd(); + after(() => { + process.chdir(cwd); + }); + + const appDir = testSetup.createTestAppDir(); + process.chdir(appDir); + + fs.writeFileSync( + path.join(appDir, 'package.json'), + + // Chrome 55 supports async and arrow functions + '{"browserslist": "Chrome 55"}' + ); + + const config = createWebpackConfig('www/build', 'prod'); + config.setPublicPath('/build'); + config.addEntry('async', './js/async_function.js'); + config.configureBabel(null, { + useBuiltIns: 'usage', + corejs: 3, + }); + + testSetup.runWebpack(config, async(webpackAssert) => { + webpackAssert.assertOutputFileContains( + 'async.js', + 'async function(){console.log("foo")}().then(()=>{console.log("bar")})' + ); + + done(); + }); + }); + + it('When enabled, react JSX is transformed!', (done) => { const config = createWebpackConfig('www/build', 'dev'); config.setPublicPath('/build');