运行以下Web包配置会给我带来大量错误,第一个错误就在下面。我只是不明白为什么它在web包内。
请注意;我正在使用Reactjs。
更新:当我执行webpack
而非webpack web pack.config.js
时,它可以正常运行。但我需要能够使用一个用于生产,一个用于开发吗?
你知道为什么吗?
webpack config:webpack.condig.js
var path = require('path');
var webpack = require('webpack');
module.exports = {
devtool: 'eval',
entry: path.resolve(__dirname, './app/main.js'),
output: {
path: path.join(__dirname, 'build'),
filename: 'bundle.js',
publicPath: '/app/'
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
new webpack.NoErrorsPlugin()
],
resolve: {
extensions: ['', '.js', '.jsx']
},
module: {
loaders: [
{ test: /\.css$/, loader: "style-loader!css-loader" },
{ test: /\.jsx?$/, exclude: /(node_modules|bower_components)/, loader: 'babel', include: path.join(__dirname, 'app')},
{ test: /\.js?$/, exclude: /(node_modules|bower_components)/, loader: 'babel', include: path.join(__dirname, 'app')},
{ test: /\.jpg$/, loader: "file-loader" },
{ test: /\.(png|woff|woff2|eot|ttf|svg)$/, loader: 'url-loader?limit=100000' }
]
}
};
错误:
ERROR in (webpack)/package.json
Module parse failed: src/node_modules/webpack/package.json Line 2: Unexpected token :
You may need an appropriate loader to handle this file type.
| {
| "name": "webpack",
| "version": "1.12.1",
| "author": {
@ (webpack)/lib/Stats.js 139:16-42
答案 0 :(得分:3)
如果使用CLI,它将读取文件
webpack.config.js
(或--config选项传递的文件)。此文件应导出配置对象:
所以webpack正在寻找.js
文件,而不是.json
(除了文件内容也是JS)。将您的webpack.config.json
重命名为webpack.config.js
,然后您就可以这样称呼它:
webpack
如果你想通过命令行和配置文件的另一个文件名加载它,你也可以这样做:
webpack --config yourconfig.js