首页 文章

ReferenceError:未定义webpack

提问于
浏览
32

在我的webpack应用程序中,我有一个由"npm run build"触发的基本构建过程,它执行webpack二进制文件并将我的index.html复制到/ app到/ dist . 每当我运行 npm run build 我得到 ReferenceError: webpack is not defined 但是当我运行启动webpack-dev-server的 npm start 时,一切都很好 .

这是我的webpack配置文件:

var ExtractTextPlugin = require('extract-text-webpack-plugin');

var config = {
    context: __dirname + '/app',
    entry: './index.js',
    output: {
        path: __dirname + '/app',
        filename: 'app.js'
    },
    module: {
        loaders: [
            { test: /\.js$/, loader: 'babel', exclude: /node_modules/ },
            { test: /\.html$/, loader: 'raw', exclude: /node_modules/ },
            { test: /\.scss$/, loader: ExtractTextPlugin.extract('style', 'css!sass'), exclude: /node_modules/}
        ]
    },
    plugins: [
        new ExtractTextPlugin('app.css')
    ]
};

if (process.env.NODE_ENV == 'production') {
    config.output.path = __dirname + '/dist';
    config.plugins.push(new webpack.optimize.UglifyJsPlugin());
}

module.exports = config;

1 回答

  • 88

    你错过了

    var webpack = require('webpack');
    

    在您的文件的开头 . 如果您想稍微优化执行,可以将其推送到您的 if 块中 .

相关问题