Skip to content

Commit b2809f5

Browse files
committed
Don't make @babel/preset-env force all transforms in prod
1 parent 9a3cb43 commit b2809f5

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

fixtures/js/async_function.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
async function foo() {
2+
console.log('foo');
3+
}
4+
5+
foo().then(() => {
6+
console.log('bar');
7+
});

lib/loaders/babel.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ module.exports = {
4242
// https://babeljs.io/docs/en/babel-preset-env#modules
4343
modules: false,
4444
targets: {},
45-
forceAllTransforms: webpackConfig.isProduction(),
4645
useBuiltIns: webpackConfig.babelOptions.useBuiltIns,
4746
corejs: webpackConfig.babelOptions.corejs,
4847
};

test/functional.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1148,6 +1148,41 @@ module.exports = {
11481148
});
11491149
});
11501150

1151+
it('Babel does not force transforms if they are not needed', (done) => {
1152+
const cwd = process.cwd();
1153+
after(() => {
1154+
process.chdir(cwd);
1155+
});
1156+
1157+
const appDir = testSetup.createTestAppDir();
1158+
process.chdir(appDir);
1159+
1160+
fs.writeFileSync(
1161+
path.join(appDir, 'package.json'),
1162+
1163+
// Chrome 55 supports async and arrow functions
1164+
'{"browserslist": "Chrome 55"}'
1165+
);
1166+
1167+
const config = createWebpackConfig('www/build', 'prod');
1168+
config.setPublicPath('/build');
1169+
config.addEntry('async', './js/async_function.js');
1170+
config.configureBabel(null, {
1171+
useBuiltIns: 'usage',
1172+
corejs: 3,
1173+
});
1174+
1175+
testSetup.runWebpack(config, async(webpackAssert) => {
1176+
webpackAssert.assertOutputFileContains(
1177+
'async.js',
1178+
'async function(){console.log("foo")}().then(()=>{console.log("bar")})'
1179+
);
1180+
1181+
done();
1182+
});
1183+
});
1184+
1185+
11511186
it('When enabled, react JSX is transformed!', (done) => {
11521187
const config = createWebpackConfig('www/build', 'dev');
11531188
config.setPublicPath('/build');

0 commit comments

Comments
 (0)