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.

Unable to remove comments in CSS and/or JS during compiling

See original GitHub issue
  • Laravel Mix Version: 0.11.3 (npm list --depth=0)
  • Node Version (node -v): 7.9.0
  • NPM Version (npm -v): 4.5.0
  • OS:

Description:

Unable to remove comments in CSS and/or JS during compiling. The only way is to manually edit webpack.config.js to add the parameters:

{ comments: false }

However, webpack.config.js is inside the node_modules directory, so the changes will not be pushed to git.

Steps To Reproduce:

Just run any npm run <script> and comments are not removed.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

8reactions
golubkovdencommented, Jan 17, 2019

If you want to remove all comments add this to your mix options (laravel-mix: 4)

mix.options({
        cssNano: {
            discardComments: {
                removeAll: true,
            },
        },
    })

P.S. @ruchern this comments not removed because starts with *!, see docs

1reaction
ReneLemscommented, Apr 11, 2018

@ruchern To anyone that needs a solution to this. You can provide custom options to the webpack modules in webpack.mix.js, the original options are displayed in /node_modules/laravel-mix/src/Options.js

In laravel 5.4 i provided additional config option like below and all comments were stripped from my minified code, js and css alike.

mix.options({
    postCss: [
        require('postcss-discard-comments')({
            removeAll: true
        })
    ],
    uglify: {
        comments: false
    }
})

You do need the postcss-discard-comments module for this.

I think in the current version of laravel-mix it is done like this (not tested):

mix.options({
    postCss: [
        require('postcss-discard-comments')({
            removeAll: true
        })
    ],
    uglify: {
        uglifyOptions: {
            comments: false
        },
    }
})
Read more comments on GitHub >

github_iconTop Results From Across the Web

Unable to remove comments in CSS and/or JS during compiling
Unable to remove comments in CSS and/or JS during compiling. The only way is to manually edit webpack.config.js to add the parameters:.
Read more >
Remove LESS // comments on compile - css - Stack Overflow
So, to answer your question, you can't really strip out /**/ comments without using compress . Which does all other sorts of things...
Read more >
How can I remove License comment from the bundle ... - HUGO
I'm trying to handle assets via Hugo pipes, but I found that there is a license comment in the final bundle. How can...
Read more >
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 >
Trouble removing css comments with RegExp - JavaScript
I want to remove comments from css files using nodejs. I have this working fairly well: String.prototype.clean = function(){ return ...
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