如何将一个项目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的任务在需要它的任务之前运行,它应该工作。
- 在“module”全局variables上运行grunt-typescript时,angular-mock和node.js发生冲突
- grunt-injector不注入文件
- Grunt:自定义任务开发的方法
- 如何用grunt.loglogging彩色信息
- 通过代理或不使用grunt执行摩卡testing
- Node / Grunt – Autoprefixer – 如何添加configuration到我的Gruntfile.js&如何检查支持的浏览器?
- 一旦grunt任务完成,如何打印出文本?
- 使用requirejs加载一个带有几个类的文件(grunt-concat)
- RequireJS 2.1.9使用Grunt时会导致“最大调用堆栈..”错误