Skip to content

Commit

Permalink
docs: build JS with esbuild (#1686)
Browse files Browse the repository at this point in the history
Also, backport a few tweaks in application.js from upstream
  • Loading branch information
XhmikosR authored Apr 6, 2023
1 parent 4e2d991 commit c4d367a
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 33 deletions.
5 changes: 3 additions & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"node": true
},
"parserOptions": {
"ecmaVersion": 2019
"ecmaVersion": 2019,
"sourceType": "script"
},
"extends": "eslint:recommended",
"rules": {
Expand All @@ -29,7 +30,7 @@
"node": false
},
"parserOptions": {
"sourceType": "script"
"sourceType": "module"
}
}
]
Expand Down
4 changes: 0 additions & 4 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,6 @@ module:
target: assets/scss/bootstrap
- source: node_modules/bootstrap/dist/js/bootstrap.bundle.min.js
target: static/assets/js/vendor/bootstrap.bundle.min.js
- source: node_modules/clipboard/dist/clipboard.min.js
target: assets/js/vendor/clipboard.min.js
- source: node_modules/fuse.js/dist/fuse.min.js
target: assets/js/vendor/fuse.min.js

params:
description: "Official open source SVG icon library for Bootstrap"
Expand Down
15 changes: 9 additions & 6 deletions docs/assets/js/application.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
/* global ClipboardJS:false */
import ClipboardJS from 'clipboard'

(function () {
'use strict'
const btnHtml = [
'<div class="bd-clipboard">',
'<button type="button" class="btn-clipboard" title="Copy to clipboard">',
'<i class="bi bi-clipboard" aria-hidden="true"></i>',
'</button>',
'</div>'].join('')

const btnHtml = '<div class="bd-clipboard"><button type="button" class="btn-clipboard" title="Copy to clipboard"><i class="bi bi-clipboard" aria-hidden="true"></i></button></div>'

Array.prototype.slice.call(document.querySelectorAll('div.highlight'))
document.querySelectorAll('div.highlight')
.forEach(element => {
element.insertAdjacentHTML('beforebegin', btnHtml)
})
Expand Down Expand Up @@ -53,7 +56,7 @@
}

// Disable empty links in docs
Array.prototype.slice.call(document.querySelectorAll('[href="#"]'))
document.querySelectorAll('[href="#"]')
.forEach(link => {
link.addEventListener('click', event => {
event.preventDefault()
Expand Down
2 changes: 0 additions & 2 deletions docs/assets/js/color-modes.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
*/

(() => {
'use strict'

const storedTheme = localStorage.getItem('theme')

const getPreferredTheme = () => {
Expand Down
4 changes: 1 addition & 3 deletions docs/assets/js/search.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
/* global Fuse:false */
import Fuse from 'fuse.js'

(function () {
'use strict'

const iconsBody = document.querySelector('#icons-body')

if (!iconsBody) return
Expand Down
26 changes: 10 additions & 16 deletions docs/layouts/partials/scripts.html
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
<script async src="/assets/js/vendor/bootstrap.bundle.min.js"></script>

{{- if or .IsHome (eq .Page.Layout "sprite") -}}
{{- $fuseVendor := resources.Get "js/vendor/fuse.min.js" -}}
{{- $searchJs := resources.Get "js/search.js" -}}
{{- $searchBundle := slice $fuseVendor $searchJs | resources.Concat "assets/js/search.js" -}}

{{- if eq hugo.Environment "production" -}}
{{- $searchBundle = $searchBundle | resources.Minify -}}
{{- end }}
<script async src="{{ $searchBundle.Permalink | relURL }}"></script>
{{- end }}

{{- $clipboardVendor := resources.Get "js/vendor/clipboard.min.js" -}}
{{- $applicationJs := resources.Get "js/application.js" -}}
{{- $applicationBundle := slice $clipboardVendor $applicationJs | resources.Concat "assets/js/application.js" -}}
{{- $esbuildOptions := dict "target" "es2019" -}}

{{- if eq hugo.Environment "production" -}}
{{- $applicationBundle = $applicationBundle | resources.Minify -}}
{{- $esbuildOptions = merge $esbuildOptions (dict "minify" "true") -}}
{{- end -}}

{{- if or .IsHome (eq .Page.Layout "sprite") -}}
{{- $searchJs := resources.Get "js/search.js" | js.Build $esbuildOptions | resources.Copy "/assets/js/search.js" -}}
<script async src="{{ $searchJs.Permalink | relURL }}"></script>
{{- end }}
<script async src="{{ $applicationBundle.Permalink | relURL }}"></script>

{{- $application := resources.Get "js/application.js" | js.Build $esbuildOptions | resources.Copy "/assets/js/application.js" -}}
<script async src="{{ $application.Permalink | relURL }}"></script>

0 comments on commit c4d367a

Please sign in to comment.