I'm working on a code with css and I found every class wrote before it
#media -sass-debug-info{filename{font-family:file\:\/\/C\:\/www\/w-balls-html\/html_source\/lib\/_master\.scss}line{font-family:\00003640}}
I found the at the doc of saas something about it
- ({#to_s => #to_s}) debug_info
A hash that will be associated with this rule in the CSS document if the :debug_info option is enabled. This data is used by e.g. the FireSass Firebug extension.
Returns:({#to_s => #to_s}) [debug-info-documentation][1]
but couldn't know how to debug it or know how to convert to the normal #media
#media all and (max-width: 699px) and (min-width: 520px))
If you are using Grunt to run your application, you can edit the Gruntfile.js file. You are looking for the Compass section. I found it around line 175. In that section you want to modify the the Server debugInfo to false.
// Compiles Sass to CSS and generates necessary files if requested
compass: {
options: {
sassDir: '<%= yeoman.app %>/styles',
cssDir: '.tmp/styles',
generatedImagesDir: '.tmp/images/generated',
imagesDir: '<%= yeoman.app %>/images',
javascriptsDir: '<%= yeoman.app %>/scripts',
fontsDir: '<%= yeoman.app %>/styles/fonts',
importPath: './bower_components',
httpImagesPath: '/images',
httpGeneratedImagesPath: '/images/generated',
httpFontsPath: '/styles/fonts',
relativeAssets: false,
assetCacheBuster: false,
raw: 'Sass::Script::Number.precision = 10\n'
},
dist: {
options: {
generatedImagesDir: '<%= yeoman.dist %>/images/generated'
}
},
server: {
options: {
debugInfo: false
}
}
},
By changing the option to false you will not have the debug info in the file. I recommend that you leave the debug info while in development. When the site is finished and ready for production THEN remove the debug info.
Lastly, this will not remove the comments out of the CSS file. You may notice that Compass inserts a location comment at the beginning of each selector. (See below)
/* line 19, ../../bower_components/bootstrap-sass-official/assets/stylesheets/bootstrap/_normalize.scss */
body { margin: 0; }
In order to remove that you will need to use Minification. Grunt can also take care of that. You will need to make sure the Gruntfile.js is configured. (I found mine to be commented out with // before every line. I had to remove those lines) After that just run
grunt cssmin
These 2 steps took a 475 KB CSS file down to 110 KB.
Hope this helps!
I was trying to figure out how to use that information myself to edit the original SASS files and learned that it is used for developing using a FireSASS plugin.
If you want human readable debug line number you want the noLineComments grunt setting, like so:
debug: {
options: {
watch: false,
outputStyle: 'expanded',
debugInfo: false, // this generates browser debug info, not human friendly
noLineComments: false, // human friendly debug comments
}
},
Which will spit out something like:
/* line 18, ../../sass/config/_font-icons.scss */
[class^="icon"],
[class*=" icon"] {
font-family: "HW Icon Font";
font-weight: normal;
font-style: normal;
text-decoration: inherit;
-webkit-font-smoothing: antialiased;
}
Related
I am trying to use html-minifier grunt plugin (https://github.com/gruntjs/grunt-contrib-htmlmin) and the documentation says we can use multiple targets; That is, we can specify different options for different build environment. In the below example 2 targets are configured 'dist' and 'dev'
grunt.initConfig({
htmlmin: {
dist: {
options: {
removeComments: true,
collapseWhitespace: true
},
files: {
'dist/index.html': 'src/index.html'
}
},
dev: {
files: {
'dist/index.html': 'src/index.html'
}
}
}
});
But my question is, while using grunt how can I instruct the plugin to use specific target? For example, for a production build I want to use "dist" target specified in plugin config. I can do grunt htmlmin but it triggers 'dev' target only.
Problem
Everything else equal, my final pages differ in their CSS result. The prod version lacks the proper flexbox alignment as seen in the following comparison:
Dev
Prod
The problem is caused by the PurifyCSSPlugin. I don't know how to configure it still cleaning up the right parts of the css, keeping the parts I really need?
Any help would be appreciated. The complete code is available here.
Research so far
Update 2017-08-21:
In the production version there is css missing for the following classes
subtitle
title:not(.is-spaced) + .subtitle {
margin-top: -1.5rem;
}
columns
#media screen and (min-width: 769px), print
.columns:not(.is-desktop) {
display: flex;
}
Setup
I use webpack-3 together with bulma to make a webpage. I have two script tasks defined to build my application 1. in development and 2. for production.
"dev": "webpack-dev-server --progress --colors",
"prod": "npm run clean && NODE_ENV=prod webpack -p",
Inside my webpack config I switch between two configurations for the css handling, depending on the NODE_ENV variable. The config looks as follows:
const cssConfigEnvironments = {
'dev': ['style-loader', 'css-loader?sourceMap', 'sass-loader'],
'prod': ExtractTextPlugin.extract({
fallback: 'style-loader',
use: ['css-loader', 'sass-loader']
})
}
In addition I disable the ExtractTextPlugin for development.
new ExtractTextPlugin({ // Builds .css, see https://github.com/webpack-contrib/extract-text-webpack-plugin
filename: '[name].css',
allChunks: true,
disable: !envIsProd
}),
The only noticeable info shown inside the console is the following deprecation warning:
(node:2275) DeprecationWarning: Chunk.modules is deprecated. Use Chunk.getNumberOfModules/mapModules/forEachModule/containsModule instead.
The problem is really coming from the PurifyCSSPlugin there is an issue already open tackling it.
As a quick fix you have to whitelist the not tag:
new PurifyCSSPlugin({
// Give paths to parse for rules. These should be absolute!
paths: glob.sync(path.join(__dirname, 'src/*.html')),
minimize: envIsProd,
purifyOptions: {
info: true,
whitelist: [ '*:not*' ]
}
})
Question Part 1
In my current setup, I have a folder that looks like this:
/wwwroot <-- Hosted in localhost
/_project <-- Contains gruntfile.js
/_dev <-- Contains Source Code
The wwwroot folder is hosted in XAMPP and open in my browser. The _project folder contains my gruntfile.js, and _dev contains all the JS and SCSS that is compiled into JS and CSS by Grunt.
This has worked fine for a year or two, but recently, I updated my packages, and the generated sourcemaps have begun breaking. Chrome shows a blank code panel in Sources, and Firefox Dev displays a 404 error's HTML in the sources code panel. The sources were now being looked for inside the /wwwroot folder. Because of this, the sources 404 and aren't shown, and I can't use sourcemap debugging which I rely on.
Relevant parts of Gruntfile:
uglify: {
common: {
options: {
mangle: false,
compress: true, // true or false or {}
preserveComments: 'all', // true or 'all' or 'some'
sourceMap : true
},
files: {
// '../wwwroot/Content/includes/js/libs.js': ['../_dev/js/common/libs/*.js'],
'../wwwroot/Content/includes/js/buildbar.js': ['../_dev/js/common/buildbar/*.js'],
'../wwwroot/Content/includes/js/framework.js': ['../_dev/js/common/framework/*.js'],
}
},
}
Short of painfully rearranging my directory structure... how can I fix this?
Question part 2:
I've tried using grunt-uglify-contrib's sourceMapRoot option as follows:
uglify: {
common: {
options: {
mangle: false,
compress: true, // true or false or {}
preserveComments: 'all', // true or 'all' or 'some'
sourceMap : true,
sourceMapRoot: "C:/Users/quint/Documents/Github/build-siteengine/a/a/a/a"
},
files: {
// '../wwwroot/Content/includes/js/libs.js': ['../_dev/js/common/libs/*.js'],
'../wwwroot/Content/includes/js/buildbar.js': ['../_dev/js/common/buildbar/*.js'],
'../wwwroot/Content/includes/js/framework.js': ['../_dev/js/common/framework/*.js'],
}
},
}
For some reason, though, the paths that show in the Sources panel in Firefox Dev are missing four directories, hence why I've added the /a/a/a/a. Why would this be happening?
This also doesn't solve my problem, since in Firefox Dev clicking on the line numbers open the file in the browser and don't take me to the line of code in the debugger, and in Chrome there is no effect.
When I develop web applications, I'm used to add a ?ver=XXX at the end of my CSS URIs.
I'm updating a wordpress theme and I found a filter that removes any ?ver= from "static ressources" :
add_filter( 'script_loader_src', 'mb_remove_script_version', 15, 1 );
add_filter( 'style_loader_src', 'mb_remove_script_version', 15, 1 );
Searching the web I found that without removing thoses ver=, CDN may not work and do not cache the CSS files ! That's a big surprise to me as I used it everywhere.
I use this version to force browsers to update their cache when I modify the CSS (by versionning up).
How do you force browser to understand the file must be downloaded again without using a ver= ?
--
Thank you
Nicolas.
You can use a tool such as Grunt (or gulp) to rev your assets:
https://www.npmjs.com/package/grunt-wp-assets
https://www.npmjs.com/package/gulp-rev
Thank to your answers, here is the full answer :
In my theme there is this file "theme-functions.php" in the ~theme/lib directory.
This is the file that loads the css file using the enqueue_style function :
wp_enqueue_style( '_mbbasetheme-style', get_template_directory_uri() . '/style.min.css' );
Using grunt as suggested, I was able to achieve the following steps :
Compass the SASS file and make a unique css file ==> style.css
Minify my unique css file to make it lighter ==> style.min.css
Version my css file to make a unique file name ==> style.4c72.min.css
These steps use the following grunt-plugins :
grunt-contrib-compass : with this grunt rule in Gruntfile.js
compass: {
dist: {
options: {
config: 'config.rb'
}
}
},
grunt-contrib-cssmin : with this grunt rule in Gruntfile.js
cssmin: {
options: {
keepSpecialComments: 1
},
minify: {
expand: true,
cwd: '',
src: ['*.css', '!*.min.css'],
dest: '',
ext: '.min.css'
}
},
grunt-wp-assets : with this grunt rule in Gruntfile.js
version: {
assets: {
options: {
algorithm: 'sha1',
length: 4,
format: false,
rename: false,
minify: true,
manifest: 'manifest.json'
},
files: {
'lib/theme-functions.php': ['style.min.css']
}
}
},
As you can see, the last one takes a file in argument to update the reference to the css file. After the grunt execution (actually a grunt-contrib-watch rule), the theme-functions.php is updated to :
wp_enqueue_style( '_mbbasetheme-style', get_template_directory_uri() . '/style.4c72.min.css' );
I’m using https://github.com/jney/grunt-htmlcompressor to compress HTML files. But it’s requiring me to manually type-in all the HTML files which I want minified:
grunt.initConfig({
htmlcompressor: {
compile: {
files: {
'dest/index.html': 'src/index.html'
},
options: {
type: 'html',
preserveServerScript: true
}
}
}
});
Is there a way to specify that I want to minify all HTML files of the entire folder (and subfolders)?
Or, in case this html-compressor is limited, are you aware of a different npm package that does this HTML mification?
The glob pattern should be allowed for any grunt task by default. Then simply use dynamic files to build each one to your dest
Instead of:
files: {
'dest/index.html': 'src/index.html'
},
Go with:
files: [
{
expand: true, // Enable dynamic expansion.
cwd: 'src/', // Src matches are relative to this path.
src: ['**/*.html'], // Actual pattern(s) to match.
dest: 'dest/', // Destination path prefix.
},
],
As far as another plugin I would recommend grunts contrib version since it's more common and maintained by the grunt team.