Skip to content

Commit

Permalink
feat(js): Use built-in js minifier instead of babel
Browse files Browse the repository at this point in the history
*Better sizes compression
*Increase build speed

Signed-off-by: Khusika Dhamar Gusti <mail@khusika.com>
  • Loading branch information
Khusika Dhamar Gusti committed Jul 10, 2021
1 parent 3b90474 commit 0a9b06a
Show file tree
Hide file tree
Showing 8 changed files with 7 additions and 17 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Hugo default output directory
public/
/exampleSite/resources/
/exampleSite/assets/js/

node_modules/
build/
Expand Down
2 changes: 1 addition & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npm run build && npm run copy && git add resources assets/js
npm run build && npm run copy && git add resources
File renamed without changes.
3 changes: 0 additions & 3 deletions assets/js/theme.min.js

This file was deleted.

1 change: 0 additions & 1 deletion assets/js/theme.min.js.map

This file was deleted.

1 change: 0 additions & 1 deletion assets/js/themes.min.js

This file was deleted.

7 changes: 1 addition & 6 deletions layouts/partials/assets.html
Original file line number Diff line number Diff line change
Expand Up @@ -213,12 +213,7 @@
{{- $config | jsonify | printf "window.config=%s;" | dict "Content" | dict "Scratch" .Scratch "Data" | partial "scratch/script.html" -}}

{{- /* Theme script */ -}}
{{- if .Site.Params.SourceMap -}}
{{- dict "Source" "js/theme.min.js" "Fingerprint" $fingerprint | dict "Scratch" .Scratch "Data" | partial "scratch/script.html" -}}
{{- $_ := (resources.Get "js/theme.min.js.map").RelPermalink -}}
{{- else -}}
{{- dict "Source" "js/themes.min.js" "Fingerprint" $fingerprint | dict "Scratch" .Scratch "Data" | partial "scratch/script.html" -}}
{{- end -}}
{{- dict "Source" "js/theme.js" "Minify" true "Fingerprint" $fingerprint | dict "Scratch" .Scratch "Data" | partial "scratch/script.html" -}}

{{- with (.Scratch.Get "this").scriptArr -}}
{{- delimit . "\n" | dict "Content" | dict "Scratch" $.Scratch "Data" | partial "scratch/script.html" -}}
Expand Down
9 changes: 4 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,12 @@
},
"scripts": {
"preinstall": "npx npm-force-resolutions",
"babel": "npx babel src/js --out-file assets/js/theme.min.js --source-maps && npx babel src/js --out-file assets/js/themes.min.js",
"build": "rm -f -r exampleSite/public && npm run babel && hugo -v --source=exampleSite --themesDir ../ --gc",
"build": "rm -f -r exampleSite/public && hugo -v --source=exampleSite --themesDir ../ --gc",
"build-lunr-segmentit": "browserify src/lib/lunr.segmentit.js -o assets/lib/lunr/lunr.segmentit.js -t babelify --presets @babel/preset-env --presets minify",
"purgejs": "mkdir -p exampleSite/src/js && sed '593,597d;615,636d;639,642d;727d' src/js/theme.js > exampleSite/src/js/theme.js && npx babel exampleSite/src/js --out-file exampleSite/assets/js/themes.min.js --presets minify",
"purgejs": "mkdir -p exampleSite/assets/js && sed '593,597d;615,636d;639,642d;727d' assets/js/theme.js > exampleSite/assets/js/theme.js",
"deploy": "npm run purgejs && hugo -v --source=exampleSite --themesDir ../ --gc --minify",
"start": "npm run babel && hugo server --source=exampleSite --themesDir ../ -D --disableFastRender",
"start-production": "npm run babel && hugo server --source=exampleSite --themesDir ../ -D --disableFastRender -e production",
"start": "hugo server --source=exampleSite --themesDir ../ -D --disableFastRender",
"start-production": "hugo server --source=exampleSite --themesDir ../ -D --disableFastRender -e production",
"copy": "rm -rf resources && mv -f exampleSite/resources resources",
"reinstall": "rm -rf node_modules && npm install",
"prepare": "husky install"
Expand Down

0 comments on commit 0a9b06a

Please sign in to comment.