Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ class Options {
return this._options['sassOptions'];
}

get terser() {
return this._options['terser'];
}

_normalizeFilePath(optionName) {
const {_options} = this;

Expand All @@ -87,7 +91,7 @@ class Options {
Option ${optionName} contains '\\' characters.

This can be due to using Windows paths in a config file, which is not
supported, or because its use is legitimate in POSIX paths.
supported, or because its use is legitimate in POSIX paths.

In the first case, you should edit your 'gulpfile.js' and change any
paths to be in POSIX format.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"gulp-replace-task": "^0.11.0",
"gulp-sass": "^3.2.0",
"gulp-sourcemaps": "1.6.0",
"gulp-terser": "^2.0.0",
"gulp-util": "^3.0.8",
"gulp-watch": "^5.0.1",
"gulp-zip": "^3.2.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@

const chalk = require('chalk');
const fs = require('fs-extra');
const gulpIf = require('gulp-if');
const rename = require('gulp-rename');
const replace = require('gulp-replace-task');
const sourcemaps = require('gulp-sourcemaps');
const terser = require('gulp-terser');
const _ = require('lodash');
const path = require('path');
const PluginError = require('plugin-error');
Expand Down Expand Up @@ -91,6 +94,7 @@ module.exports = function () {
'build:fix-at-directives',
'build:r2',
'build:copy:fontAwesome',
'build:minify:js',
Copy link
Contributor Author

@jbalsas jbalsas Dec 22, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait until the very end and then minify all the things. Keep in mind that we don't have a babel step ourselves, but people could configure it on their own, so chances are we're going to break things if that's the case (at least for sourcemaps).

'build:war',
cb
);
Expand Down Expand Up @@ -313,6 +317,17 @@ module.exports = function () {
);
});

gulp.task('build:minify:js', () => {
const production = process.env.NODE_ENV === 'production';

return gulp
.src(pathBuild.join('**', '*.js').asPosix)
.pipe(gulpIf(production, sourcemaps.init()))
.pipe(gulpIf(production, terser(options.terser || {})))
.pipe(gulpIf(production, sourcemaps.write('.')))
.pipe(gulp.dest(pathBuild));
});

gulp.task('build:war', (done) => {
runSequence('plugin:version', 'plugin:war', done);
});
Expand Down
28 changes: 27 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7076,6 +7076,16 @@ [email protected]:
through2 "^2.0.0"
vinyl "^1.0.0"

gulp-terser@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/gulp-terser/-/gulp-terser-2.0.0.tgz#07f95ef9121fe9d4970c3c4ee775c9cd658d0474"
integrity sha512-8KxzgUpNeLsSujUCrNKUiSI1ioO5TfW4ODhbM+wzNTWgYp7yCIl1c/5EeOI+SOXaNLi+BzzMqrbb0eYMIThFCQ==
dependencies:
plugin-error "^1.0.1"
terser "5.4.0"
through2 "^4.0.2"
vinyl-sourcemaps-apply "^0.2.1"

gulp-util@^3.0, gulp-util@^3.0.0, gulp-util@^3.0.4, gulp-util@^3.0.7, gulp-util@^3.0.8:
version "3.0.8"
resolved "https://registry.yarnpkg.com/gulp-util/-/gulp-util-3.0.8.tgz#0054e1e744502e27c04c187c3ecc505dd54bbb4f"
Expand Down Expand Up @@ -12552,7 +12562,7 @@ read-pkg@^5.0.0, read-pkg@^5.2.0:
parse-json "^5.0.0"
type-fest "^0.6.0"

"readable-stream@2 || 3", readable-stream@^3.0.6, readable-stream@^3.1.1:
"readable-stream@2 || 3", readable-stream@3, readable-stream@^3.0.6, readable-stream@^3.1.1:
version "3.6.0"
resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-3.6.0.tgz#337bbda3adc0706bd3e024426a286d4b4b2c9198"
integrity sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA==
Expand Down Expand Up @@ -14504,6 +14514,15 @@ [email protected], terser@^5.3.8:
source-map "~0.7.2"
source-map-support "~0.5.19"

[email protected]:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes me super sad... the fact that gulp-terser requires [email protected] and yet we apparently use 4.8.0 befuddles me 😂

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

html-webpack-plugin (last published 10 days ago 🎉) and more directly html-minifier-terser (last published 7 months ago 😢) are the main culprits:

yarn why terser                                                                                                                                             0.29s [wincent/fix-ci] ~/code/liferay-frontend-projects
yarn why v1.22.5
[1/4] 🤔  Why do we have the module "terser"...?
[2/4] 🚚  Initialising dependency graph...
warning Missing version in workspace at "/Users/greghurrell/code/liferay-frontend-projects/projects/js-themes-toolkit", ignoring.
[3/4] 🔍  Finding dependency...
[4/4] 🚡  Calculating file sizes...
=> Found "[email protected]"
info Has been hoisted to "terser"
info Reasons this module exists
   - "workspace-aggregator-2b18f523-66b8-4ae1-9a79-f299cab4ade8" depends on it
   - Hoisted from "_project_#@liferay#npm-scripts#terser"
   - Hoisted from "_project_#terser-webpack-plugin#terser"
info Disk size without dependencies: "2.95MB"
info Disk size with unique dependencies: "3.94MB"
info Disk size with transitive dependencies: "3.95MB"
info Number of shared dependencies: 4
=> Found "gulp-terser#[email protected]"
info This module exists because "_project_#liferay-theme-tasks#gulp-terser" depends on it.
info Disk size without dependencies: "2.61MB"
info Disk size with unique dependencies: "3.6MB"
info Disk size with transitive dependencies: "3.61MB"
info Number of shared dependencies: 4
=> Found "html-minifier-terser#[email protected]"
info This module exists because "_project_#@liferay#npm-scripts#html-webpack-plugin#html-minifier-terser" depends on it.
info Disk size without dependencies: "1.86MB"
info Disk size with unique dependencies: "2.85MB"
info Disk size with transitive dependencies: "2.87MB"
info Number of shared dependencies: 4
✨  Done in 0.96s.

And people wonder why I am so grumpy about dependencies...

version "5.4.0"
resolved "https://registry.yarnpkg.com/terser/-/terser-5.4.0.tgz#9815c0839072d5c894e22c6fc508fbe9f5e7d7e8"
integrity sha512-3dZunFLbCJis9TAF2VnX+VrQLctRUmt1p3W2kCsJuZE4ZgWqh//+1MZ62EanewrqKoUf4zIaDGZAvml4UDc0OQ==
dependencies:
commander "^2.20.0"
source-map "~0.7.2"
source-map-support "~0.5.19"

terser@^4.6.3:
version "4.8.0"
resolved "https://registry.yarnpkg.com/terser/-/terser-4.8.0.tgz#63056343d7c70bb29f3af665865a46fe03a0df17"
Expand Down Expand Up @@ -14590,6 +14609,13 @@ through2@^3.0.0, through2@^3.0.1:
inherits "^2.0.4"
readable-stream "2 || 3"

through2@^4.0.2:
version "4.0.2"
resolved "https://registry.yarnpkg.com/through2/-/through2-4.0.2.tgz#a7ce3ac2a7a8b0b966c80e7c49f0484c3b239764"
integrity sha512-iOqSav00cVxEEICeD7TjLB1sueEL+81Wpzp2bY17uZjZN0pWZPuo4suZ/61VujxmqSGFfgOcNuTZ85QJwNZQpw==
dependencies:
readable-stream "3"

through@2, "through@>=2.2.7 <3", through@^2.3.6, through@^2.3.8, through@~2.3, through@~2.3.4:
version "2.3.8"
resolved "https://registry.yarnpkg.com/through/-/through-2.3.8.tgz#0dd4c9ffaabc357960b1b724115d7e0e86a2e1f5"
Expand Down