step 16 select task 추가
@60a464c3075e6881ce2303cc52bd8ff79c1f2389
--- README.md
+++ README.md
... | ... | @@ -78,6 +78,7 @@ |
| 78 | 78 |
- [Step 13. runSequence를 사용해서 직렬/병렬로 실행하기](./step13_run_sequence) |
| 79 | 79 |
- [Step 14. React + Browserify + Babel 빌드하기](./step14_react) |
| 80 | 80 |
- [Step 15. 다중 엔트리 React + Browserify + Watchify + Babel 빌드하기](./step15_watchify) |
| 81 |
+- [Step 16. 수행할 작업을 메뉴에서 선택해서 실행하기](./step16_select_task) |
|
| 81 | 82 |
|
| 82 | 83 |
#### Gulp 를 활용하는데 도움이 되는 링크들 |
| 83 | 84 |
- [Gulp Recipes](https://github.com/gulpjs/gulp/tree/master/docs/recipes) |
+++ step16_select_task/gulpfile.js
... | ... | @@ -0,0 +1,66 @@ |
| 1 | +var gulp = require('gulp');
| |
| 2 | +var uglify = require('gulp-uglify');
| |
| 3 | +var concat = require('gulp-concat');
| |
| 4 | +var minifycss = require('gulp-minify-css');
| |
| 5 | +var minifyhtml = require('gulp-minify-html');
| |
| 6 | +var plumber = require('gulp-plumber');
| |
| 7 | +var runSequence = require('run-sequence');
| |
| 8 | +var inquirer = require('inquirer');
| |
| 9 | + | |
| 10 | +var errorHandler = function (error) {
| |
| 11 | + console.error(error.message); | |
| 12 | + this.emit('end');
| |
| 13 | +}; | |
| 14 | +var plumberOption = {
| |
| 15 | + errorHandler: errorHandler | |
| 16 | +} | |
| 17 | + | |
| 18 | +gulp.task('minifyhtml', function () {
| |
| 19 | + return gulp.src('src/**/*.html')
| |
| 20 | + .pipe(plumber(plumberOption)) | |
| 21 | + .pipe(minifyhtml()) | |
| 22 | + .pipe(gulp.dest('dist'));
| |
| 23 | +}); | |
| 24 | + | |
| 25 | +gulp.task('uglify', function () {
| |
| 26 | + return gulp.src('src/**.*.js')
| |
| 27 | + .pipe(plumber(plumberOption)) | |
| 28 | + .pipe(uglify()) | |
| 29 | + .pipe(concat('main.js'))
| |
| 30 | + .pipe(gulp.dest('dist/js'));
| |
| 31 | +}); | |
| 32 | + | |
| 33 | +gulp.task('minifycss', function () {
| |
| 34 | + return gulp.src('src/**/*.css')
| |
| 35 | + .pipe(plumber(plumberOption)) | |
| 36 | + .pipe(minifycss()) | |
| 37 | + .pipe(concat('main.css'))
| |
| 38 | + .pipe(gulp.dest('dist/css'));
| |
| 39 | +}); | |
| 40 | + | |
| 41 | +gulp.task('watch', function () {
| |
| 42 | + gulp.watch('src/**/*.js', ['uglify']);
| |
| 43 | + gulp.watch('src/**/*.css', ['minifycss']);
| |
| 44 | + gulp.watch('src/**/*.html', ['minifyhtml']);
| |
| 45 | +}); | |
| 46 | + | |
| 47 | +gulp.task('build', ['uglify', 'minifycss', 'minifyhtml']);
| |
| 48 | + | |
| 49 | +gulp.task('default', function (done) {
| |
| 50 | + inquirer.prompt([ | |
| 51 | + {
| |
| 52 | + type: 'list', | |
| 53 | + name: 'task', | |
| 54 | + message: '어떤 작업을 수행하시겠습니까?', | |
| 55 | + choices: [ | |
| 56 | + { name: 'JavaScript 빌드', value: 'uglify' },
| |
| 57 | + { name: 'CSS 빌드', value: 'minifycss' },
| |
| 58 | + { name: 'HTML 빌드', value: 'minifyhtml' },
| |
| 59 | + new inquirer.Separator(), | |
| 60 | + { name: '전체 빌드', value: 'build' }
| |
| 61 | + ] | |
| 62 | + } | |
| 63 | + ]).then(function (answers) {
| |
| 64 | + runSequence(answers.task, done); | |
| 65 | + }); | |
| 66 | +}); |
+++ step16_select_task/package.json
... | ... | @@ -0,0 +1,28 @@ |
| 1 | +{ | |
| 2 | + "name": "gulp-step-by-step", | |
| 3 | + "version": "1.0.0", | |
| 4 | + "description": "gulp.js 를 시작하기 위한 간단한 예제들과 설명", | |
| 5 | + "main": "index.js", | |
| 6 | + "scripts": { | |
| 7 | + "test": "echo \"Error: no test specified\" && exit 1" | |
| 8 | + }, | |
| 9 | + "repository": { | |
| 10 | + "type": "git", | |
| 11 | + "url": "git+https://github.com/eu81273/gulp-step-by-step.git" | |
| 12 | + }, | |
| 13 | + "author": "AHN JAE-HA", | |
| 14 | + "license": "MIT", | |
| 15 | + "bugs": { | |
| 16 | + "url": "https://github.com/eu81273/gulp-step-by-step/issues" | |
| 17 | + }, | |
| 18 | + "devDependencies": { | |
| 19 | + "gulp": "^3.9.0", | |
| 20 | + "gulp-concat": "^2.6.0", | |
| 21 | + "gulp-minify-css": "^1.2.1", | |
| 22 | + "gulp-minify-html": "^1.0.4", | |
| 23 | + "gulp-plumber": "^1.0.1", | |
| 24 | + "gulp-uglify": "^1.4.0", | |
| 25 | + "inquirer": "^1.1.0", | |
| 26 | + "run-sequence": "^1.1.5" | |
| 27 | + } | |
| 28 | +} |
+++ step16_select_task/src/css/dummy1.css
... | ... | @@ -0,0 +1,3 @@ |
| 1 | +h2 {
| |
| 2 | + color: blue; | |
| 3 | +} |
+++ step16_select_task/src/css/dummy2.css
... | ... | @@ -0,0 +1,3 @@ |
| 1 | +b {
| |
| 2 | + font-size: 5em; | |
| 3 | +} |
+++ step16_select_task/src/dummy.html
... | ... | @@ -0,0 +1,1 @@ |
| 1 | +<!-- 내용없음! --> |
+++ step16_select_task/src/index.html
... | ... | @@ -0,0 +1,13 @@ |
| 1 | +<!DOCTYPE html> | |
| 2 | +<html lang="ko"> | |
| 3 | +<head> | |
| 4 | + <meta charset="UTF-8"> | |
| 5 | + <title>gulp example</title> | |
| 6 | + <link rel="stylesheet" type="text/css" href="css/main.css"> | |
| 7 | +</head> | |
| 8 | +<body> | |
| 9 | + <h2 id="title"></h2> | |
| 10 | + | |
| 11 | + <script src="js/main.js"></script> | |
| 12 | +</body> | |
| 13 | +</html> |
+++ step16_select_task/src/js/main.js
... | ... | @@ -0,0 +1,3 @@ |
| 1 | +(function () { | |
| 2 | + document.getElementById('title').text = "Hello World!" | |
| 3 | +})(); |
Add a comment
Delete comment
Once you delete this comment, you won't be able to recover it. Are you sure you want to delete this comment?