From 635ad42ac7d8bae02e4c1e2d5e18fb330b8720be Mon Sep 17 00:00:00 2001 From: Nicolas Peugnet Date: Sat, 9 Dec 2023 23:42:30 +0100 Subject: [PATCH] Download fonts locally on build 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. --- .gitignore | 1 + package-lock.json | 114 ++++++++++++++++++++++++++++++++++++++++++++++ package.json | 1 + rollup.config.mjs | 7 +++ 4 files changed, 123 insertions(+) diff --git a/.gitignore b/.gitignore index 54f6f57..51a7a1e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ # App files /node_modules/ /public/app/ +/public/fonts/ config.json .env diff --git a/package-lock.json b/package-lock.json index 0fbabfa..8a69c3e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -29,6 +29,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", @@ -1483,6 +1484,15 @@ "type": "^1.0.1" } }, + "node_modules/data-uri-to-buffer": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/data-uri-to-buffer/-/data-uri-to-buffer-4.0.1.tgz", + "integrity": "sha512-0R9ikRb668HB7QDxT1vkpuUBtqc53YyAwMwGeUFKRojY/NWKvdZ+9UYtRfGmhqNbRkTSVpMbmyhXipFFv2cb/A==", + "dev": true, + "engines": { + "node": ">= 12" + } + }, "node_modules/debug": { "version": "4.3.4", "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", @@ -1958,6 +1968,29 @@ "reusify": "^1.0.4" } }, + "node_modules/fetch-blob": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/fetch-blob/-/fetch-blob-3.2.0.tgz", + "integrity": "sha512-7yAQpD2UMJzLi1Dqv7qFYnPbaPx7ZfFK6PiIxQ4PfkGPyNyl2Ugx+a/umUonmKqjhM4DnfbMvdX6otXq83soQQ==", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/jimmywarting" + }, + { + "type": "paypal", + "url": "https://paypal.me/jimmywarting" + } + ], + "dependencies": { + "node-domexception": "^1.0.0", + "web-streams-polyfill": "^3.0.3" + }, + "engines": { + "node": "^12.20 || >= 14.13" + } + }, "node_modules/file-entry-cache": { "version": "6.0.1", "resolved": "https://registry.npmjs.org/file-entry-cache/-/file-entry-cache-6.0.1.tgz", @@ -2055,6 +2088,18 @@ "node": ">= 6" } }, + "node_modules/formdata-polyfill": { + "version": "4.0.10", + "resolved": "https://registry.npmjs.org/formdata-polyfill/-/formdata-polyfill-4.0.10.tgz", + "integrity": "sha512-buewHzMvYL29jdeQTVILecSaZKnt/RJWjoZCF5OW60Z67/GmSLBkOFM7qh1PI3zFNtJbaZL5eQu1vLfazOwj4g==", + "dev": true, + "dependencies": { + "fetch-blob": "^3.1.2" + }, + "engines": { + "node": ">=12.20.0" + } + }, "node_modules/fs.realpath": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", @@ -2743,6 +2788,43 @@ "integrity": "sha512-CXdUiJembsNjuToQvxayPZF9Vqht7hewsvy2sOWafLvi2awflj9mOC6bHIg50orX8IJvWKY9wYQ/zB2kogPslQ==", "dev": true }, + "node_modules/node-domexception": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/node-domexception/-/node-domexception-1.0.0.tgz", + "integrity": "sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ==", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/jimmywarting" + }, + { + "type": "github", + "url": "https://paypal.me/jimmywarting" + } + ], + "engines": { + "node": ">=10.5.0" + } + }, + "node_modules/node-fetch": { + "version": "3.3.2", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-3.3.2.tgz", + "integrity": "sha512-dRB78srN/l6gqWulah9SrxeYnxeddIG30+GOqK/9OlLVyLg3HPnr6SqOWTWOXKRwC2eGYCkZ59NNuSgvSrpgOA==", + "dev": true, + "dependencies": { + "data-uri-to-buffer": "^4.0.0", + "fetch-blob": "^3.1.4", + "formdata-polyfill": "^4.0.10" + }, + "engines": { + "node": "^12.20.0 || ^14.13.1 || >=16.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/node-fetch" + } + }, "node_modules/normalize-path": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz", @@ -3132,6 +3214,29 @@ "fsevents": "~2.3.2" } }, + "node_modules/rollup-plugin-bundle-fonts": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/rollup-plugin-bundle-fonts/-/rollup-plugin-bundle-fonts-1.0.0.tgz", + "integrity": "sha512-yqDZc6Qbk+Zg7V7GrxwZVxyTTJBHGvVUPpzjVJnPK1OGsTgpAN1myhxqG69SCPkWGXmqq7M8540GxaAOgCwauA==", + "dev": true, + "dependencies": { + "@rollup/pluginutils": "^5.0.2", + "magic-string": "^0.27.0", + "node-fetch": "^3.3.0" + } + }, + "node_modules/rollup-plugin-bundle-fonts/node_modules/magic-string": { + "version": "0.27.0", + "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.27.0.tgz", + "integrity": "sha512-8UnnX2PeRAPZuN12svgR9j7M1uWMovg/CEnIwIG0LFkXSJJe4PdfUGiTGl8V9bsBHFUtfVINcSyYxd7q+kx9fA==", + "dev": true, + "dependencies": { + "@jridgewell/sourcemap-codec": "^1.4.13" + }, + "engines": { + "node": ">=12" + } + }, "node_modules/rollup-plugin-css-only": { "version": "4.5.2", "resolved": "https://registry.npmjs.org/rollup-plugin-css-only/-/rollup-plugin-css-only-4.5.2.tgz", @@ -3934,6 +4039,15 @@ "integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==", "dev": true }, + "node_modules/web-streams-polyfill": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/web-streams-polyfill/-/web-streams-polyfill-3.2.1.tgz", + "integrity": "sha512-e0MO3wdXWKrLbL0DgGnUV7WHVuw9OUvL4hjgnPkIeEvESk74gAITi5G606JtZPp39cd8HA9VQzCIvA49LpPN5Q==", + "dev": true, + "engines": { + "node": ">= 8" + } + }, "node_modules/webdav": { "version": "4.11.3", "resolved": "https://registry.npmjs.org/webdav/-/webdav-4.11.3.tgz", diff --git a/package.json b/package.json index 994d4b3..b6f5bb3 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/rollup.config.mjs b/rollup.config.mjs index 8953c7e..0bdd0a4 100644 --- a/rollup.config.mjs +++ b/rollup.config.mjs @@ -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'; @@ -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' }),