1 | const gulp = require('gulp');
|
2 | // Gulp プラグインを一括で読み込む
|
3 | const gulpLoadPlugins = require('gulp-load-plugins');
|
4 | const $ = gulpLoadPlugins();
|
5 |
|
6 | /* ================================================================================
|
7 | * 関数定義
|
8 | * ================================================================================ */
|
9 |
|
10 | /**
|
11 | * SCSS をビルドする Function
|
12 | *
|
13 | * @param {String} ビルドするファイル名。'*' を渡せば src/styles/ 配下の全ファイルが対象となる
|
14 | * @return {Stream}
|
15 | */
|
16 | function buildCss(fileName) {
|
17 | return gulp
|
18 | .src([`./src/styles/${fileName}.scss`]) // エントリポイント
|
19 | .pipe($.plumber(function(error) {
|
20 | return this.emit('end');
|
21 | }))
|
22 | .pipe(
|
23 | $.sass({
|
24 | outputStyle: 'compressed'
|
25 | })
|
26 | .on('error', $.sass.logError)
|
27 | )
|
28 | .pipe(gulp.dest('./dist/styles')); // ./dist/styles/ 配下に出力する
|
29 | }
|
30 |
|
31 | /**
|
32 | * JavaScript をビルドする Function
|
33 | *
|
34 | * @param {String} ビルドするファイル名。'*' を渡せば src/scripts/ 配下の全ファイルが対象となる
|
35 | * @return {Stream}
|
36 | */
|
37 | function buildJs(fileName) {
|
38 | return gulp
|
39 | .src(`src/scripts/${fileName}.js`) // src/scripts/ 配下の指定ファイルを対象にビルドする
|
40 | .pipe($.plumber()) // エラー時にプロセスが落ちないようにするプラグイン
|
41 | .pipe($.uglify({
|
42 | compress: true, // ビルドする
|
43 | mangle: true, // 変数の難読化を行う
|
44 | output: {
|
45 | comments: 'some' // 「*!」で始まるブロックコメントを残す
|
46 | }
|
47 | }))
|
48 | .pipe(gulp.dest('dist/scripts/')); // dist/scripts/ 配下に出力する (対象ディレクトリがなくても OK・ファイルは上書き)
|
49 | }
|
50 |
|
51 | /* ================================================================================
|
52 | * タスク定義
|
53 | * ================================================================================ */
|
54 |
|
55 | /**
|
56 | * CSS ビルド … 全ファイル
|
57 | *
|
58 | * @return {Stream}
|
59 | */
|
60 | gulp.task('build-css', () => {
|
61 | return buildCss('*');
|
62 | });
|
63 |
|
64 | /**
|
65 | * CSS ビルド … Corredor
|
66 | *
|
67 | * @return {Stream}
|
68 | */
|
69 | gulp.task('build-css-corredor', () => {
|
70 | return buildCss('Corredor');
|
71 | });
|
72 |
|
73 | /**
|
74 | * CSS ビルド … Murga
|
75 | *
|
76 | * @return {Stream}
|
77 | */
|
78 | gulp.task('build-css-murga', () => {
|
79 | return buildCss('Murga');
|
80 | });
|
81 |
|
82 | /**
|
83 | * CSS ビルド … El Mylar
|
84 | *
|
85 | * @return {Stream}
|
86 | */
|
87 | gulp.task('build-css-elmylar', () => {
|
88 | return buildCss('ElMylar');
|
89 | });
|
90 |
|
91 | /**
|
92 | * CSS ビルド … Bit-Archer
|
93 | *
|
94 | * @return {Stream}
|
95 | */
|
96 | gulp.task('build-css-bitarcher', () => {
|
97 | return buildCss('BitArcher');
|
98 | });
|
99 |
|
100 | /**
|
101 | * JavaScript ビルド … 全ファイル
|
102 | *
|
103 | * @return {Stream}
|
104 | */
|
105 | gulp.task('build-js', () => {
|
106 | return buildJs('*');
|
107 | });
|
108 |
|
109 | /**
|
110 | * JavaScript ビルド … Corredor
|
111 | *
|
112 | * @return {Stream}
|
113 | */
|
114 | gulp.task('build-js-corredor', () => {
|
115 | return buildJs('Corredor');
|
116 | });
|
117 |
|
118 | /**
|
119 | * JavaScript ビルド … Corredor Check
|
120 | *
|
121 | * @return {Stream}
|
122 | */
|
123 | gulp.task('build-js-corredor-check', () => {
|
124 | return buildJs('CorredorCheck');
|
125 | });
|
126 |
|
127 | /**
|
128 | * JavaScript ビルド … Murga
|
129 | *
|
130 | * @return {Stream}
|
131 | */
|
132 | gulp.task('build-js-murga', () => {
|
133 | return buildJs('Murga');
|
134 | });
|
135 |
|
136 | /**
|
137 | * JavaScript ビルド … El Mylar
|
138 | *
|
139 | * @return {Stream}
|
140 | */
|
141 | gulp.task('build-js-elmylar', () => {
|
142 | return buildJs('ElMylar');
|
143 | });
|
144 |
|
145 | /**
|
146 | * JavaScript ビルド … Bit-Archer
|
147 | *
|
148 | * @return {Stream}
|
149 | */
|
150 | gulp.task('build-js-bitarcher', () => {
|
151 | return buildJs('BitArcher');
|
152 | });
|