ReferenceError:未定义webpack

node.js Webpack

神乐阿飞

2020-03-23

在我的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;

第3114篇《ReferenceError:未定义webpack》来自Winter(https://github.com/aiyld/aiyld.github.io)的站点

0个回答

问题类别

JavaScript Ckeditor Python Webpack TypeScript Vue.js React.js ExpressJS KoaJS CSS Node.js HTML Django 单元测试 PHP Asp.net jQuery Bootstrap IOS Android