问题
I'm trying to inject content via grunt-replace when I build by visual studio solution. However I would like to inject different content depending on the build configuration.
Is it possible to read the build configuration using grunt/node.
Thanks.
回答1:
You can use grunt.option
for this. Provide your build env on the command line and use it in the Gruntfile using grunt.option.
Quoting the example from grunt.option documentation
Gruntfile.js
grunt.initConfig({
compass: {
dev: {
options: {
/* ... */
outputStyle: 'expanded'
},
},
staging: {
options: {
/* ... */
outputStyle: 'compressed'
},
},
},
});
var target = grunt.option('target') || 'dev';
grunt.registerTask('deploy', ['compass:' + target]);
As you run grunt deploy your stylesheets would default to the dev target and output the CSS in the expanded format. If you ran grunt deploy --target=staging
the staging target would instead be ran and your CSS would be in the compressed format.
grunt deploy --target=staging
来源:https://stackoverflow.com/questions/29260774/injecting-content-via-grunt-task-depending-on-asp-net-project-build-configurati