问题
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