Created
April 25, 2014 02:11
-
-
Save TomoyaShibata/11275833 to your computer and use it in GitHub Desktop.
jsファイルの結合・圧縮をgruntを使って完全自動化 ref: http://qiita.com/bps_tomoya/items/a8dac15c764d9dfca354
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> npm install grunt-contrib-concat -save-dev | |
> npm install grunt-contrib-uglify -save-dev | |
> npm install grunt-contrib-watch -save-dev |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> 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... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
grunt.initConfig({ | |
watch: { | |
js: { | |
files: 'js/*.js', // 監視対象ファイル | |
tasks: ['concat', 'uglify'] // 実行させるタスク | |
} | |
} | |
}); | |
grunt.loadNpmTasks('grunt-contrib-watch'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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