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.

[0.11.4] CSS Comments are not removed

See original GitHub issue

Node: 6.10.3 NPM: 4.5.0 OS: Ubuntu 16.04 cleancss: 4.0.12

Fresh laravel 5.4 app followed by npm install. Added cleanCss options to webpack.mix.js

const { mix } = require('laravel-mix');

/*
 |--------------------------------------------------------------------------
 | Mix Asset Management
 |--------------------------------------------------------------------------
 |
 | Mix provides a clean, fluent API for defining some Webpack build steps
 | for your Laravel application. By default, we are compiling the Sass
 | file for the application as well as bundling up all the JS files.
 |
 */
mix.options({
    cleanCss: {
    	level: {
    		1: { specialComments: 'none'}	
    	}
    },
    purifyCss: true,
});

mix.js('resources/assets/js/app.js', 'public/js')
   .sass('resources/assets/sass/app.scss', 'public/css');

npm run prod results in a minified app.css file but comments are not removed:

charset "UTF-8";@import url(https://fonts.googleapis.com/css?family=Raleway:300,400,600);/*!
 * Bootstrap v3.3.7 (http://getbootstrap.com)
 * Copyright 2011-2016 Twitter, Inc.
 * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
 *//*! normalize.css v3.0.3 | MIT License | github.com/necolas/normalize.css */html{font-family:sans-serif;-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%;font-size:10px;-webkit-tap-highlight-color:transparent}[hidden],template{display:none} ....

Running cleancss cli results in a file without comments: cleancss -O1 specialComments:none app.css > clean.css

@charset "UTF-8";@import url(https://fonts.googleapis.com/css?family=Raleway:300,400,600);html{font-family:sans-serif;-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%;font-size:10px;-webkit-tap-highlight-color:transparent}[hidden],template{display:none} ...

Cheers

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:15 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
rjsworkingcommented, May 8, 2017

@marcelogarbin

Yes.

Tweaked webpack.mix.js

const {mix} = require('laravel-mix');

/*
 |--------------------------------------------------------------------------
 | Mix Asset Management
 |--------------------------------------------------------------------------
 |
 | Mix provides a clean, fluent API for defining some Webpack build steps
 | for your Laravel application. By default, we are compiling the Sass
 | file for the application as well as bundling up all the JS files.
 |
 */

let LiveReloadPlugin = require('webpack-livereload-plugin');

// Disable toast notifications
mix.disableNotifications();

mix.options({
    cleanCss: {
        level: {
            1: {
                specialComments: 'none'
            }
        }
    },

    postCss: [
         require('postcss-discard-comments')({ removeAll: true })
    ],

    purifyCss: true
});

mix.js('resources/assets/js/app.js', 'public/js/app.js');

mix.sass('resources/assets/sass/app.scss', 'public/css/app.css');

mix.styles(['resources/assets/css/style.css'], 'public/css/styles.css');

style.css output

@import url(//fonts.googleapis.com/css?family=Open+Sans:300,400,600,700&lang=en);body{color:#676a6c;font-family:'Open Sans',helvetica,arial,sans-serif}.layout{background-color:red}span.navy{color:#1ab394}p.text-color{color:#676a6c}

Try to delete your node_modules folder and install packages again (npm install)

2reactions
garbinmarcelocommented, May 6, 2017

Also I am not able to remove the comments, however using the “postcss-discard-comments” plugin, I can remove the comments from my SASS file, the same configuration does not work for mix.stylus.

Did you find any alternatives?

my configs.: mix.sass()

mix.sass('resources/assets/sass/style.scss', 'public/css')
    .options({
        postCss: [
            require('postcss-discard-comments')({
                removeAll: true
            })
        ]
    }
);

and mix.styles()

mix.styles([
    'bower_components/bootstrap/dist/css/bootstrap.css',
    'bower_components/font-awesome/css/font-awesome.css',
    'bower_components/select2/dist/css/select2.css',
    'bower_components/animate.css/animate.css',
    'bower_components/hover/css/hover.css',
    'bower_components/lity/dist/lity.css',
    'bower_components/SpinKit/css/spinkit.css',
    'bower_components/sweetalert2/dist/sweetalert2.css',
    'public/css/style.*.css'
], 'public/css/app.css', {
    use: [
        require('postcss-discard-comments')({
            removeAll: true
        })
    ]
});
Read more comments on GitHub >

github_iconTop Results From Across the Web

[0.11.4] CSS Comments are not removed · Issue #776 - GitHub
npm run prod results in a minified app.css file but comments are not removed: charset "UTF-8";@import url(https://fonts.googleapis.com/css ...
Read more >
Comments - CSS: Cascading Style Sheets - MDN Web Docs
A CSS comment is used to add explanatory notes to the code or to prevent the browser from interpreting specific parts of the...
Read more >
Comments in CSS - CSS-Tricks
In this case, this comment lets someone reading the CSS file know that that particular line of CSS was intended to allow for...
Read more >
Angular Update Guide
We are deprecating support for @angular/platform-webworker , as it has been incompatible with the CLI. Running Angular's rendering architecture in a web ...
Read more >
Changes 0.11.x - web2ldap
Removed invalid note about NON-ASCII chars not allowed in LDIF input form. Display allowed URL schemes as note near LDIF input form.
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