webpack.config.js:
let webpack = require('webpack');
let path = require('path');
module.exports = {
context:__dirname + '/src',
entry:"./js/index.js",
module:{
loaders:[
{
test: /\.js?$/,
exclude: /node_modules/,
loader:'babel-loader',
query:{
presets:['es2015','react']
}
}
]
},
output:{
path:__dirname + "/src",
filename:"bundle.js"
}
};
package.json:
{
"name": "test",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"antd": "^2.1.0",
"babel": "^5.8.23",
"babel-core": "^6.24.1",
"babel-loader": "^6.4.1",
"babel-preset-es2015": "^6.24.0",
"babel-preset-react": "^6.23.0",
"react": "^15.3.2",
"react-dom": "^15.3.2",
"webpack": "^2.4.1",
"webpack-dev-server": "^2.4.4"
}
}
webpack
配置没问题。报错应该是babel
query
那里有问题。第一种解决方法:
presets:['es2015','react']map(require.resolve)
第一种没解决,就把
query
删掉,在根目录下新建.babelrc
把query
这个json
对象放进去第二种也没解决的话,升级一下
babel
相关的插件的版本,重复上面的步骤。