Webpack:模块解析失败

Webpack: Module parse failed

运行 下面的 web pack 配置给了我很多错误,第一个在下面。我只是不明白为什么它在 web pack 本身中。

注意;我正在使用 Reactjs。

更新:当我 webpack 而不是 webpack web pack.config.js 时,它起作用了。但是我需要能够将一台用于生产,一台用于开发?

你知道为什么吗?

webpack 配置: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

webpack documentation 中指出:

If you use the CLI it will read a file webpack.config.js (or the file passed by the --config option). This file should export the configuration object:

所以 webpack 寻找的是 .js 文件,而不是 .json(除此之外你的文件内容也是 JS)。将你的 webpack.config.json 重命名为 webpack.config.js,然后你就可以这样称呼它:

webpack

如果你想通过命令行和配置文件的另一个文件名加载它,你也可以这样做:

webpack --config yourconfig.js