我有两个grunt配置,如下所示
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代码中下面一行的example.Consider
RestangularProvider.setBaseUrl("http://localhost:3000");对于开发和生产,该参数都需要分开。有两份生产和开发代码副本是完全不合逻辑的。
发布于 2017-03-11 03:56:15
我更喜欢使用像--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传递任何特定于环境的数据
grunt --build=dev \
--api-endpoint=/api/foohttps://stackoverflow.com/questions/42726594
复制相似问题