Skip to content

Instantly share code, notes, and snippets.

@TomoyaShibata
Created April 25, 2014 02:11
Show Gist options
  • Save TomoyaShibata/11275833 to your computer and use it in GitHub Desktop.
Save TomoyaShibata/11275833 to your computer and use it in GitHub Desktop.
jsファイルの結合・圧縮をgruntを使って完全自動化 ref: http://qiita.com/bps_tomoya/items/a8dac15c764d9dfca354
> npm install grunt-contrib-concat -save-dev
> npm install grunt-contrib-uglify -save-dev
> npm install grunt-contrib-watch -save-dev
> grunt watch
Running "watch" task
Waiting...
>> File "js\original.js" changed.
Running "concat:files" (concat) task
File js/concat/hogehoge.js created.
Running "uglify:dist" (uglify) task
File js/min/hogehoge-min.js created: 155 B → 87 B
Done, without errors.
Completed in 0.918s at Fri Apr 25 2014 10:59:44 GMT+0900 (東京 (標準時)) - Waiting...
grunt.initConfig({
watch: {
js: {
files: 'js/*.js', // 監視対象ファイル
tasks: ['concat', 'uglify'] // 実行させるタスク
}
}
});
grunt.loadNpmTasks('grunt-contrib-watch');
module.exports = function (grunt) {
var pkg = grunt.file.readJSON('package.json');
grunt.initConfig({
concat: {
files: {
// 元ファイルの指定
src : 'js/*.js',
// 出力ファイルの指定
dest: 'js/concat/hogehoge.js'
}
},
uglify: {
dist: {
files: {
// 出力ファイル: 元ファイル
'js/min/hogehoge-min.js': 'js/concat/hogehoge.js'
}
}
},
watch: {
js: {
files: 'js/*.js',
tasks: ['concat', 'uglify']
}
}
});
// プラグインのロード・デフォルトタスクの登録
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.registerTask('default', ['concat', 'uglify']);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment