简体   繁体   English

如何使用Grunt更改Requirejs配置设置?

[英]How do I use Grunt to change a Requirejs config setting?

I'm precompiling Handlebars templates and loading them through Requirejs. 我正在预编译车把模板并通过Requirejs加载它们。

Grunt creates a build and does all the precompiling and whatnot. Grunt创建一个构建,并进行所有预编译等操作。

Next step is to use Handlebars Runtime instead of the full Handlebars script. 下一步是使用Handlebars Runtime,而不是完整的Handlebars脚本。

In the RequireJS config, the path to Handlebars is set: 在RequireJS配置中,设置了Handlebars的路径:

js/src/config.js : js/src/config.js

require.config({
    //...
    paths: { handlebars: 'lib/handlebars' }
    //...
});

For a particular Grunt task, I wish to include an option that will change this path to handlebars.runtime , so that when the whole thing is compressed into a single file it only has the runtime version of Handlebars. 对于特定的Grunt任务,我希望包括一个将此路径更改为handlebars.runtime的选项,以便当将整个内容压缩到单个文件中时,它仅具有Handlebars的运行时版本。

The config that gets included into the build would therefore be: 因此,包含在构建中的配置为:

require.config({
    //...
    paths: { handlebars: 'lib/handlebars.runtime' }
    //...
});

Is this possible? 这可能吗? Is there a better of way achieving the same result? 是否有更好的方法可以达到相同的结果?

you can pass options to grunt tasks - is this what you want to do? 您可以通过选项来执行任务-这是您想要做的吗?

grunt myTask --myOption value

which is then available in your grunt config for that task (in your case require) like so: 然后可以在您的grunt配置中为该任务提供(按您的情况要求),如下所示:

grunt.option('myOption')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM