我有两个咕unt配置,如下所示
grunt.registerTask('default', ['copy','jade','sass','browserify']);
grunt.registerTask('dev',['copy','jade','sass','browserify','watch']);
现在,因为我使用的是grunt-contrib-watch
,所以我需要在下面添加脚本
script(src='//localhost:35729/livereload.js')
用于实时录取的工作。如何根据生产环境选择添加脚本。拥有两个index.jade
文件是一个选项,这使我可以通过此部分,但是还有许多其他变量(例如API root等)取决于构建环境。在这种情况下为生产和开发环境建立的最佳实践是什么?
编辑
可以肯定。以上index.jade
只是一个示例。考虑JS代码中的以下行
RestangularProvider.setBaseUrl("http://localhost:3000");
对于开发和生产,参数需要分开。拥有两份生产代码和开发代码是完全不合逻辑的。
我更喜欢使用 --build
index.jade
if env.debug
script(src='//localhost:35729/livereload.js')
gruntfile
module.exports = function(grunt) {
var DEBUG = grunt.option('build') === 'dev';
// Configure Jade to conditionally render livereload.js
// with DEBUG === true
grunt.initConfig({
pug: {
options: {
data: function() {
return {
env: {
debug: DEBUG
}
};
}
}
}
});
}
使用它像
grunt dev --build=dev
您可以通过Grunt
传递任何ENV特定数据grunt --build=dev
--api-endpoint=/api/foo