我真的很想能夠擁有一個開發grunt文件並使用相同的文件生成腳本版本。用於開發/生產環境的替代grunt.js任務
我已經試過這個建議,但是當我嘗試調用dev/prod參數時,我的腳本會失敗。我相信答案是針對舊版本的grunt,或者可能是我正在使用的插件。
module.exports = function (grunt) {
// load all grunt tasks
require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
compass: {
dev: {
options: {
config: 'config.rb',
force: true,
livereload: true
}
}
},
uglify: {
build: {
src: ['docroot/js/*.js', 'docroot/components/**/*.js'],
dest: 'docroot/dis/main.min.js'
}
},
watch: {
options: {
dateFormat: function(time) {
grunt.log.writeln('The watch finished in ' + time + 'ms at' + (new Date()).toString());
grunt.log.writeln('Waiting for more changes...');
},
livereload: true
},
sass: {
files: ['docroot/sass/*.scss'],
tasks: ['compass:dev']
},
/* watch and see if our javascript files change, or new packages are installed */
js: {
files: '<%= uglify.build.src %>',
tasks: ['uglify']
},
/* watch our files for change, reload */
livereload: {
files: ['*.html', 'docroot/css/*.css', 'docroot/img/*', 'docroot/js/{main.min.js, plugins.min.js}'],
options: {
livereload: true
}
}
}
});
grunt.registerTask('default', 'watch');
};
真的,只要我可以得到兩個版本,稱他們用,例如運行:
grunt //local
grunt prod //live
然後我就可以玩的腳本,什麼加載。
我想你要找的是什麼「選項」 - https://github.com/gruntjs/grunt/wiki/grunt.option - 我相信這仍然是正確的方法。 也檢出yeoman,因爲他們有一個乾淨的設置與各種有用的件到這個難題。所有你必須記住的是grunt服務器和grunt構建。 – Dylan