我使用cssmin包含@imports的文件. cssmin正是递归地导入本地文件,但是对于指向URL的导入,导入是内联的.这使得最终的CSS无效,因为@规则必须在文件的开头.有没有人知道这个问题的一个很好的解决方案或解决方法?
解决方法
我和cssmin和@import有完全一样的问题,我发现一个有grunt concat的解决方案:
>创建一个concat grunt任务:
>将@import url放在mified css文件的开头,并替换@imports url的引用为“”.
>执行cssmin任务后执行任务concat:cssImport.
Grunt task Code: to execute (concat:cssImport)
- grunt.initConfig({
- concat: {
- cssImport: {
- options: {
- process: function(src,filepath) {
- return "@import url(http://fonts.googleapis.com/css?family=Roboto:400,300,900);"+src.replace('@import url(http://fonts.googleapis.com/css?family=Roboto:400,900);','');
- }
- }
- },files: {
- 'your_location_file_origin/file.full.min.css': ['your_location_file_destination/file.full.min.css']
- }
- } )}
我的灵感来自https://github.com/gruntjs/grunt-contrib-concat#custom-process-function.