Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
244 views
in Technique[技术] by (71.8m points)

javascript - Alternate grunt.js tasks for dev/prod environments

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

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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 grunt and on your production run 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']);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...