How to rewrite relative url in minified css with cssmin?

I was looking for a solution to my problem, and I found posts with similar problems, but not the same. I have the following folder structure:

js
└── GUIFramework
    ├── external
    └── WaspFramework
        ├── Core
        └── GUI
            └── Controls
                └── WaspMask
                    ├── css
                    │   └── WaspMask.css
                    └── resources
                        └── default_loader_circle.gif

Inside the file WaspMask.css, I have this rule:

.wasp-loader-default {background-image: url ("../resources/default_loader_circle.gif"); }

Well, I tried to minimize it (in combination with other css files) with the plugin cssmin. My grunt file is placed in a folder WaspFrameworkand I want to generate minified css there. The grunt file file is as follows:

module.exports = function (grunt) {

    var _sources = grunt.file.readJSON('./sources.json');
    var _filesCSS = _sources.css;

    grunt.initConfig({

        cssmin: {
            wasp: {
                options: {
                    keepSpecialComments: 0
                },
                files: {
                    'wasp-bundle.min.css': _filesCSS
                }
            }
        }
    });

    // load plugins
    grunt.loadNpmTasks('grunt-contrib-cssmin');

    // register at least this one task
    grunt.registerTask('default', ['cssmin']);
};

As _filesCSSI have a way for all of the files in order to minimize and associations WaspMask.css.

, cssmin URL- wasp-loader-default , , , . cssmin, root:

options: {
    keepSpecialComments: 0,
    root: '.',
},

URL- /GUI/Controls/WaspMask/resources/default_loader_circle.gif, - . (GUI/Controls/WaspMask/resources/default_loader_circle.gif ), . . root, URL , .

, ?

+4
1

, , 'cssmin': https://github.com/gruntjs/grunt-contrib-cssmin/pull/47

, 'bootstrap.css' . ( , "noAdvanced" true ) , : https://github.com/gruntjs/grunt-contrib-cssmin/issues/103

EDIT: grunt:

module.exports = function (grunt) {
    var conf = grunt.file.readJSON('sources.json');
    grunt.initConfig({
        cssmin: {
            options: {
                keepSpecialComments: 0,
                target: 'commonDir',
                noAdvanced: true
            },
            test: {
                files: {
                    'test.min.css': conf.css
                }
            }
        }
    });
    // load plugins
    grunt.loadNpmTasks('grunt-contrib-cssmin');
    // register at least this one task
    grunt.registerTask('default', ['cssmin']);
};

target , ( json , ).

noAdvanced - , , , bootstrap.css, @XhmikosR https://github.com/gruntjs/grunt-contrib-cssmin/issues/103, , , . .

+1

Source: https://habr.com/ru/post/1542359/


All Articles