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