ES6可以在webpack.config.js中本地使用吗? [英] Can ES6 be used natively in webpack.config.js?

查看:56
本文介绍了ES6可以在webpack.config.js中本地使用吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此答案:如何在webpack.config.js中使用ES6?
似乎暗示着转嫁步骤.

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

ES6可以本地使用吗?怎么样?

Can ES6 be used natively? How?

例如,我尝试在这里 require import 并收到以下错误

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

推荐答案

您应使用webpack-cli

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

要使用该标志,您必须安装babel-register. webpack --config-register babel-register --config ....

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

另一个选项是 esm .

Another option is esm.

这篇关于ES6可以在webpack.config.js中本地使用吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆