Grunt cwd选项问题 [英] Grunt cwd option issue

查看:134
本文介绍了Grunt cwd选项问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的项目中配置grunt-svg-sprite插件,并按照这里的文档 http:// gruntjs .com / configurations-tasks

lockquote
所有的src匹配都是相对于(但不包括)这个路径的。


$ b 匹配的模式,相对于cwd。

按照 https://www.npmjs.com/package/grunt-svg-sprite


但是,由于路径/资产将成为形状ID的一部分,因此最有可能需要添加大多数情况下是工作目录:



  your_target:{
expand:true,
cwd:'path / to / assets',
src:['** / *。svg'],
dest:'path / to / css / dir',
选项:{
//目标特定操作tions
}
},

现在,我的grunt文件的部分:

  svg_sprites:{
选项:{

},
cw_sprites:{
展开:true,
cwd:'public / assets / dist / svgs /',
src:['** / *。svg'],
dest:'public / assets / stylesheets / svg-sprites',
options:{
shape:{
dimension:{
maxWidth:32,
maxHeight:32,
$,
间距:{
填充:0,
}

},
模式:{
css:{
渲染:{
css:true
},
示例:true
},
less:true,
}
}


}
},

使用--verbose选项运行上述任务时,我在输出中看到以下内容:

  .... 
读取public / assets / dist / svgs / uncollapsed-triangle.svg ... OK
阅读公共/资产/字体/ glyphicons-halflings-regular。 svg ... OK
读取公共/资产/字体/ myraid-pro / MyriadPro-Regular.svg ... OK
警告:无法读取未替换的属性'替换'使用--force继续。

根据上面的日志,它正尝试读取CWD路径之外的其他目录公共/资产/距离/ svgs。实际上,它继续读取包含bower_components等项目的根目录并扫描整个项目根目录。



我认为使用带有src选项的cwd选项会限制它到'cwd'的子目录或相对于'cwd'的目录。为什么其他目录正在被扫描?



我错过了什么吗?感谢您的帮助。

解决方案

好的,我想我终于明白了。实际上有两个名称非常相似的项目:


  1. grunt-svg-sprite( https://www.npmjs.com/package/grunt-svg-sprite )和

  2. grunt-svg-sprites( https://www.npmjs.com/package/grunt- svg-sprites



  3. 我想使用第一个项目,但错误地安装了第二个项目!!!!!显然它不会工作: - )



    我删除了错误的模块(2)并安装了第一个模块 - 它的功能就像一个魅力。让我想知道命名约定是否需要对npm模块进行一些思考。

    I am trying to configure grunt-svg-sprite plugin in my project and as per documentation here http://gruntjs.com/configuring-tasks:

    cwd All src matches are relative to (but don't include) this path.

    src Pattern(s) to match, relative to the cwd.

    And as per https://www.npmjs.com/package/grunt-svg-sprite

    However, as the path/to/assets would become part of the shape IDs, you will most likely want to add a working directory in most cases:

    your_target: {
        expand      : true,
        cwd         : 'path/to/assets',
        src         : ['**/*.svg'],
        dest        : 'path/to/css/dir',
        options     : {
            // Target-specific options 
        }
    },
    

    Now, my grunt file has section:

        svg_sprites: {
            options: {
    
            },
            cw_sprites: {
                expand: true,
                cwd: 'public/assets/dist/svgs/',
                src: ['**/*.svg'],
                dest: 'public/assets/stylesheets/svg-sprites',
                options: {
                    shape : {
                        dimension: {
                            maxWidth: 32,
                            maxHeight: 32,
                        },
                        spacing: {
                            padding:0,
                        }
    
                    },
                    mode: {
                        css : {
                            render: {
                                css: true
                            },
                            example:true
                        },
                        less: true,
                    }
                }
    
    
            }
        },
    

    when I run the above task with the --verbose option, I see the following in the output:

    ....
    Reading public/assets/dist/svgs/uncollapsed-triangle.svg...OK
    Reading public/assets/fonts/glyphicons-halflings-regular.svg...OK
    Reading public/assets/fonts/myraid-pro/MyriadPro-Regular.svg...OK
    Warning: Cannot read property 'replace' of undefined Use --force to continue.
    

    As per the log above, it is trying to read other directories as well that are outside the CWD path public/assets/dist/svgs. In fact, it goes on to read the root directory of project containing bower_components etc. and scans the entire project root.

    I thought using the cwd option with src option would restrict it to sub-directories of 'cwd' or directories relative to 'cwd'. Why are other directories being scanned?

    Am I missing something? Thank you for your help.

    解决方案

    Okay, I think I finally figured it out. There are actually two projects with very similar names:

    1. grunt-svg-sprite (https://www.npmjs.com/package/grunt-svg-sprite) and
    2. grunt-svg-sprites (https://www.npmjs.com/package/grunt-svg-sprites)

    I wanted to use the first project but installed the second one by mistake!!!!! Obviously it wouldn't have worked :-)

    I removed the erroneous module (2) and installed the first one - it works like a charm. Makes me wonder if the naming convention needs some thinking for npm modules.

    这篇关于Grunt cwd选项问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆