cssmin not correctly handling @import

前端 未结 6 1656
粉色の甜心
粉色の甜心 2021-02-08 01:40

I am using cssmin on files containing @imports. cssmin is recursively importing local files correctly, but for imports that point to a URL the imports are left inline. This ma

6条回答
  •  迷失自我
    2021-02-08 02:36

    I have exactly the same problem with cssmin and @import, and i found a solution with grunt concat:

    1. Create a concat grunt task that:
    2. Put @import url in the begining of mified css file and replaces references of @imports url for "".
    3. Execute task concat:cssImport after cssmin task.

    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,300,900);', '');
                  }
               }
             },
                files: {
                    'your_location_file_origin/file.full.min.css': ['your_location_file_destination/file.full.min.css']
                }
            } )}
    

    My inspiration comes from https://github.com/gruntjs/grunt-contrib-concat#custom-process-function.

提交回复
热议问题