无法在webpack bundle js文件中删除注释 [英] Unable to strip comments in webpack bundle js file

查看:418
本文介绍了无法在webpack bundle js文件中删除注释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直试图在webpack捆绑的js文件中删除注释。
我尝试了几种方法,但它还没有工作,我收到的评论就像

I have been trying to strip comments in the webpack bundled js file. I have tried several methods but it's not working still and I get comments like

"/**\n * Copyright 2013-present, Facebook, Inc.\n * All rights reserved.\n *\n * This source code is licensed under the BSD-style license found in the\ ...

为此,捆绑的文件变得越来越大。目前大小为1.6mb。
我试过这个

For this the bundled file is getting huge. Currently huge at 1.6mb size. I have tried this

new webpack.optimize.UglifyJsPlugin({
        sourceMap: false,
        compress: {
            sequences: true,
            dead_code: true,
            conditionals: true,
            booleans: true,
            unused: true,
            if_return: true,
            join_vars: true,
            drop_console: true
        },
        mangle: {
            except: ['$super', '$', 'exports', 'require']
        },
        output: {
            comments: false
        }
    })

new webpack.optimize.UglifyJsPlugin({
        compress: { warnings: false },
        sourceMap: false,
        output: false
    })

同时将环境设置为生产

set NODE_ENV=production



<我无法理解我错在哪里。
请帮忙。
提前致谢。

I am not able to understand where I am wrong. Please help. Thanks in advance.

推荐答案

UglifyJsPlugin 不要即使您出于法律原因设置 comments:false ,也要删除 @licence 条评论。你可以在关于webpack GitHub问题上阅读它。

UglifyJsPlugin don't remove @licence comments even if you set comments: false for legal reasons. You can read about it on webpack GitHub issue.

如果您想删除此类评论(风险自负),您应该搜索其他加载器,例如 webpack-comment-remover-loader stripcomment-loader

If you want to remove this kind of comments (on your own risk) you should search for other loaders like webpack-comment-remover-loader or stripcomment-loader.

这篇关于无法在webpack bundle js文件中删除注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆