aboutsummaryrefslogtreecommitdiffstats
path: root/gulpfile.babel.js
diff options
context:
space:
mode:
authorLibravatar vantezzen <hello@vantezzen.io>2019-10-12 12:24:14 +0200
committerLibravatar vantezzen <hello@vantezzen.io>2019-10-12 12:24:14 +0200
commit362d034f4a24ed4579f1f7e36add582b66f4617d (patch)
treec2804f357473a6b6a0c5fcbe50e805bee6047b9c /gulpfile.babel.js
parentMerge pull request #109 from getferdi/l10n_develop (diff)
downloadferdium-app-362d034f4a24ed4579f1f7e36add582b66f4617d.tar.gz
ferdium-app-362d034f4a24ed4579f1f7e36add582b66f4617d.tar.zst
ferdium-app-362d034f4a24ed4579f1f7e36add582b66f4617d.zip
Add minifiers to gulp production builds
Diffstat (limited to 'gulpfile.babel.js')
-rw-r--r--gulpfile.babel.js15
1 files changed, 15 insertions, 0 deletions
diff --git a/gulpfile.babel.js b/gulpfile.babel.js
index 193f08813..4932d56f8 100644
--- a/gulpfile.babel.js
+++ b/gulpfile.babel.js
@@ -1,7 +1,12 @@
1/* eslint max-len: 0 */ 1/* eslint max-len: 0 */
2import gulp from 'gulp'; 2import gulp from 'gulp';
3import gulpIf from 'gulp-if';
3import babel from 'gulp-babel'; 4import babel from 'gulp-babel';
4import sass from 'gulp-sass'; 5import sass from 'gulp-sass';
6import csso from 'gulp-csso';
7import terser from 'terser';
8import composer from 'gulp-uglify/composer';
9import htmlMin from 'gulp-htmlmin';
5import server from 'gulp-server-livereload'; 10import server from 'gulp-server-livereload';
6import { exec } from 'child_process'; 11import { exec } from 'child_process';
7import dotenv from 'dotenv'; 12import dotenv from 'dotenv';
@@ -17,6 +22,8 @@ import * as rawStyleConfig from './src/theme/default/legacy.js';
17 22
18dotenv.config(); 23dotenv.config();
19 24
25const uglify = composer(terser, console);
26
20const styleConfig = Object.keys(rawStyleConfig).map((key) => { 27const styleConfig = Object.keys(rawStyleConfig).map((key) => {
21 const isHex = /^#[0-9A-F]{6}$/i.test(rawStyleConfig[key]); 28 const isHex = /^#[0-9A-F]{6}$/i.test(rawStyleConfig[key]);
22 return { 29 return {
@@ -124,6 +131,10 @@ export function mvLernaPackages() {
124export function html() { 131export function html() {
125 return gulp 132 return gulp
126 .src(paths.html.src, { since: gulp.lastRun(html) }) 133 .src(paths.html.src, { since: gulp.lastRun(html) })
134 .pipe(gulpIf(process.env.NODE_ENV !== 'development', htmlMin({ // Only minify in production to speed up dev builds
135 collapseWhitespace: true,
136 removeComments: true
137 })))
127 .pipe(gulp.dest(paths.html.dest)); 138 .pipe(gulp.dest(paths.html.dest));
128} 139}
129 140
@@ -148,6 +159,9 @@ export function styles() {
148 includePaths: ['./node_modules', '../node_modules'], 159 includePaths: ['./node_modules', '../node_modules'],
149 }).on('error', sass.logError), 160 }).on('error', sass.logError),
150 ) 161 )
162 .pipe((gulpIf(process.env.NODE_ENV !== 'development', csso({ // Only minify in production to speed up dev builds
163 restructure: false, // Don't restructure CSS, otherwise it will break the styles
164 }))))
151 .pipe(gulp.dest(paths.styles.dest)); 165 .pipe(gulp.dest(paths.styles.dest));
152} 166}
153 167
@@ -159,6 +173,7 @@ export function scripts() {
159 comments: false, 173 comments: false,
160 }), 174 }),
161 ) 175 )
176 .pipe(gulpIf(process.env.NODE_ENV !== 'development', uglify())) // Only uglify in production to speed up dev builds
162 .pipe(gulp.dest(paths.scripts.dest)); 177 .pipe(gulp.dest(paths.scripts.dest));
163} 178}
164 179