简体   繁体   中英

How to minimize javascript with Webpack?

I'm trying to minimize my bundle.js file with webpack, but getting errors in my config:

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
        })
    ]
};

The error:

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

Seems like you're missing var webpack = require('webpack'); at the top of your configuration file.

It works for me this way

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM