diff options
author | Vijay A <avijayr@protonmail.com> | 2021-05-09 09:00:17 +0530 |
---|---|---|
committer | Vijay Raghavan Aravamudhan <vraravam@users.noreply.github.com> | 2021-05-09 17:27:22 +0530 |
commit | 26a8fe5904487beebe3ec0d904612baff22f7c80 (patch) | |
tree | 60f9ba86a55b30be5f88e763f1e2a923a8f451b0 /gulpfile.babel.js | |
parent | Fixing missed default translation file from prior commit. (diff) | |
download | ferdium-app-26a8fe5904487beebe3ec0d904612baff22f7c80.tar.gz ferdium-app-26a8fe5904487beebe3ec0d904612baff22f7c80.tar.zst ferdium-app-26a8fe5904487beebe3ec0d904612baff22f7c80.zip |
Minor refactoring to pull into reusable function in gulpfile.
Diffstat (limited to 'gulpfile.babel.js')
-rw-r--r-- | gulpfile.babel.js | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/gulpfile.babel.js b/gulpfile.babel.js index 692ada685..dff694b46 100644 --- a/gulpfile.babel.js +++ b/gulpfile.babel.js | |||
@@ -24,6 +24,10 @@ dotenv.config(); | |||
24 | 24 | ||
25 | const uglify = composer(terser, console); | 25 | const uglify = composer(terser, console); |
26 | 26 | ||
27 | const isDevBuild = ((process.env.NODE_ENV || 'development').trim().toLowerCase() === 'development'); | ||
28 | |||
29 | const getTargetEnv = isDevBuild ? 'development' : 'production'; | ||
30 | |||
27 | const styleConfig = Object.keys(rawStyleConfig).map((key) => { | 31 | const styleConfig = Object.keys(rawStyleConfig).map((key) => { |
28 | const isHex = /^#[0-9A-F]{6}$/i.test(rawStyleConfig[key]); | 32 | const isHex = /^#[0-9A-F]{6}$/i.test(rawStyleConfig[key]); |
29 | return { | 33 | return { |
@@ -147,7 +151,7 @@ export function exportBuildInfo() { | |||
147 | export function html() { | 151 | export function html() { |
148 | return gulp | 152 | return gulp |
149 | .src(paths.html.src, { since: gulp.lastRun(html) }) | 153 | .src(paths.html.src, { since: gulp.lastRun(html) }) |
150 | .pipe(gulpIf(process.env.NODE_ENV !== 'development', htmlMin({ // Only minify in production to speed up dev builds | 154 | .pipe(gulpIf(!isDevBuild, htmlMin({ // Only minify in production to speed up dev builds |
151 | collapseWhitespace: true, | 155 | collapseWhitespace: true, |
152 | removeComments: true, | 156 | removeComments: true, |
153 | }))) | 157 | }))) |
@@ -162,10 +166,7 @@ export function styles() { | |||
162 | sassVariables( | 166 | sassVariables( |
163 | Object.assign( | 167 | Object.assign( |
164 | { | 168 | { |
165 | $env: | 169 | $env: getTargetEnv, |
166 | process.env.NODE_ENV === 'development' | ||
167 | ? 'development' | ||
168 | : 'production', | ||
169 | }, | 170 | }, |
170 | ...styleConfig, | 171 | ...styleConfig, |
171 | ), | 172 | ), |
@@ -176,7 +177,7 @@ export function styles() { | |||
176 | includePaths: ['./node_modules', '../node_modules'], | 177 | includePaths: ['./node_modules', '../node_modules'], |
177 | }).on('error', sass.logError), | 178 | }).on('error', sass.logError), |
178 | ) | 179 | ) |
179 | .pipe((gulpIf(process.env.NODE_ENV !== 'development', csso({ // Only minify in production to speed up dev builds | 180 | .pipe((gulpIf(!isDevBuild, csso({ // Only minify in production to speed up dev builds |
180 | restructure: false, // Don't restructure CSS, otherwise it will break the styles | 181 | restructure: false, // Don't restructure CSS, otherwise it will break the styles |
181 | })))) | 182 | })))) |
182 | .pipe(gulp.dest(paths.styles.dest)) | 183 | .pipe(gulp.dest(paths.styles.dest)) |
@@ -190,10 +191,7 @@ export function verticalStyle() { | |||
190 | sassVariables( | 191 | sassVariables( |
191 | Object.assign( | 192 | Object.assign( |
192 | { | 193 | { |
193 | $env: | 194 | $env: getTargetEnv, |
194 | process.env.NODE_ENV === 'development' | ||
195 | ? 'development' | ||
196 | : 'production', | ||
197 | }, | 195 | }, |
198 | ...styleConfig, | 196 | ...styleConfig, |
199 | ), | 197 | ), |
@@ -204,7 +202,7 @@ export function verticalStyle() { | |||
204 | includePaths: ['./node_modules', '../node_modules'], | 202 | includePaths: ['./node_modules', '../node_modules'], |
205 | }).on('error', sass.logError), | 203 | }).on('error', sass.logError), |
206 | ) | 204 | ) |
207 | .pipe((gulpIf(process.env.NODE_ENV !== 'development', csso({ // Only minify in production to speed up dev builds | 205 | .pipe((gulpIf(!isDevBuild, csso({ // Only minify in production to speed up dev builds |
208 | restructure: false, // Don't restructure CSS, otherwise it will break the styles | 206 | restructure: false, // Don't restructure CSS, otherwise it will break the styles |
209 | })))) | 207 | })))) |
210 | .pipe(gulp.dest(paths.verticalStyle.dest)) | 208 | .pipe(gulp.dest(paths.verticalStyle.dest)) |
@@ -219,7 +217,7 @@ export function scripts() { | |||
219 | comments: false, | 217 | comments: false, |
220 | }), | 218 | }), |
221 | ) | 219 | ) |
222 | .pipe(gulpIf(process.env.NODE_ENV !== 'development', uglify())) // Only uglify in production to speed up dev builds | 220 | .pipe(gulpIf(!isDevBuild, uglify())) // Only uglify in production to speed up dev builds |
223 | .pipe(gulp.dest(paths.scripts.dest)) | 221 | .pipe(gulp.dest(paths.scripts.dest)) |
224 | .pipe(connect.reload()); | 222 | .pipe(connect.reload()); |
225 | } | 223 | } |