grunt-contrib-less icon indicating copy to clipboard operation
grunt-contrib-less copied to clipboard

Variables not modified in all cases

Open paazmaya opened this issue 11 years ago • 4 comments

I have a LESS file with:

@import-path: "/normal-place";
@import "@{import-path}/styles";

With the following configuration the variable is not overwritten:

modifyVars: {
  'import-path': "'../other-location'"
}

With the following configuration the variable is overwritten:

modifyVars: {
  'import-path': '../other-location'
}

but it comes out as, thus not working as supposed to:

@import-path: ../other-location;

paazmaya avatar Apr 16 '14 08:04 paazmaya

I've been fiddling with this just now. Try the following:

 modifyVars: {
  import-path: '"../other-location"'
}

It worked for me. Be sure to call the variable like this though: @{import-path} since it's a path

SubZane avatar Apr 01 '15 12:04 SubZane

I ran into the same issue. I think it's just a quoting issue but it's easy to miss, perhaps it's worth adding to the README something like:

Ensure variables used in paths are properly quoted, e.g 'my-path': '"../location"'

nguillaumin avatar Apr 13 '16 05:04 nguillaumin

Hi, In my case this doesn't work. My "import-path" is given as a parameter to grunt cli, this way: > grunt --theme-path=../../../proj1/theme Hence I have no way of "quoting" things. I did tried any combination possible of single and double quotes on the cli though.

My Gruntfile.js

module.exports = (grunt) => {
    const themePath = grunt.option('theme-path');
    grunt.loadNpmTasks('grunt-contrib-less');
    grunt.initConfig({
        pkg: grunt.file.readJSON('package.json'),
        less: {
            development: {
                options: {
                    dumpLineNumbers: 'comments',
                    modifyVars: {
                        'theme-path': themePath
                    }
                },
                files: {
                    'wwwroot/css/app.css': 'src/less/main.less'
                }
            }
        }
    });
    grunt.registerTask('default', ['less']);
};

My main.less

@import '@{theme-path}/colors.less';

All this gives me:

Running "less:development" (less) task
>> NameError: variable @theme-path is undefined in src/less/main.less on line 1, column 9:

I'm using grunt v0.4.5 and grunt-contrib-less v1.4.1.

stepbeta avatar Mar 15 '17 14:03 stepbeta

Sorry, after more try-and-error. Solution was:

modifyVars: {
    'theme-path': '"' + themePath + '"'
}

stepbeta avatar Mar 15 '17 14:03 stepbeta