我在我的客户端app.js中的angular.js中有此设置:
var options = {};
options.api = {};
options.api.base_url = "http://myDomainName.tld:8080";
在构建应用程序时,我需要能够在CLI上进行更改。
我的想法是用咕unt咕do做这件事。
还有其他想法如何解决这个问题吗?
您可以使用grunt-template模块。
将app.js
文件添加为app.js.tpl
。
app.js.tpl
var options = {};
options.api = {};
options.api.base_url = "<%= base_url %>";
Gruntfile.js
module.exports = function(grunt) {
grunt.initConfig({
'template': {
'process-js-template': {
'options': {
'data': {
'base_url': 'http://myDomainName.tld:8080'
//Can also use 'base_url': grunt.option('base_url')
//If you wanted to take it from the CLI.
//EG: grunt default --base_url=http://myDomainName.tld:8080
}
},
'files': {
//The key being where you want to save the file.
'path/to/app.js': ['path/to/app.js.tpl']
}
}
}
});
grunt.loadNpmTasks('grunt-template');
grunt.registerTask('default', [
'template'
]);
};
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句