[英]ReactJS error You may need an appropriate loader to handle this file type
[英]You may need an appropriate loader to handle this file type-error
您需要为js文件配置babel-loader才能进行翻译
webpack配置片段:
{
test: /\.js$/,
exclude: /node_modules/,
use: [
'babel-loader'
]
}
内部模块规则。
还要在项目主目录中添加.babelrc
文件,内容如下
{
"presets" : [
"latest"
]
}
要使用ecmascript-6
您需要(1)添加具有以下预设的.babelrc
文件
{
"presets": [ "es2015" ]
}
es2015
是您需要的特定设备。
然后(2)将您的webpack配置为包括
module.exports = {
...,
loaders : [
{ test: /\.js$/, exclude: /(node_modules)/, loader: 'babel-loader' }
]
}
仅通过npm安装装载程序是不够的。 您必须在webpack中配置该加载程序。
在您的webpack.config.js
添加以下webpack.config.js
loaders: [
{
test: /\.js$/,
exclude: /(node_modules|bower_components)/,
loader: 'babel-loader',
query: {
presets: ['es2015']
}
}
]
上面的代码意味着,只要找到与\\.js$
模式匹配的文件(以.js结尾的文件),就会使用babel-loader。 (您已经将babel-loader安装到了依赖项中。
您也可以使用loader: 'babel'
代替`loader:'babel-loader'。 一样的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.