简体   繁体   中英

Can I use Webpack in ES6 without using Babel?

Node now gives us the option of using.mjs files or setting "type": "module" . I would like to do that because it's 2021, ES6 is widespread and I'm writing my server-side code using ES6 modules.

But that means I can't use require() like we always did before. Ok then, I'll just use ES6's import .

Well nope, it doesn't seem that is officially supported for Webpack's config. All the old answers on StackOverflow are telling me I've got to use Babel for backwards compatibility. It seems like there should be a better solution by now.

Is there one?

I found the problem on my own. It was my fault, In 2021, Webpack can totally use ES6 for config and it can bundle up ES6 JS just fine as long as all your dependencies are cool with ES6. like @bigless said.

I just made an error in the config file. With node modules, we'd say something like module.exports = {... } . The ES6 equivalent is just export default {... } . I simply forgot to change it over.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM