설치 설명 및 스텝 1~7 추가
@d7b645929d20cb49dfd3bfcc01a0261c4a5beef1
+++ .gitignore
... | ... | @@ -0,0 +1,27 @@ |
| 1 | +# Logs | |
| 2 | +logs | |
| 3 | +*.log | |
| 4 | + | |
| 5 | +# Runtime data | |
| 6 | +pids | |
| 7 | +*.pid | |
| 8 | +*.seed | |
| 9 | + | |
| 10 | +# Directory for instrumented libs generated by jscoverage/JSCover | |
| 11 | +lib-cov | |
| 12 | + | |
| 13 | +# Coverage directory used by tools like istanbul | |
| 14 | +coverage | |
| 15 | + | |
| 16 | +# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) | |
| 17 | +.grunt | |
| 18 | + | |
| 19 | +# node-waf configuration | |
| 20 | +.lock-wscript | |
| 21 | + | |
| 22 | +# Compiled binary addons (http://nodejs.org/api/addons.html) | |
| 23 | +build/Release | |
| 24 | + | |
| 25 | +# Dependency directory | |
| 26 | +# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git | |
| 27 | +node_modules |
+++ README.md
... | ... | @@ -0,0 +1,23 @@ |
| 1 | +## gulp 시작하기 | |
| 2 | + | |
| 3 | +gulp.js을 시작하기 위해 필요한 가장 기본적인 사용 방법들을 정리했습니다. | |
| 4 | + | |
| 5 | + | |
| 6 | +#### gulp 설치하기 | |
| 7 | + | |
| 8 | +gulp 를 사용하기에 앞서 node.js 와 npm 이 먼저 미리 설치되어 있어야 한다. node.js 와 npm 이 설치되었다면, 먼저 아래와 같이 package.json 파일을 생성해준다. | |
| 9 | + | |
| 10 | +```bash | |
| 11 | +$ npm init | |
| 12 | +``` | |
| 13 | + | |
| 14 | +package.json 파일이 생성되었다면, 아래와 같이 gulp 를 global 과 local 모두 설치해준다. | |
| 15 | + | |
| 16 | +```bash | |
| 17 | +$ npm install gulp --global | |
| 18 | +$ npm install gulp --save-dev | |
| 19 | +``` | |
| 20 | + | |
| 21 | +--save-dev 옵션으로 설치해주는 이유는, 대부분 gulp 가 production 이 아닌 개발 과정에서만 필요하기 때문에, NODE_ENV 의 값이 production 인 경우 gulp가 설치되지 않도록 하기 위함이다. | |
| 22 | + | |
| 23 | +이제 이어서 gulp의 설정 파일인 gulpfile.js 을 step1부터 차근차근 따라가며 만들어가보자. |
+++ package.json
... | ... | @@ -0,0 +1,19 @@ |
| 1 | +{ | |
| 2 | + "name": "gulp-example", | |
| 3 | + "version": "1.0.0", | |
| 4 | + "description": "", | |
| 5 | + "main": "index.js", | |
| 6 | + "scripts": { | |
| 7 | + "test": "echo \"Error: no test specified\" && exit 1" | |
| 8 | + }, | |
| 9 | + "author": "", | |
| 10 | + "license": "ISC", | |
| 11 | + "devDependencies": { | |
| 12 | + "autoprefixer": "^5.2.0", | |
| 13 | + "gulp": "^3.9.0", | |
| 14 | + "gulp-autoprefixer": "^3.1.0", | |
| 15 | + "gulp-concat": "^2.6.0", | |
| 16 | + "gulp-minify-css": "^1.2.1", | |
| 17 | + "gulp-uglify": "^1.4.0" | |
| 18 | + } | |
| 19 | +} |
+++ step1_hello_world/gulpfile.js
... | ... | @@ -0,0 +1,6 @@ |
| 1 | +var gulp = require('gulp');
| |
| 2 | + | |
| 3 | +// hello world 라고 콘솔에 찍는 task | |
| 4 | +gulp.task('hello', function () {
| |
| 5 | + return console.log('Hello World!');
| |
| 6 | +}); |
+++ step2_default task/gulpfile.js
... | ... | @@ -0,0 +1,9 @@ |
| 1 | +var gulp = require('gulp');
| |
| 2 | + | |
| 3 | +// hello world 라고 콘솔에 찍는 task | |
| 4 | +gulp.task('hello', function () {
| |
| 5 | + return console.log('Hello World!');
| |
| 6 | +}); | |
| 7 | + | |
| 8 | +//gulp를 실행하면 default 로 hello task 실행 | |
| 9 | +gulp.task('default', ['hello']);
|
+++ step3_series/gulpfile.js
... | ... | @@ -0,0 +1,14 @@ |
| 1 | +var gulp = require('gulp');
| |
| 2 | + | |
| 3 | +// hello 라고 콘솔에 찍는 task | |
| 4 | +gulp.task('hello', function () {
| |
| 5 | + return console.log('Hello');
| |
| 6 | +}); | |
| 7 | + | |
| 8 | +// world 라고 콘솔에 찍는 task, hello 라는 task가 먼저 완료된 뒤에만 실행된다. | |
| 9 | +gulp.task('world', ['hello'], function () {
| |
| 10 | + return console.log('World!');
| |
| 11 | +}); | |
| 12 | + | |
| 13 | +//gulp를 실행하면 default 로 world task를 실행 (world task는 먼저 hello task를 실행) | |
| 14 | +gulp.task('default', ['world']);
|
+++ step4_uglify/dist/dummy1.js
... | ... | @@ -0,0 +1,1 @@ |
| 1 | +function hello(){console.log("hello world! - 1")}(No newline at end of file) |
+++ step4_uglify/dist/dummy2.js
... | ... | @@ -0,0 +1,1 @@ |
| 1 | +function hello(){console.log("hello world! - 2")}(No newline at end of file) |
+++ step4_uglify/dist/dummy3.js
... | ... | @@ -0,0 +1,1 @@ |
| 1 | +function hello(){console.log("hello world! - 3")}(No newline at end of file) |
+++ step4_uglify/gulpfile.js
... | ... | @@ -0,0 +1,12 @@ |
| 1 | +var gulp = require('gulp');
| |
| 2 | +var uglify = require('gulp-uglify');
| |
| 3 | + | |
| 4 | +//자바스크립트 파일을 minify | |
| 5 | +gulp.task('uglify', function () {
| |
| 6 | + return gulp.src('src/*.js') //src 폴더 아래의 모든 js 파일을
| |
| 7 | + .pipe(uglify()) //minify 해서 | |
| 8 | + .pipe(gulp.dest('dist')); //dist 폴더에 저장
| |
| 9 | +}); | |
| 10 | + | |
| 11 | +//gulp를 실행하면 default 로 uglify task를 실행 | |
| 12 | +gulp.task('default', ['uglify']);
|
+++ step4_uglify/src/dummy1.js
... | ... | @@ -0,0 +1,4 @@ |
| 1 | +//dummy hello world function | |
| 2 | +function hello1 () {
| |
| 3 | + console.log('hello world! - 1');
| |
| 4 | +} |
+++ step4_uglify/src/dummy2.js
... | ... | @@ -0,0 +1,4 @@ |
| 1 | +//dummy hello world function | |
| 2 | +function hello2 () {
| |
| 3 | + console.log('hello world! - 2');
| |
| 4 | +} |
+++ step4_uglify/src/dummy3.js
... | ... | @@ -0,0 +1,4 @@ |
| 1 | +//dummy hello world function | |
| 2 | +function hello3 () {
| |
| 3 | + console.log('hello world! - 3');
| |
| 4 | +} |
+++ step5_watch/dist/dummy1.js
... | ... | @@ -0,0 +1,1 @@ |
| 1 | +function hello(){console.log("hello world! - 1")}(No newline at end of file) |
+++ step5_watch/dist/dummy2.js
... | ... | @@ -0,0 +1,1 @@ |
| 1 | +function hello(){console.log("hello world! - 2")}(No newline at end of file) |
+++ step5_watch/dist/dummy3.js
... | ... | @@ -0,0 +1,1 @@ |
| 1 | +function hello(){console.log("hello world! - 3")}(No newline at end of file) |
+++ step5_watch/gulpfile.js
... | ... | @@ -0,0 +1,17 @@ |
| 1 | +var gulp = require('gulp');
| |
| 2 | +var uglify = require('gulp-uglify');
| |
| 3 | + | |
| 4 | +//자바스크립트 파일을 minify | |
| 5 | +gulp.task('uglify', function () {
| |
| 6 | + return gulp.src('src/*.js') //src 폴더 아래의 모든 js 파일을
| |
| 7 | + .pipe(uglify()) //minify 해서 | |
| 8 | + .pipe(gulp.dest('dist')); //dist 폴더에 저장
| |
| 9 | +}); | |
| 10 | + | |
| 11 | +// 파일 변경 감지 | |
| 12 | +gulp.task('watch', function () {
| |
| 13 | + gulp.watch('src/*.js', ['uglify']);
| |
| 14 | +}); | |
| 15 | + | |
| 16 | +//gulp를 실행하면 default 로 uglify task와 watch task를 실행 | |
| 17 | +gulp.task('default', ['uglify', 'watch']);
|
+++ step5_watch/src/dummy1.js
... | ... | @@ -0,0 +1,4 @@ |
| 1 | +//dummy hello world function | |
| 2 | +function hello1 () {
| |
| 3 | + console.log('hello world! - 1');
| |
| 4 | +} |
+++ step5_watch/src/dummy2.js
... | ... | @@ -0,0 +1,4 @@ |
| 1 | +//dummy hello world function | |
| 2 | +function hello2 () {
| |
| 3 | + console.log('hello world! - 2');
| |
| 4 | +} |
+++ step5_watch/src/dummy3.js
... | ... | @@ -0,0 +1,4 @@ |
| 1 | +//dummy hello world function | |
| 2 | +function hello3 () {
| |
| 3 | + console.log('hello world! - 3');
| |
| 4 | +} |
+++ step6_concat/dist/main.js
... | ... | @@ -0,0 +1,1 @@ |
| 1 | +function hello(){console.log("hello world! - 1")}function hello(){console.log("hello world! - 2")}function hello(){console.log("hello world! - 3")}(No newline at end of file) |
+++ step6_concat/gulpfile.js
... | ... | @@ -0,0 +1,16 @@ |
| 1 | +var gulp = require('gulp');
| |
| 2 | +var uglify = require('gulp-uglify');
| |
| 3 | +var concat = require('gulp-concat');
| |
| 4 | + | |
| 5 | +gulp.task('uglify', function () {
| |
| 6 | + return gulp.src('src/*.js')
| |
| 7 | + .pipe(concat('main.js'))
| |
| 8 | + .pipe(uglify()) | |
| 9 | + .pipe(gulp.dest('dist'));
| |
| 10 | +}); | |
| 11 | + | |
| 12 | +gulp.task('watch', function () {
| |
| 13 | + gulp.watch('src/*.js', ['uglify']);
| |
| 14 | +}); | |
| 15 | + | |
| 16 | +gulp.task('default', ['uglify', 'watch']);
|
+++ step6_concat/src/dummy1.js
... | ... | @@ -0,0 +1,4 @@ |
| 1 | +//dummy hello world function | |
| 2 | +function hello1 () {
| |
| 3 | + console.log('hello world! - 1');
| |
| 4 | +} |
+++ step6_concat/src/dummy2.js
... | ... | @@ -0,0 +1,4 @@ |
| 1 | +//dummy hello world function | |
| 2 | +function hello2 () {
| |
| 3 | + console.log('hello world! - 2');
| |
| 4 | +} |
+++ step6_concat/src/dummy3.js
... | ... | @@ -0,0 +1,4 @@ |
| 1 | +//dummy hello world function | |
| 2 | +function hello3 () {
| |
| 3 | + console.log('hello world! - 3');
| |
| 4 | +} |
+++ step7_css_minify/gulpfile.js
... | ... | @@ -0,0 +1,29 @@ |
| 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 | + | |
| 6 | +//자바스크립트 파일을 minify | |
| 7 | +gulp.task('uglify', function () {
| |
| 8 | + return gulp.src('src/**/*.js') //src 폴더 아래의 모든 js 파일을
| |
| 9 | + .pipe(concat('main.js')) //병합하고
| |
| 10 | + .pipe(uglify()) //minify 해서 | |
| 11 | + .pipe(gulp.dest('dist/js')); //dist 폴더에 저장
| |
| 12 | +}); | |
| 13 | + | |
| 14 | +//CSS 파일을 minify | |
| 15 | +gulp.task('minifycss', function () {
| |
| 16 | + return gulp.src('src/**/*.css') //src 폴더 아래의 모든 css 파일을
| |
| 17 | + .pipe(concat('main.css')) //병합하고
| |
| 18 | + .pipe(minifycss()) //minify 해서 | |
| 19 | + .pipe(gulp.dest('dist/css')); //dist 폴더에 저장
| |
| 20 | +}); | |
| 21 | + | |
| 22 | +//파일 변경 감지 | |
| 23 | +gulp.task('watch', function () {
| |
| 24 | + gulp.watch('src/**/*.js', ['uglify']);
| |
| 25 | + gulp.watch('src/**/*.css', ['minifycss']);
| |
| 26 | +}); | |
| 27 | + | |
| 28 | +//gulp를 실행하면 default 로 minifycss task를 실행 | |
| 29 | +gulp.task('default', ['uglify', 'minifycss', 'watch']);
|
+++ step7_css_minify/src/css/dummy1.css
... | ... | @@ -0,0 +1,4 @@ |
| 1 | +/* dummy class a */ | |
| 2 | +a {
| |
| 3 | + font-size: 1em; | |
| 4 | +} |
+++ step7_css_minify/src/css/dummy2.css
... | ... | @@ -0,0 +1,4 @@ |
| 1 | +/* dummy class b */ | |
| 2 | +b {
| |
| 3 | + font-size: 2em; | |
| 4 | +} |
+++ step7_css_minify/src/js/dummy1.js
... | ... | @@ -0,0 +1,4 @@ |
| 1 | +//dummy hello world function | |
| 2 | +function hello1 () {
| |
| 3 | + console.log('hello world! - 1');
| |
| 4 | +} |
+++ step7_css_minify/src/js/dummy2.js
... | ... | @@ -0,0 +1,4 @@ |
| 1 | +//dummy hello world function | |
| 2 | +function hello2 () {
| |
| 3 | + console.log('hello world! - 2');
| |
| 4 | +} |
+++ step7_css_minify/src/js/dummy3.js
... | ... | @@ -0,0 +1,4 @@ |
| 1 | +//dummy hello world function | |
| 2 | +function hello3 () {
| |
| 3 | + console.log('hello world! - 3');
| |
| 4 | +} |
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?