AHN JAE-HA 2015-10-23
step 8 추가
@c2ac9ae09cbe53d5bc66f6ff50a917c4ee582b69
package.json
--- package.json
+++ package.json
@@ -10,10 +10,12 @@
   "license": "ISC",
   "devDependencies": {
     "autoprefixer": "^5.2.0",
+    "browser-sync": "^2.9.11",
     "gulp": "^3.9.0",
     "gulp-autoprefixer": "^3.1.0",
     "gulp-concat": "^2.6.0",
     "gulp-minify-css": "^1.2.1",
+    "gulp-minify-html": "^1.0.4",
     "gulp-uglify": "^1.4.0"
   }
 }
 
step8_browser_sync/gulpfile.js (added)
+++ step8_browser_sync/gulpfile.js
@@ -0,0 +1,51 @@
+var gulp = require('gulp');
+var uglify = require('gulp-uglify');
+var concat = require('gulp-concat');
+var minifycss = require('gulp-minify-css');
+var minifyhtml = require('gulp-minify-html');
+var browserSync = require('browser-sync').create();
+
+//dist 폴더를 기준으로 웹서버 실행
+gulp.task('server', ['uglify', 'minifycss', 'minifyhtml'], function () {
+	return browserSync.init({
+		server: {
+			baseDir: './dist'
+		}
+	});
+});
+
+//HTML 파일을 minify
+gulp.task('minifyhtml', function () {
+	return gulp.src('src/**/*.html') //src 폴더 아래의 모든 html 파일을
+		.pipe(minifyhtml()) //minify 해서
+		.pipe(gulp.dest('dist')) //dist 폴더에 저장
+		.pipe(browserSync.reload({stream:true})); //browserSync 로 브라우저에 반영
+});
+
+//자바스크립트 파일을 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 폴더에 저장
+		.pipe(browserSync.reload({stream:true})); //browserSync 로 브라우저에 반영
+});
+
+//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 폴더에 저장
+		.pipe(browserSync.reload({stream:true})); //browserSync 로 브라우저에 반영
+});
+
+//파일 변경 감지
+gulp.task('watch', function () {
+	gulp.watch('src/**/*.js', ['uglify']);
+	gulp.watch('src/**/*.css', ['minifycss']);
+	gulp.watch('src/**/*.html', ['minifyhtml']);
+});
+
+//gulp를 실행하면 default 로 minifycss task를 실행
+gulp.task('default', ['server', 'watch']);
 
step8_browser_sync/src/css/dummy1.css (added)
+++ step8_browser_sync/src/css/dummy1.css
@@ -0,0 +1,4 @@
+/* dummy class a */
+a {
+    font-size: 1em;
+}
 
step8_browser_sync/src/css/dummy2.css (added)
+++ step8_browser_sync/src/css/dummy2.css
@@ -0,0 +1,4 @@
+/* dummy class b */
+b {
+    font-size: 2em;
+}
 
step8_browser_sync/src/index.html (added)
+++ step8_browser_sync/src/index.html
@@ -0,0 +1,13 @@
+<!DOCTYPE html>
+<html lang="ko">
+<head>
+    <meta charset="UTF-8">
+    <title>gulp example</title>
+    <link rel="stylesheet" type="text/css" href="css/main.css">
+</head>
+<body>
+    <h2>Hello World!</h2>
+
+    <script src="js/main.js"></script>
+</body>
+</html>
 
step8_browser_sync/src/js/dummy1.js (added)
+++ step8_browser_sync/src/js/dummy1.js
@@ -0,0 +1,4 @@
+//dummy hello world function
+function hello1 () {
+    console.log('hello world! - 1');
+}
 
step8_browser_sync/src/js/dummy2.js (added)
+++ step8_browser_sync/src/js/dummy2.js
@@ -0,0 +1,4 @@
+//dummy hello world function
+function hello2 () {
+    console.log('hello world! - 2');
+}
 
step8_browser_sync/src/js/dummy3.js (added)
+++ step8_browser_sync/src/js/dummy3.js
@@ -0,0 +1,4 @@
+//dummy hello world function
+function hello3 () {
+    console.log('hello world! - 3');
+}
Add a comment
List