Socrates
Socrates

Reputation: 9604

Use Webpack to output es6?

Is there a way to use Webpack to bundle all the JavaScript files and output the resulting bundle.js as an es6 file, and not to es5? So, it is Webpack's job to bundle, but is it actually Webpack's job to convert to es6? Or is that the job of some Webpack loader? Or would I have to use babel for that?

Upvotes: 18

Views: 17094

Answers (2)

Wis
Wis

Reputation: 514

webpack 5 can generate both ES5 and ES6/ES2015 code.

The default configuration will generate ES2015. If you need to support older browsers (like IE11), you can set output.ecmaVersion: 5.

https://webpack.js.org/migrate/5/#turn-off-es2015-syntax-in-runtime-code-if-necessary

Upvotes: 9

lukas-reineke
lukas-reineke

Reputation: 3322

Webpack still can't do this. There is an open ticket here https://github.com/webpack/webpack/issues/2933

For now, if you want to bundle es6 the most promising solution seems to be rollup

This article is also linked in the discussion on GitHub and provides a pretty good overview

https://medium.com/webpack/webpack-and-rollup-the-same-but-different-a41ad427058c

Upvotes: 3

Related Questions