【发布时间】:2014-04-06 15:12:57
【问题描述】:
我一直在尝试从一个 grunt 任务中找到为我的所有 grunt 任务设置全局选项的最佳方法,但没有太多运气让事情正常工作。
我想知道任务是否以某种方式编译,以便它们被初始选项值卡住,或者是否可以在运行时更改选项(当 watch 任务正在运行时),我只是做错了事。
基本情况
这是一个特定的情况(注意 Gruntfile 是用 coffeescript 编写的)。我从以下任务开始:
sass:
options:
sourcemap: true
compile:
files:
"css/style.css" : "sass/style.sass"
我想要做什么
我希望能够从另一个任务中动态设置 sourcemap 选项,如下所示:
sass:
options:
sourcemap: '<% grunt.options('local') %>'
compile:
files:
"css/style.css" : "sass/style.sass"
watch 任务将获取更改,并运行一个任务来适当地设置全局选项。
watch:
local:
files: ['local.json']
tasks: ['local']
dist:
files: ['dist.json']
tasks: ['dist']
grunt.option('local', true) # Base declaration
grunt.registerTask( 'local', 'Local is true', () -> grunt.option('local', true) )
grunt.registerTask( 'dist', 'Local is false', () -> grunt.option('no-local') )
我希望对其进行配置,以便在“本地”或“dist”任务运行之后触发的任何任务(例如当watch 再次运行sass 任务时)它将使用我的“本地”的最新值选项。我尝试了几种方法,这似乎是最有希望的,但我还没有让它按预期工作。
【问题讨论】:
标签: coffeescript gruntjs grunt-contrib-watch