Skip to content

Instantly share code, notes, and snippets.

@Phonbopit Phonbopit/gulpfile.js Secret
Last active Mar 6, 2019

Embed
What would you like to do?
var gulp = require('gulp');
// Import all gulp plugins
var minifyCSS = require('gulp-minify-css');
var rename = require('gulp-rename');
var uglify = require('gulp-uglify');
var concat = require('gulp-concat');
gulp.task('css' ,function() {
return gulp
.src('main.css') // ไฟล์ที่ต้องการ minify
.pipe(minifyCSS()) // สั่ง execute minifyCSS
.pipe(rename({ suffix: '.min' })) // หลังจาก minify ก็เพิ่ม .min ต่อท้ายชื่อไฟล์
.pipe(gulp.dest('assets')); // dest : คือโฟลเดอร์ที่ต้องการเซฟ
});
gulp.task('js', function() {
return gulp
.src('main.js') // ไฟล์ที่ต้องการ uglify()
.pipe(uglify()) // สั่ง execute uglify()
.pipe(rename({ suffix: '.min' })) // เพิ่ม .min ต่อท้ายไฟล์
.pipe(gulp.dest('assets')); // โฟลเดอร์ที่ต้องการเซฟ
});
gulp.task('watch', function() {
gulp.watch('main.css', ['css']);
gulp.watch('main.js', ['js']);
});
gulp.task('default', ['watch']);
gulp.task('all', ['css', 'js', 'watch']);
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Gulp Example</title>
<link href='//fonts.googleapis.com/css?family=Varela+Round' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="assets/main.min.css">
</head>
<body>
<div class="container" id="main">
<h1 class="title">Hello Gulp.js</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</div>
<script src="assets/main.min.js"></script>
</body>
</html>
body {
margin-top: 80px;
font-family: "Varela Round", sans-serif;
}
.container {
position: relative;
width: 800px;
margin: 0 auto;
padding: 20px;
background: #f6f6f6;
}
.container .title {
text-align: center;
color: #242424;
font-weight: bold;
}
.container p {
color: #666060;
}
.text-right {
text-align: right;
}
'use strict';
(function () {
console.log('Hello World');
var date = new Date();
var D = date.getDate();
var M = date.getMonth();
var Y = date.getFullYear();
var h = date.getHours();
var m = date.getMinutes() > 9 ? date.getMinutes() : '0' + date.getMinutes();
var stringDate = D + '/' + M + '/' + Y + ' ' + h + ' : ' + m;
document.getElementById('main').innerHTML += '<p class="text-right">Created At : ' + stringDate + '</p>';
})();
{
"name": "gulp-example",
"version": "1.0.0",
"devDependencies": {
"gulp": "^3.8.11",
"gulp-concat": "^2.5.2",
"gulp-minify-css": "^1.0.0",
"gulp-rename": "^1.2.2",
"gulp-uglify": "^1.2.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.