question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Although I am using the UglifyJS plugin and have options turned on, I still get some comments in the code like /*! ... */. I want to strip my entire output of any comment. How can I do that?

Kind regards, Ingwie.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:7
  • Comments:20 (2 by maintainers)

github_iconTop GitHub Comments

23reactions
agundermanncommented, Jun 28, 2015
new webpack.optimize.UglifyJsPlugin({
    output: {
        comments: false
    }
})
10reactions
IngwiePhoenixcommented, Nov 8, 2015

I get them stripped now. This is my config for Uglifyjs. The only place where comments are left, is CSS.

module.exports = {
    compress: {
        warnings: false,
        properties: true,
        sequences: true,
        dead_code: true,
        conditionals: true,
        comparisons: true,
        evaluate: true,
        booleans: true,
        unused: true,
        loops: true,
        hoist_funs: true,
        cascade: true,
        if_return: true,
        join_vars: true,
        //drop_console: true,
        drop_debugger: true,
        unsafe: true,
        hoist_vars: true,
        negate_iife: true,
        //side_effects: true
    },
    //sourceMap: true,
    mangle: {
        toplevel: true,
        sort: true,
        eval: true,
        properties: true
    },
    output: {
        space_colon: false,
        comments: function(node, comment) {
            var text = comment.value;
            var type = comment.type;
            if (type == "comment2") {
                // multiline comment
                return /@copyright/i.test(text);
            }
        }
    }
}

Notice the function there - that does the trick. It only leaves comments with @copyright in. All others are goners.

Read more comments on GitHub >

github_iconTop Results From Across the Web

strip-comments - npm
Strip line and/or block comments from a string. Blazing fast, and works with JavaScript, Sass, CSS, Less.js, and a number of other languages....
Read more >
Strip comments from a string - Rosetta Code
The task is to remove text that follow any of a set of comment markers, (in these examples either a hash or a...
Read more >
strip-comments - npm Package Health Analysis - Snyk
Strip line and/or block comments from a string. Blazing fast, and works with JavaScript, Sass, CSS, Less.js, and a number of other languages....
Read more >
strip-comments examples - CodeSandbox
Strip Comments Examples. Learn how to use strip-comments by viewing and forking example apps that make use of strip-comments on CodeSandbox.
Read more >
Remove comments from string with JavaScript using JavaScript
How can I remove all comments from 's' string? Should I use some Regexp for it? I don't know. javascript.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found