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