2015-09-11 182 views
0

运行以下网络包配置会给我提供很多错误,第一个错误在下面。我只是不明白为什么它是在网络包内。Webpack:模块解析失败

注意;我正在使用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 
+0

你试图加载JSON文件没有JSON加载器? – Shikloshi

+0

你如何运行webpack(命令行命令)? – nils

+0

不,但我使用Reactjs? –

回答

3

在它规定的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(除了你的文件的内容是lso JS)。重命名webpack.config.jsonwebpack.config.js,那么你可以这样调用:

webpack 

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

webpack --config yourconfig.js 
+0

非常明显:我错过了--config ;-) –

相关问题