Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

493
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda