Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
238 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 Answer

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']);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...