Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't make @babel/preset-env force all transforms in prod #612

Merged
merged 1 commit into from Aug 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 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');
Expand Down