Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

496
Visualizações
Unable to strip comments in webpack bundle js file

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\ ...

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

also this

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

Also set the enviroment to production

set NODE_ENV=production

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

over 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

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

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.

over 4 years ago · Santiago Trujillo Relatório

0

This is what you need:

new UglifyJsPlugin({
    comments: false,
}),

From here.


Here is the line from the Webpack and @Everettss is right.

File: /webpack/lib/optimize/UglifyJsPlugin.js
097:                        let output = {};
098:                        output.comments = Object.prototype.hasOwnProperty.call(options, "comments") ? options.comments : /^\**!|@preserve|@license/;
099:                        output.beautify = options.beautify;
100:                        for(let k in options.output) {
101:                            output[k] = options.output[k];
102:                        }

and you may check the regular expression which confirms what Sokra stated.

enter image description here

I am not sure about UglifyJsPlugin, but usually if you privide the legal statement somewhere else you should eliminate all the comments.

If your lawyer confirms this is OK, you may try to tweak the /*! so the regular expression fails and the comments will be not there any more.

over 4 years ago · Santiago Trujillo Relatório

0

For webpack 4 this was working for me:

// webpack.config.js

const UglifyJsPlugin = require('uglifyjs-webpack-plugin');

module.exports = {
  // other config properties...

  optimization: {
    minimizer: [
      new UglifyJsPlugin({
        uglifyOptions: {
          output: {
            comments: false
          }
        }
      })
    ]
  }
};

You can find more information in the official docs.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda