如何将一个项目variablesconfig.get()放到Grunt中的任务initConfig中?
在Grunt中,我有一个自定义的多任务从HTML文件中提取path,并使用grunt.config.set()
将这些find的path添加到名为“pathsfound”的configuration数组中。
我想使用grunt.config.get()
来访问这些path,以便我可以使用它们来连接,uglify等。
Gruntfile.coffee
pathfinder: dist: files: [ expand: true cwd: '<%= yeoman.app %>' src: '*.html' ] concat: dist: src: grunt.config.get('pathsfound') dest: 'stuff.js'
我的注册任务如下所示:
grunt.registerTask 'dist', ['pathfinder:dist', 'concat:dist']
但是,concat任务给了我一个TypeError: Cannot call method 'indexOf' of undefined
错误的TypeError: Cannot call method 'indexOf' of undefined
,提示grunt.config.get()
在initConfig中找不到pathsfound
variables。
有没有办法在initConfig阶段延迟加载configurationvariables?
你编写它的方式, grunt.config.get
调用在configuration对象被构build时执行,所以你的variables还没有。
稍后让grunt加载它们的方法是使用模板来代替:
concat: dist: src: "<%= pathsfound.bower %>"
这些模板在任务运行之前就被延迟了。 如果设置configuration的任务在需要它的任务之前运行,它应该工作。