Skip to content

Commit

Permalink
Merge pull request #4 from ajcrites/terser
Browse files Browse the repository at this point in the history
feat(terser): use terser over uglify-es
  • Loading branch information
ajcrites authored Feb 20, 2019
2 parents e0cd3f8 + b01ac77 commit 8d46827
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 20 deletions.
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"bin": "dist/index.js",
"types": "lib",
"scripts": {
"prepublishOnly": "rimraf lib dist && tsc --project tsconfig.build.json && cp src/bin.js lib && ncc build lib/bin.js -m -e uglify-es -e html-minifier",
"prepublishOnly": "rimraf lib dist && tsc --project tsconfig.build.json && cp src/bin.js lib && ncc build lib/bin.js -m -e html-minifier",
"test": "tsc && tslint --project tsconfig.json"
},
"husky": {
Expand Down Expand Up @@ -41,9 +41,12 @@
"mkdirp-promise": "^5.0.1",
"mz": "^2.7.0",
"rmfr": "^2.0.0",
"uglify-es": "^3.3.9",
"terser": "^3.16.1",
"yargs": "^12.0.1"
},
"files": ["/lib", "/dist"],
"files": [
"/lib",
"/dist"
],
"repository": "github:ajcrites/scutage"
}
12 changes: 8 additions & 4 deletions src/scutage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import { JSDOM } from 'jsdom';
import { readFile, writeFile, copyFile, exists } from 'mz/fs';
import * as mkdirp from 'mkdirp-promise';
import * as rmfr from 'rmfr';
import { minify } from 'html-minifier';
import { minify as htmlMinify } from 'html-minifier';
import { basename, dirname } from 'path';
import * as uglifyEs from 'uglify-es';
import { minify as jsMinify } from 'terser';

import * as globby from 'globby';

Expand Down Expand Up @@ -56,7 +56,11 @@ not loaded by your static HTML file, you should copy it to ${output} after \`scu

// Minify all script tags with JavaScript text
[].slice.call(doc.querySelectorAll('script:not([src])')).map(elem => {
elem.textContent = uglifyEs.minify(elem.textContent).code;
const minifyResult = jsMinify(elem.textContent);
if (minifyResult.error) {
throw minifyResult.error;
}
elem.textContent = minifyResult.code;
});

// Transform all link tags into style tags with their contents
Expand Down Expand Up @@ -86,7 +90,7 @@ not loaded by your static HTML file, you should copy it to ${output} after \`scu
}),
);

const content = minify(dom.serialize(), {
const content = htmlMinify(dom.serialize(), {
collapseBooleanAttributes: true,
collapseInlineTagWhitespace: true,
collapseWhitespace: true,
Expand Down
37 changes: 24 additions & 13 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,11 @@ browser-process-hrtime@^0.1.2:
version "0.1.2"
resolved "https://registry.yarnpkg.com/browser-process-hrtime/-/browser-process-hrtime-0.1.2.tgz#425d68a58d3447f02a04aa894187fce8af8b7b8e"

buffer-from@^1.0.0:
version "1.1.1"
resolved "https://registry.yarnpkg.com/buffer-from/-/buffer-from-1.1.1.tgz#32713bc028f75c02fdb710d7c7bcec1f2c6070ef"
integrity sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A==

builtin-modules@^1.0.0, builtin-modules@^1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/builtin-modules/-/builtin-modules-1.1.1.tgz#270f076c5a72c02f5b65a47df94c5fe3a278892f"
Expand Down Expand Up @@ -436,14 +441,10 @@ [email protected], commander@~2.16.0:
version "2.16.0"
resolved "https://registry.yarnpkg.com/commander/-/commander-2.16.0.tgz#f16390593996ceb4f3eeb020b31d78528f7f8a50"

commander@^2.12.1, commander@^2.14.1, commander@^2.9.0:
commander@^2.12.1, commander@^2.14.1, commander@^2.9.0, commander@~2.17.1:
version "2.17.1"
resolved "https://registry.yarnpkg.com/commander/-/commander-2.17.1.tgz#bd77ab7de6de94205ceacc72f1716d29f20a77bf"

commander@~2.13.0:
version "2.13.0"
resolved "https://registry.yarnpkg.com/commander/-/commander-2.13.0.tgz#6964bca67685df7c1f1430c584f07d7597885b9c"

component-emitter@^1.2.1:
version "1.2.1"
resolved "https://registry.yarnpkg.com/component-emitter/-/component-emitter-1.2.1.tgz#137918d6d78283f7df7a6b7c5a63e140e69425e6"
Expand Down Expand Up @@ -2214,6 +2215,14 @@ source-map-resolve@^0.5.0:
source-map-url "^0.4.0"
urix "^0.1.0"

source-map-support@~0.5.9:
version "0.5.10"
resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.5.10.tgz#2214080bc9d51832511ee2bab96e3c2f9353120c"
integrity sha512-YfQ3tQFTK/yzlGJuX8pTwa4tifQj4QS2Mj7UegOu8jAz59MqIiMGPXxQhVQiIMNzayuUSF/jEuVnfFF5JqybmQ==
dependencies:
buffer-from "^1.0.0"
source-map "^0.6.0"

source-map-url@^0.4.0:
version "0.4.0"
resolved "https://registry.yarnpkg.com/source-map-url/-/source-map-url-0.4.0.tgz#3e935d7ddd73631b97659956d55128e87b5084a3"
Expand All @@ -2222,7 +2231,7 @@ [email protected], source-map@^0.5.6:
version "0.5.7"
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.5.7.tgz#8a039d2d1021d22d1ea14c80d8ea468ba2ef3fcc"

source-map@~0.6.0, source-map@~0.6.1:
source-map@^0.6.0, source-map@~0.6.0, source-map@~0.6.1:
version "0.6.1"
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.6.1.tgz#74722af32e9614e9c287a8d0bbde48b5e2f1a263"

Expand Down Expand Up @@ -2354,6 +2363,15 @@ symbol-tree@^3.2.2:
version "3.2.2"
resolved "https://registry.yarnpkg.com/symbol-tree/-/symbol-tree-3.2.2.tgz#ae27db38f660a7ae2e1c3b7d1bc290819b8519e6"

terser@^3.16.1:
version "3.16.1"
resolved "https://registry.yarnpkg.com/terser/-/terser-3.16.1.tgz#5b0dd4fa1ffd0b0b43c2493b2c364fd179160493"
integrity sha512-JDJjgleBROeek2iBcSNzOHLKsB/MdDf+E/BOAJ0Tk9r7p9/fVobfv7LMJ/g/k3v9SXdmjZnIlFd5nfn/Rt0Xow==
dependencies:
commander "~2.17.1"
source-map "~0.6.1"
source-map-support "~0.5.9"

thenify-all@^1.0.0:
version "1.6.0"
resolved "https://registry.yarnpkg.com/thenify-all/-/thenify-all-1.6.0.tgz#1a1918d402d8fc3f98fbf234db0bcc8cc10e9726"
Expand Down Expand Up @@ -2526,13 +2544,6 @@ typescript@^3.2.2:
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.2.2.tgz#fe8101c46aa123f8353523ebdcf5730c2ae493e5"
integrity sha512-VCj5UiSyHBjwfYacmDuc/NOk4QQixbE+Wn7MFJuS0nRuPQbof132Pw4u53dm264O8LPc2MVsc7RJNml5szurkg==

uglify-es@^3.3.9:
version "3.3.9"
resolved "https://registry.yarnpkg.com/uglify-es/-/uglify-es-3.3.9.tgz#0c1c4f0700bed8dbc124cdb304d2592ca203e677"
dependencies:
commander "~2.13.0"
source-map "~0.6.1"

[email protected]:
version "3.4.7"
resolved "https://registry.yarnpkg.com/uglify-js/-/uglify-js-3.4.7.tgz#4df6b92e54789aa921a254cb1e33704d6ec12b89"
Expand Down

0 comments on commit 8d46827

Please sign in to comment.