-
Notifications
You must be signed in to change notification settings - Fork 195
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(storybook): vite migration (#2803)
Migrating the build for our Storybook instance from Webpack to Vite for a stronger front-of-the-front-end build system. **Why?** - More efficient code splitting due to using native ESM. - Rapid cold start speed and efficient HMR for swift code modifications. - Local and browser caching are built-in features. - PostCSS is pre-configured and a built-in utility requiring very little (or often no) configuration. Yes, Vite comes with a limited plugins ecosystem as compared to webpack, but what they have are focused on front-of-the-front-end tooling such as postcss and esbuild which meet our needs without adding complexity. **Changes to support the migration** - Wrap typekit.js loader in DOMContentLoaded (Vite is loading it more quickly causing initialization issues) - Load styles for the context decorator by appending them to style tags as-needed - Updated development guide for Storybook to describe changes - Create a new loaders folder to pull out the font, icon, and token loaders - Update main.js config in storybook to use Vite config instead - Use ESM syntax for Storybook workspace - Pass the context data through templates to allow us to query it in nested components
- Loading branch information
1 parent
b322fe7
commit 2c5e5eb
Showing
111 changed files
with
3,834 additions
and
4,477 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@spectrum-css/preview": minor | ||
--- | ||
|
||
Feature to migrate Storybook to use Vite's builder instead of Webpack. This change reduces the configuration complexity with more built-in features that align with our needs. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@spectrum-css/tokens": minor | ||
--- | ||
|
||
This feature adds the custom variables for each context (spectrum and express) to the root-named asset (dist/css/express/global-vars.css) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,52 @@ | ||
/* global Typekit */ | ||
|
||
// This wrapper prevents loading the font more than once | ||
if (!window.Typekit) { | ||
const kitId = | ||
document.querySelector("[lang]:not([lang=\"en-US\"])") === null | ||
? "mge7bvf" | ||
: "rok6rmo"; | ||
|
||
window.addEventListener("DOMContentLoaded", () => { | ||
const html = document.documentElement; | ||
html.classList.add("wf-loading"); | ||
const root = document.head ?? document.body ?? html; | ||
const isNotEnglish = root.querySelector("[lang]:not([lang=\"en-US\"])"); | ||
|
||
const toggleClass = (state, force = true) => { | ||
if (html) html.classList.toggle(`wf-${state}`, force); | ||
else if (root) root.classList.toggle(`wf-${state}`, force); | ||
}; | ||
|
||
const t = setTimeout(function () { | ||
html.classList.remove("wf-loading"); | ||
html.classList.add("wf-inactive"); | ||
const timeout = setTimeout(function () { | ||
toggleClass("loading", false); | ||
toggleClass("inactive"); | ||
}, 3000); | ||
|
||
const tk = document.createElement("script"); | ||
let d = false; | ||
|
||
// Always load over https | ||
tk.src = "https://use.typekit.net/" + kitId + ".js"; | ||
tk.type = "text/javascript"; | ||
tk.async = "true"; | ||
tk.onload = tk.onreadystatechange = () => { | ||
const a = this.readyState; | ||
if (d || (a && a !== "complete" && a !== "loaded")) return; | ||
|
||
d = true; | ||
clearTimeout(t); | ||
|
||
try { | ||
window.Typekit = Typekit.load({ | ||
kitId, | ||
scriptTimeout: 3000, | ||
}); | ||
} | ||
catch (b) {/* empty */} | ||
const config = { | ||
kitId: isNotEnglish ? "mge7bvf" : "rok6rmo", | ||
scriptTimeout: 3000, | ||
active: () => { | ||
toggleClass("loading"); | ||
}, | ||
}; | ||
|
||
document.body.appendChild(tk); | ||
} | ||
// This wrapper prevents loading the font more than once | ||
if (window && !window.Typekit) { | ||
let d = false; | ||
let tk = document.querySelector("#typekit"); | ||
|
||
if (!tk) { | ||
tk = document.createElement("script"); | ||
tk.id = "typekit"; | ||
tk.src = `https://use.typekit.net/${config.kitId}.js`; | ||
tk.type = "text/javascript"; | ||
tk.async = "true"; | ||
tk.onload = tk.onreadystatechange = function () { | ||
const readyState = this.readyState; | ||
if (d || (readyState && readyState !== "complete" && readyState !== "loaded")) return; | ||
|
||
d = true; | ||
clearTimeout(timeout); | ||
|
||
try { | ||
window.Typekit = Typekit.load(config); | ||
} | ||
catch (b) {/* empty */} | ||
}; | ||
root.appendChild(tk); | ||
} | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.