【发布时间】:2015-07-23 16:15:40
【问题描述】:
在我的 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;
【问题讨论】: