开发模式,使用GruntJS AngularJS [英] Development mode for AngularJS using GruntJS
问题描述
我有几个产品,与自耕农角发生器开始了,而且它一直是pretty良好的开发设置。有一件事我一直没能找到一个好的解决方案是设置一个开发/生产模式标志。
I have a couple of products that started off with the yeoman angular generator, and it has been a pretty good dev setup. One thing I haven't been able to find a good solution for is setting a development/production mode flag.
当然,我们使用,我们只需要在生产中所以有,我们可以使用内联JavaScript和/或HTML文件将是非常有益刺的/ dev可变一些工具。我搜索了网上的解决方案之前,但没有发现任何有用的。
Naturally we use a few tools that we only want on in production so having prod/dev variable that we can use both inline JavaScript and/or HTML files would be quite useful. I searched for solutions online before but haven't found anything useful.
最后,我正在寻找一个好的解决方案在AngularJS的设置使用,通过咕噜理想位置服务和/或建立运行。什么是其他球队来这里干什么?
Ultimately, I'm looking for a good solution to use in an AngularJS setting, ideally set via grunt serve and/or build run. What are other teams doing here?
推荐答案
我使用 NG-恒。它创建一个包含您所选择的某些角度常数.js文件。
I'm using ng-constant. It creates a .js file which contains some angular constants of your choice.
grunt.initConfig({
...
ngconstant: {
options: {
name: 'config',
dest: '<%= yeoman.app %>/scripts/config.js'
},
development: {
constants: {
myVariable: 'it is development'
}
},
production: {
constants: {
myVariable: 'it is production'
}
}
}
});
然后只需将其添加到您的任务:
And then just add it to your tasks:
grunt.registerTask('serve', [
...
'ngconstant:development',
...
]);
和不要忘了包括此/scripts/config.js文件在您的HTML和注入'配置'到你的应用程序。
And don't forget to include this /scripts/config.js file in your html and inject 'config' into your app.
var app = angular.module('myApp', [
'config',
...
]);
这篇关于开发模式,使用GruntJS AngularJS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!