Can ES6 be used natively in webpack.config.js?

让人想犯罪 __ 提交于 2021-02-10 15:47:47

问题


This answer: How can I use ES6 in webpack.config.js?
seems to imply a transpilation step.

Can ES6 be used natively? How?

For example I tried to convert the simple example here from require to import and receive the following error

(function (exports, require, module, __filename, __dirname) { import path from 'path'
                                                                     ^^^^
SyntaxError: Unexpected identifier

回答1:


You should use webpack-cli --config-register (-r) to allow that.

To use that flag, you must have babel-register installed. webpack --config-register babel-register --config ....

Another option is esm.



来源:https://stackoverflow.com/questions/52146755/can-es6-be-used-natively-in-webpack-config-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!