Skip to content

Commit

Permalink
Download fonts locally on build
Browse files Browse the repository at this point in the history
Use rollup-plugin-bundle-fonts [1] to download fonts locally on build and
not rely on a CDN on production.

[1] https://github.com/mgreminger/rollup-plugin-bundle-fonts

Fixes #58 while carbon-design-system/carbon-components-svelte#1629 is
not finished.
  • Loading branch information
n-peugnet committed Dec 9, 2023
1 parent b98938b commit 635ad42
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# App files
/node_modules/
/public/app/
/public/fonts/
config.json
.env

Expand Down
114 changes: 114 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"eslint": "^8.0.0",
"eslint-plugin-svelte3": "^4.0.0",
"rollup": "^3.29.4",
"rollup-plugin-bundle-fonts": "^1.0.0",
"rollup-plugin-css-only": "^4.5.2",
"rollup-plugin-livereload": "^2.0.0",
"rollup-plugin-svelte": "^7.0.0",
Expand Down
7 changes: 7 additions & 0 deletions rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import typescript from '@rollup/plugin-typescript';
import json from '@rollup/plugin-json';
import css from 'rollup-plugin-css-only';
import { copy } from '@web/rollup-plugin-copy';
import bundleFonts from 'rollup-plugin-bundle-fonts';
import sveltePreprocess from 'svelte-preprocess';
import { optimizeCarbonImports as carbon } from "carbon-preprocess-svelte";
import { execSync } from 'child_process';
Expand Down Expand Up @@ -64,6 +65,12 @@ export default {
// JSON plugin to convert translation files to modules.
json({ namedExports: false }),

// Download and package fonts localy
bundleFonts({
fontTargetDir: 'public/fonts',
cssBundleDir: 'public/app',
}),

// we'll extract any component CSS out into
// a separate file - better for performance
css({ output: 'bundle.css' }),
Expand Down

0 comments on commit 635ad42

Please sign in to comment.