aboutsummaryrefslogtreecommitdiffstats
path: root/gulpfile.babel.js
diff options
context:
space:
mode:
Diffstat (limited to 'gulpfile.babel.js')
-rw-r--r--gulpfile.babel.js40
1 files changed, 15 insertions, 25 deletions
diff --git a/gulpfile.babel.js b/gulpfile.babel.js
index 193f08813..dda198c18 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 {
@@ -32,7 +39,6 @@ const paths = {
32 src: 'src', 39 src: 'src',
33 dest: 'build', 40 dest: 'build',
34 tmp: '.tmp', 41 tmp: '.tmp',
35 dictionaries: 'dictionaries',
36 package: `out/${config.version}`, 42 package: `out/${config.version}`,
37 recipes: { 43 recipes: {
38 src: 'recipes/*.tar.gz', 44 src: 'recipes/*.tar.gz',
@@ -124,6 +130,10 @@ export function mvLernaPackages() {
124export function html() { 130export function html() {
125 return gulp 131 return gulp
126 .src(paths.html.src, { since: gulp.lastRun(html) }) 132 .src(paths.html.src, { since: gulp.lastRun(html) })
133 .pipe(gulpIf(process.env.NODE_ENV !== 'development', htmlMin({ // Only minify in production to speed up dev builds
134 collapseWhitespace: true,
135 removeComments: true
136 })))
127 .pipe(gulp.dest(paths.html.dest)); 137 .pipe(gulp.dest(paths.html.dest));
128} 138}
129 139
@@ -148,6 +158,9 @@ export function styles() {
148 includePaths: ['./node_modules', '../node_modules'], 158 includePaths: ['./node_modules', '../node_modules'],
149 }).on('error', sass.logError), 159 }).on('error', sass.logError),
150 ) 160 )
161 .pipe((gulpIf(process.env.NODE_ENV !== 'development', csso({ // Only minify in production to speed up dev builds
162 restructure: false, // Don't restructure CSS, otherwise it will break the styles
163 }))))
151 .pipe(gulp.dest(paths.styles.dest)); 164 .pipe(gulp.dest(paths.styles.dest));
152} 165}
153 166
@@ -159,6 +172,7 @@ export function scripts() {
159 comments: false, 172 comments: false,
160 }), 173 }),
161 ) 174 )
175 .pipe(gulpIf(process.env.NODE_ENV !== 'development', uglify())) // Only uglify in production to speed up dev builds
162 .pipe(gulp.dest(paths.scripts.dest)); 176 .pipe(gulp.dest(paths.scripts.dest));
163} 177}
164 178
@@ -179,29 +193,6 @@ export function webserver() {
179 ); 193 );
180} 194}
181 195
182export function dictionaries(done) {
183 const { SPELLCHECKER_LOCALES } = require('./build/i18n/languages');
184
185 let packages = '';
186 Object.keys(SPELLCHECKER_LOCALES).forEach((key) => {
187 packages = `${packages} hunspell-dict-${key}`;
188 });
189
190 _shell(
191 `npm install --prefix "${path.join(__dirname, 'temp')}" ${packages}`,
192 () => {
193 moveSync(
194 path.join(__dirname, 'temp', 'node_modules'),
195 path.join(__dirname, 'build', paths.dictionaries),
196 );
197
198 removeSync(path.join(__dirname, 'temp'));
199
200 done();
201 },
202 );
203}
204
205export function recipes() { 196export function recipes() {
206 return gulp.src(paths.recipes.src, { since: gulp.lastRun(recipes) }) 197 return gulp.src(paths.recipes.src, { since: gulp.lastRun(recipes) })
207 .pipe(gulp.dest(paths.recipes.dest)); 198 .pipe(gulp.dest(paths.recipes.dest));
@@ -215,7 +206,6 @@ const build = gulp.series(
215 clean, 206 clean,
216 gulp.parallel(mvSrc, mvPackageJson, mvLernaPackages), 207 gulp.parallel(mvSrc, mvPackageJson, mvLernaPackages),
217 gulp.parallel(html, scripts, styles, recipes, recipeInfo), 208 gulp.parallel(html, scripts, styles, recipes, recipeInfo),
218 dictionaries,
219); 209);
220export { build }; 210export { build };
221 211