我在包含 @imports 的文件上使用 cssmin。 cssmin 正确地递归导入本地文件,但对于指向 URL 的导入,导入将保持内联。这使得生成的缩小 CSS 无效,因为 @ 规则必须位于文件的开头。有谁知道这个问题的好的解决方案或解决方法?
我有完全相同的问题cssmin and @import,我找到了一个解决方案咕噜连接:
- 创建一个 concat grunt 任务:
- 将 @import url 放在缩小的 css 文件的开头,并将 @imports url 的引用替换为“”。
- 在 cssmin 任务之后执行任务 concat:cssImport。
Grunt 任务代码:执行 (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,300,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 https://github.com/gruntjs/grunt-contrib-concat#custom-process-function.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)