这是我的package.json
:
"scripts": {
"start": "webpack-dev-server --hot --inline",
},
"license": "",
"devDependencies": {
"babel-core": "~6.4.5",
"babel-loader": "^6.2.1",
"css-loader": "^0.23.1",
"raw-loader": "~0.5.1",
"style-loader": "^0.13.0",
"webpack": "~1.12.12",
"webpack-dev-server": "~1.14.1"
},
"dependencies": {
"angular": "~1.4.9"
}
这是我的webpack.config.js
:
var path = require('path')
module.exports = {
context: path.resolve(__dirname,'public'),
entry: './entry.js',
resolve: {
root: [__dirname + "/public"]
},
output:{
path: path.resolve(__dirname, "public"),
filename:'bundle.js',
publicPath: '/public/'
},
module:{
loaders:[
{ test: path.join(__dirname,'public'),loader:'babel'},
{ test: /\.css$/, loader:'style!css'}
]
},
devtool: '#inline-source-map'
}
这是我的entry.js
:
document.write('webpack!')
import 'angular';
这是我得到的错误:
./public/entry.js中的错误模块解析失败: /home/guy/itay/Develop/webpack-tut/node_modules/babel-loader/index.js!/home/guy/itay/Develop/webpack-tut/public/entry.js 第3行:意外的令牌您可能需要一个合适的加载器来处理 这个文件类型。
| document.write('webpack!');
|
| import 'angular';
node version: 5.4.1,
npm version: 3.3.12
答案 0 :(得分:0)
我的问题是我使用了babel ^ 6.0.0并且我没有在我的加载器中设置presets选项,如下所示:
query: {
presets: ['es2015', 'stage-2']
}
有链接帮助我完成了这个: https://medium.com/@malyw/how-to-update-babel-5-x-6-x-d828c230ec53#.xn8bkagxz