Skip to content

Commit

Permalink
Use jsDelivr to vendor the dependencies
Browse files Browse the repository at this point in the history
This way we need to vendor less extra stuff, and we can use jsDelivr's
ESM builds for packages that are not ESM-compatible out of the box, such
as scroll-lock.
  • Loading branch information
Perlence committed Dec 4, 2024
1 parent c5ba516 commit 5eac016
Show file tree
Hide file tree
Showing 434 changed files with 70 additions and 70,753 deletions.
13 changes: 7 additions & 6 deletions layouts/_default/baseof.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,19 @@
<meta name="twitter:description" content="{{ .Description }}">
<meta name="twitter:url" content="{{ .Permalink }}">
{{- /* TODO: Favicons */}}
<script src="/vendor/[email protected]/dist/scroll-lock.min.js" defer></script>
<script type="importmap">
{
"imports": {
"alpinejs": "/vendor/[email protected]/dist/module.esm.min.js",
"autosize": "/vendor/[email protected]/dist/autosize.esm.js",
"swiper": "/vendor/[email protected]/swiper.min.mjs",
"swiper/modules/pagination": "/vendor/[email protected]/modules/pagination.min.mjs"
"alpinejs": "/vendor/[email protected]",
"autosize": "/vendor/[email protected]",
"scroll-lock": "/vendor/[email protected]",
"swiper": "/vendor/[email protected]",
"swiper/css": "/vendor/[email protected]",
"swiper/css/pagination": "/vendor/[email protected]",
"swiper/modules/pagination": "/vendor/[email protected]",
}
}
</script>
<link rel="stylesheet" href="/vendor/[email protected]/swiper-bundle.min.css">
{{- with resources.Get "sass/main.scss" }}
{{- $opts := dict "transpiler" "libsass" "targetPath" "css/style.css" }}
{{- with . | toCSS $opts }}
Expand Down
2 changes: 2 additions & 0 deletions layouts/about/about.html
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ <h2 class="about--title">Team</h2>
<script type="module">
import Swiper from 'swiper';
import Pagination from 'swiper/modules/pagination';
import 'swiper/css';
import 'swiper/css/pagination';

const swiper = new Swiper('.swiper', {
grabCursor: true,
Expand Down
1 change: 1 addition & 0 deletions layouts/partials/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@

<script type="module">
import Alpine from "alpinejs";
import scrollLock from 'scroll-lock';

const mediaMd = '(min-width: 768px)';

Expand Down
32 changes: 11 additions & 21 deletions static/vendor/README.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,20 @@
# How to vendor a package
# How to vendor packages

1. Download the package from npm:
1. Find the package on [jsDelivr](https://www.jsdelivr.com/), e.g.
https://www.jsdelivr.com/package/npm/alpinejs.
2. Download the package as an ESM module. If the module name contains slashes
`/`, replace them with dashes `-`.

```sh
npm pack swiper

# Or, optionally, specify the version
npm pack [email protected]
```

2. Unpack and remove the `tgz` file:

```sh
tar xf swiper-11.1.15.tgz
rm swiper-11.1.15.tgz
curl https://cdn.jsdelivr.net/npm/PACKAGE@VERSION[/MODULE1[/MODULE2[/...]]]/+esm > PACKAGE@VERSION[-MODULE1[-MODULE2[-...]]].js
```
3. Rename the `package` folder to `<package>@<version>` format:
Example:
```sh
mv package [email protected]
curl https://cdn.jsdelivr.net/npm/[email protected]/+esm > [email protected]
curl https://cdn.jsdelivr.net/npm/[email protected]/modules/pagination/+esm > [email protected]
```
4. Commit the vendored package:

```sh
git add [email protected]
git commit
```
3. Open the module with an editor and remove the last line that starts with
`//# sourceMappingURL`.
7 changes: 7 additions & 0 deletions static/vendor/[email protected]

Large diffs are not rendered by default.

7 changes: 0 additions & 7 deletions static/vendor/[email protected]/builds/cdn.js

This file was deleted.

5 changes: 0 additions & 5 deletions static/vendor/[email protected]/builds/module.js

This file was deleted.

Loading

0 comments on commit 5eac016

Please sign in to comment.