【发布时间】:2015-11-26 12:12:13
【问题描述】:
我今天开始使用webpack,但在运行它时遇到了一些问题。
基本上我需要一个使用react & es6 的应用程序。您可以在下面看到错误:
webpack.config.js
var HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
entry: './app/app.js',
output: {
path: 'dist',
filename: 'bundle.js',
},
module: {
loaders: [
{
test: /\.js$/,
loader: 'babel',
query: {
stage: 0
},
include: __dirname + '/app'
},
]
},
plugins: [new HtmlWebpackPlugin({
template: __dirname + '/app/index.html',
hash: true,
filename: 'index.html',
inject: 'body'
})]
};
到目前为止,我尝试的是安装 es2015 并配置为
{
test: /\.jsx?$/,
loader: 'babel-loader',
exclude: /node_modules/,
query: {
presets: ['es2015']
}
}
但我仍然遇到同样的错误。
知道如何解决吗?
依赖关系
"dependencies": {
"react": "^0.14.0",
"react-dom": "^0.14.2",
"react-redux": "^4.0.0",
"webpack-dev-server": "^1.12.1"
},
"devDependencies": {
"babel-loader": "^5.3.2",
"history": "^1.13.0",
"html-webpack-plugin": "^1.6.2",
"webpack": "^1.12.2"
}
【问题讨论】:
-
你用的是什么版本的 babel?
-
@DominicTobias 我已经更新了问题,添加了我在
package.json中的依赖项 -
看看Link。在这种情况下,您需要像 es6 和 react 之类的 babel-presets 以及 babel-core npm 模块
标签: reactjs config webpack babeljs