【问题标题】:grunt configurable variablesgrunt 可配置变量
【发布时间】:2013-12-14 12:12:43
【问题描述】:

我正在使用 grunt,我在配置中添加了一个参数:

grunt.initConfig({
        // configurable paths
        yeoman: {
            app: 'app',
            dist: 'dist',
            assetsRoot: [
                '../',
                '../a/b/c/',
                '../d/d/s/'
        },
        .
        .
        .

后来我使用了那些变量。例如:

        clean: {
            dist: {
                files: [{
                    dot: true,
                    src: [
                        '.tmp',
                        '<%= yeoman.dist %>/*', // --> dist/*
                        '!<%= yeoman.dist %>/.git*' // --> !dist/*
                    ]
                }]
            },
            server: '.tmp'
        },

但后来我想使用 assetsRoot 参数,它是一个数组而不是字符串。但如果我这样做:

        connect: {
            server: {
                options: {
                    open: true,
                    base: [
                        './',
                        '.tmp'
                    ].concat('<%= yeoman.assetsRoot %>')
                }
            },
        }

但这会将字符串连接到数组而不是组合数组! 我明白了:

connect.server.options.base = ['./', '.tmp', '[ "../", "../a/b/c/", "../d/d/s/"]']

代替:

connect.server.options.base = ['./', '.tmp', '../', '../a/b/c/', '../d/d/s/']

知道如何解决这个问题吗?

【问题讨论】:

  • 我不确定,但你可以试试 .concat('') 吗?

标签: javascript node.js gruntjs yeoman


【解决方案1】:

您正在输出用单引号括起来的 assetRoot 数组,所以是的,它是一个字符串。编译后的输出将如下所示:

[1, 2].concat('[3, 4]')

'&lt;%= yeoman.assetsRoot %&gt;' 替换为&lt;%= yeoman.assetsRoot %&gt;,以便生成一个数组。

【讨论】:

  • 然后我得到SyntaxError: Unexpected token &lt;
猜你喜欢
  • 2013-11-07
  • 2013-08-18
  • 2018-01-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-07-15
  • 2013-08-30
相关资源
最近更新 更多