ReferenceError:webpack没有定义

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

这是我的webpackconfiguration文件:

 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; 

你错过了

 var webpack = require('webpack'); 

在你的文件的开始。 如果你想优化执行一下,你可以把它推到里面, if你的块。