[AngualrJS + Webpack] Production Source Maps

本文介绍如何在使用Webpack的uglify插件压缩Angular代码时,通过添加source-map来简化生产环境下的调试工作。具体方法包括在配置文件中设置devtool为'source-map',并使用UglifyJsPlugin进行代码压缩。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

When you uglify your Angular code with Webpack's uglify plugin, debugging your application can be a nightmare. See how easy it is to add source maps to your bundle so you can easily debug even in production.

 

Add source map to the production:

if(process.env.NODE_ENV === "production"){
    config.output.path = __dirname + "/dist";
    config.plugins.push(new webpack.optimize.UglifyJsPlugin()); // Uglify js
    config.devtool = 'source-map';
}

 

var webpack = require('webpack')
    path = require('path');

path.resolve(__dirname, "app");

var config = {
    context: __dirname + '/app',
    entry: './index.js',
    output: {
        path: __dirname + '/app',
        filename: 'bundle.js'
    },
    plugins: [
        new webpack.DefinePlugin({
           ON_TEST: process.env.NODE_ENV === "test"
        })
    ],
    module: {
        loaders: [
            {test: /\.js$/, loader: 'ng-annotate-loader!babel-loader', exclude: /node_modules/},
            {test: /\.html$/, loader: 'html-loader', exclude: /node_modules/},
            {test: /\.css$/, loader: 'style!css', exclude: /node_modules/},
            {test: /\.styl/, loader: 'style!css!stylus', exclude: /node_modules/}
        ]
    }
};

if(process.env.NODE_ENV === "production"){
    config.output.path = __dirname + "/dist";
    config.plugins.push(new webpack.optimize.UglifyJsPlugin()); // Uglify js
    config.devtool = 'source-map';
}

module.exports = config;

 

转载于:https://www.cnblogs.com/Answer1215/p/4798270.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值