我已经写了我的webpack.config文件,但是当我从终端运行webpack时,我得到一个错误说:
错误: Webpack配置 /home/likono/learn/yak-yik/config/webpack/development.js未找到, 请运行'捆绑exec rails webpacker:install'安装webpacker 使用默认配置或为您的自定义添加缺少的配置文件 环境。
我还在全球范围内安装了webpack。 这是我的webpack.config.js
var webpack = require("webpack");
var path = require("path");
module.exports = {
entry: {
app: './src/app.js'
},
output: {
filename: 'public/build/bundle.js',
sourceMapFilename: 'public/build/bundle.map'
},
devtool: '#source-map',
module: {
loaders: [
{ test: /\.jsx?$/,
exclude: /(node_modules)/,
loader: 'babel',
query: {
presets: ['react', 'es2015']
}
}
]
}
};
的package.json
{
"name": "yak-yik",
"version": "0.0.0",
"private": true,
"scripts": {
"start": "node ./bin/www"
},
"dependencies": {
"body-parser": "~1.18.2",
"cookie-parser": "~1.4.3",
"debug": "~2.6.9",
"express": "~4.15.5",
"hjs": "~0.0.6",
"mongoose": "^4.13.4",
"morgan": "~1.9.0",
"nodemon": "^1.12.1",
"react": "^16.1.1",
"react-dom": "^16.1.1",
"serve-favicon": "~2.4.5"
},
"devDependencies": {
"babel-core": "^6.26.0",
"babel-loader": "^7.1.2",
"babel-preset-es2015": "^6.24.1",
"babel-preset-react": "^6.24.1",
"webpack": "^3.8.1"
}
}
答案 0 :(得分:0)
我发现上面的配置存在一些问题。根据{{3}},使用-loader
时不再允许省略loaders
后缀。您需要指定babel-loader
而不是babel
。此外,{@ 1}}已弃用,建议您使用babel-preset-es2015
。我无法重现你的错误(我有一些不同的错误),但是让我的webpack通过将babel-preset-env
从loader
更改为babel
而将文件捆绑在我身边,并且babel-loader
已将presets
更改为es2015
env
,如下所示:
<强> webpack.config.js 强>
webpack.config.js
我还将{
test: /\.jsx?$/,
exclude: /(node_modules)/,
loader: 'babel-loader',
query: {
presets: ['react', 'env']
}
}
文件更改为使用package.json
而不是babel-preset-env
。
<强> package.js 强>
"babel-preset-es2015": "^6.24.1"
请试一试,如果它能解决您的问题,请告诉我。