-
Notifications
You must be signed in to change notification settings - Fork 19
/
gulpfile.js
126 lines (113 loc) · 3.09 KB
/
gulpfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
'use strict';
// 使用するプラグイン
var
babelify = require("babelify"),
bower = require('gulp-bower'),
browserify = require("browserify"),
compass = require('gulp-compass'),
composer = require('gulp-composer'),
concat = require('gulp-concat'),
del = require('del'),
gulp = require('gulp'),
gulpFilter = require('gulp-filter'),
install = require("gulp-install"),
modernizr = require('gulp-modernizr'),
notify = require("gulp-notify"),
plumber = require("gulp-plumber"),
rename = require('gulp-rename'),
sass = require('gulp-ruby-sass'),
source = require("vinyl-source-stream"),
uglify = require("gulp-uglify")
;
// 初期設定
var config = {
jsSrcPath: './webroot/sources/js/',
jsPath: './webroot/assets/js/',
scssPath: './webroot/sources/scss/',
cssPath: './webroot/assets/css/',
fontsPath: './webroot/assets/fonts/',
bowerDir: './webroot/sources/bower_components/'
}
gulp.task('bower', function() {
return bower()
.pipe(gulp.dest(config.bowerDir))
});
gulp.task('clean', function (cb) {
return del('./webroot/assets');
});
gulp.task('setup', ['clean'], function () {
return gulp.src(['./bower.json'])
.pipe(install())
;
});
// JavaScriptを圧縮
gulp.task('js.uglify', function() {
return gulp.src(config.jsSrcPath + 'app.js')
.pipe(plumber())
.pipe(uglify({
preserveComments: 'some',
preserveComments: 'license' // ライセンスを残す
}))
.pipe(rename('app.min.js'))
.pipe(gulp.dest(config.jsPath))
;
});
// Modernizrの自動処理(出来上がったソースからModernizr使用箇所を自動的に抜き出して専用のModernizrを出力する)
gulp.task('js.modernizr', function() {
gulp.src(config.jsSrcPath + '*.js')
.pipe(modernizr())
// .pipe(uglify())
.pipe(gulp.dest(config.jsPath))
;
})
// ES6で書かれたjsを通常のjsに変換
gulp.task('js.babelify', function () {
browserify({
entries: "./webroot/sources/js/app.js",
extensions: [".js"]
})
.plugin('licensify')
.transform(babelify, {presets: ['es2015']})
.bundle()
.on("error", function (err) {
console.log("Error : " + err.message);
this.emit("end");
})
.pipe(source("app.js"))
.pipe(gulp.dest("./webroot/assets/js"));
});
// JavaScript関係の処理
gulp.task('js', ['js.babelify', 'js.uglify', 'js.modernizr']);
// アイコンフォント
gulp.task('icons', function() {
return gulp.src(config.bowerDir + 'fontawesome/fonts/**.*')
.pipe(gulp.dest(config.fontsPath))
.on('error', notify.onError(function (error) {
return 'Error: ' + error.message;
}))
;
});
// スタイルシートの更新
gulp.task('css', function(){
gulp.src(config.scssPath + '**/*.scss')
.pipe(compass({
config_file: 'config.rb',
comments: false,
css: config.cssPath,
sass: config.scssPath
}))
.on('error', function(err) {
console.log(err.message);
})
;
});
// 変更点があった場合の監視
gulp.task('watch', function() {
gulp.watch(config.sassPath + '*.scss', ['css']);
gulp.watch(config.jsPath + '*.js', ['js']);
});
// Composerを実行
gulp.task("composer", function () {
composer({ "self-install": false });
})
gulp.task('default', ['icons', 'css', 'js']);