webpack3.X配置babel-loader时报错
当我在配置babel-loader的时候出现了问题,已经安装了babel-loader
babel-core
babel-preset-es2015
babel-preset-reacr
babel-preset-env
我在本地和全局都安装了webpack
package.json
{
"name": "1",
"version": "1.0.0",
"description": "",
"main": "webpack.config.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"dev": "webpack-dev-server"
},
"author": "",
"license": "ISC",
"devDependencies": {
"babel-core": "^6.26.0",
"babel-env": "^2.4.1",
"babel-loader": "^7.1.2",
"babel-preset-es2015": "^6.24.1",
"babel-preset-react": "^6.24.1",
"html-webpack-plugin": "^2.30.1",
"uglifyjs-webpack-plugin": "^1.0.1",
"webpack": "^3.8.1"
}
}
核心问题
module: {
rules: [{
test: /\.(jsx|js)$/,
use: {
loader: 'babel-loader',
options: {
presets: ['es2015', 'react']
},
exclude: /node_modules/
}
}]
},
报错信息
webpack.config.js整体文件
const path = require('path');
const htmlplugin = require('html-webpack-plugin')
const uglify = require('uglifyjs-webpack-plugin');
module.exports = {
entry: {
a: './src/a.js',
},
output: {
path: path.resolve(__dirname, 'dist'),
filename: '[name].js',
},
module: {
rules: [{
test: /\.(jsx|js)$/,
use: {
loader: 'babel-loader',
options: {
presets: ['es2015', 'react']
},
exclude: /node_modules/
}
}]
},
plugins: [
new uglify(),
new htmlplugin({
minify: {
removeAttributeQuotes: true,
},
hash: true,
template: './src/index.html'
})
],
devServer: {
contentBase: path.resolve(__dirname, 'dist'),
host: '192.168.43.205',
compress: true,
port: 9999
},
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
exclude写在了use里面,应该是
推荐用.babelrc,webpack主目录下建一个.babelrc,
webpack
.babelrc
报错:webpack的config的api写错了。
问题:rules里的use写错了,它是个数组。exclude放在test同级。