作为标题。我想在我的webpack配置文件中使用ES6模块语法。目前,我得到了:
Diagnostics:
Cannot use import declarations in modules that export using CommonJS (module.exports = 'foo' or exports.bar = 'hi') [import/no-import-module-exports]
要在webpack.config.js
中使用ES6模块语法(中间不需要.babel.
(,请执行以下操作:
package.json
添加"type": "module"
- 在
webpack.config.js
中,将Node.jsmodule.exports
更改为export default
- 在
webpack.config.js
中,将CJS__dirname
、__filename
更改为path.dirname()
、import.meta.url
,并进行了一些修改