[英]Development mode for AngularJS using GruntJS
I have a couple of products that started off with the yeoman angular generator, and it has been a pretty good dev setup. 我有几个产品从yeoman角度发生器开始,它是一个非常好的开发设置。 One thing I haven't been able to find a good solution for is setting a development/production mode flag.
我无法找到一个好的解决方案是设置开发/生产模式标志。
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. 当然,我们使用一些我们在生产中只需要的工具,因此使用prod / dev变量可以使用内联JavaScript和/或HTML文件非常有用。 I searched for solutions online before but haven't found anything useful.
我以前在网上搜索过解决方案但没有找到任何有用的东西。
Ultimately, I'm looking for a good solution to use in an AngularJS setting, ideally set via grunt serve and/or build run. 最终,我正在寻找一个在AngularJS设置中使用的好解决方案,理想情况下通过grunt服务和/或构建运行来设置。 What are other teams doing here?
其他球队在这做什么?
I'm using ng-constant . 我正在使用ng-constant 。 It creates a .js file which contains some angular constants of your choice.
它会创建一个.js文件,其中包含您选择的一些角度常量。
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',
...
]);
And don't forget to include this /scripts/config.js file in your html and inject 'config' into your app. 并且不要忘记在您的html中包含此/scripts/config.js文件并将“config”注入您的应用程序。
var app = angular.module('myApp', [
'config',
...
]);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.