如何使用Webpack最小化javascript?

时间:2015-12-04 19:31:06

标签: javascript build config webpack minimize

我试图用webpack最小化我的bundle.js文件,但在配置中出错:

module.exports = {
    entry: "./entry.js",
    output: {
        devtoolLineToLine: true,
        sourceMapFilename: "./bundle.js.map",
        pathinfo: true,
        path: __dirname,
        filename: "bundle.js"
    },
    module: {
        loaders: [
            { test: /\.css$/, loader: "style!css" }
        ]
    },
    plugins: [
        new webpack.optimize.UglifyJsPlugin({
            include: /\.min\.js$/,
            minimize: true
        })
    ]
};

错误:

/Users/leongaban/Projects/TickerTags/ionic/TickerTags/www/webpack.config.js:16
        new webpack.optimize.UglifyJsPlugin({
            ^
ReferenceError: webpack is not defined

1 个答案:

答案 0 :(得分:4)

好像您在配置文件的顶部缺少var webpack = require('webpack');

这对我有用