javascript 开发/生产环境的替代 grunt.js 任务

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13800205/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 19:49:19  来源:igfitidea点击:

Alternate grunt.js tasks for dev/prod environments

javascriptnode.jsnpmgruntjs

提问by Ben

I am trying to set up my grunt.js file so it only runs the mintask when running on my production server - when running on my local dev server I don't want to minmy code with every change as it is unnecessary.

我正在尝试设置我的 grunt.js 文件,以便它只min在我的生产服务器上运行时运行任务 - 在我的本地开发服务器上运行时,我不想min每次更改我的代码,因为这是不必要的。

Any ideas on how grunt.js can differentiate between dev/prod environments?

关于 grunt.js 如何区分开发/生产环境的任何想法?

回答by Kyle Robinson Young

Register a production task:

注册一个生产任务:

// on the dev server, only concat
grunt.registerTask('default', ['concat']);

// on production, concat and minify
grunt.registerTask('prod', ['concat', 'min']);

On your dev server run gruntand on your production run grunt prod.

在您的开发服务器上运行grunt和在您的生产运行上grunt prod

You can setup finer grain targets per task as well:

您还可以为每个任务设置更细粒度的目标:

grunt.initConfig({
  min: {
    dev: {
      // dev server minify config
    },
    prod: {
      // production server minify config
    }
  }
});
grunt.registerTask('default', ['min:dev']);
grunt.registerTask('prod', ['min:prod']);