Skip to content

Commit

Permalink
Don't make @babel/preset-env force all transforms in prod
Browse files Browse the repository at this point in the history
  • Loading branch information
Lyrkan committed Jul 15, 2019
1 parent 9a3cb43 commit bca161d
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
7 changes: 7 additions & 0 deletions fixtures/js/async_function.js
@@ -0,0 +1,7 @@
async function foo() {
console.log('foo');
}

foo().then(() => {
console.log('bar');
});
1 change: 0 additions & 1 deletion lib/loaders/babel.js
Expand Up @@ -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,
};
Expand Down
35 changes: 35 additions & 0 deletions test/functional.js
Expand Up @@ -1148,6 +1148,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 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');
Expand Down

0 comments on commit bca161d

Please sign in to comment.