webpack.config.js的问题

时间:2016-05-14 18:03:28

标签: webpack webpack-dev-server

当我运行命令“webpack” - 一切都好,但当我运行“webpack-dev-server --content-base src --inline --hot”时 - 我收到错误。 可能是sytax错误,打赌我找不到问题。

C:\wamp\www\react\node_modules\webpack\lib\NormalModuleFactory.js:72
                        var elements = request.replace(/^-?!+/, "").replace(/!!+/g, "!").split("!");
                                              ^

TypeError: Cannot read property 'replace' of undefined
    at C:\wamp\www\react\node_modules\webpack\lib\NormalModuleFactory.js:72:26
    at C:\wamp\www\react\node_modules\webpack\lib\NormalModuleFactory.js:28:4
    at C:\wamp\www\react\node_modules\webpack\lib\NormalModuleFactory.js:159:3
    at NormalModuleFactory.applyPluginsAsyncWaterfall (C:\wamp\www\react\node_modules\webpack\node_modules\tapable\lib\Tapable.js:75:69)
    at NormalModuleFactory.create (C:\wamp\www\react\node_modules\webpack\lib\NormalModuleFactory.js:144:8)
    at C:\wamp\www\react\node_modules\webpack\lib\Compilation.js:214:11
    at C:\wamp\www\react\node_modules\webpack\node_modules\async\lib\async.js:181:20
    at Object.async.forEachOf.async.eachOf (C:\wamp\www\react\node_modules\webpack\node_modules\async\lib\async.js:233:13)
    at Object.async.forEach.async.each (C:\wamp\www\react\node_modules\webpack\node_modules\async\lib\async.js:209:22)
    at Compilation.addModuleDependencies (C:\wamp\www\react\node_modules\webpack\lib\Compilation.js:185:8)

我的配置:

var debug = process.env.NODE_ENV !== "production";
var webpack = require('webpack');

module.exports = {
    context: __dirname+"/resources/assets/js",
    devtool: debug ? "inline-sourcemap" : null,
    entry: "./test.jsx",
    module: {
        loaders: [
            {
                test: /\.jsx?$/,
                exclude: /(node_modules|bower_components)/,
                loader: 'babel-loader',
                query: {
                    presets: ['react', 'es2015', 'stage-0'],
                    plugins: ['react-html-attrs', 'transform-class-properties', 'transform-decorators-legacy']
                }
            }
        ]
    },
    output: {
        path: __dirname + "/public/js",
        filename: "scripts.min.js"
    },
    plugins: debug ? [] : [
        new webpack.optimize.DedupePlugin(),
        new webpack.optimize.OccurenceOrderPlugin(),
        new webpack.optimize.UglifyJsPlugin({ mangle: false, sourcemap: false })
    ]
};

目录结构:

C:\wamp\www\react\public\js\ - output
C:\wamp\www\react\resources\assets\js\ - srouce (ex. test.jsx)
C:\wamp\www\react\node_modules\ - node modules
C:\wamp\www\react\ - root directory (ex. webpack.config.js)

2 个答案:

答案 0 :(得分:2)

对我来说,当我使用--inline

时发生了这个错误
"webpack": "1.12.11"
"webpack-dev-server": "1.16.2"

只要我不尝试使用--inline,一切正常。

答案 1 :(得分:0)

确保你的webpack命令指向配置,我遇到了这个问题而且转向是因为我没有指向webpack配置。 例如。     webpack-dev-server --config webpack / webpack.dev.config --inline