Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DRAFT] Fix: one-page ESM loading #1346

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
Slide,
Deck,
Text,
FitText,
Grid,
Box,
Image,
Expand All @@ -23,6 +22,7 @@ import {
DefaultTemplate,
SlideLayout
} from 'spectacle';
const FitText = Text; // TODO: NEED PUBLISH

const formidableLogo =
'https://avatars2.githubusercontent.com/u/5078602?s=280&v=4';
Expand Down
64 changes: 33 additions & 31 deletions examples/one-page/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,39 +9,40 @@
<body>
<div id="root"></div>

<!-- TODO: Need to update build script to final solution. Maybe add dev for good?-->
<script type="importmap">
{
"imports": {
"htm": "https://esm.sh/v121/htm@^3?deps=react@18.2.0",
"spectacle": "https://esm.sh/spectacle@10?bundle",
"broadcast-channel": "https://esm.sh/v121/broadcast-channel@^4.17.0?deps=react@18.2.0",
"history": "https://esm.sh/v121/history@^5.3.0?deps=react@18.2.0",
"kbar": "https://esm.sh/v121/[email protected]?deps=react@18.2.0",
"lodash.clonedeep": "https://esm.sh/v121/lodash.clonedeep@^4.5.0?deps=react@18.2.0",
"mdast-builder": "https://esm.sh/v121/mdast-builder@^1.1.1?deps=react@18.2.0",
"mdast-zone": "https://esm.sh/v121/mdast-zone@^4.0.0?deps=react@18.2.0",
"merge-anything": "https://esm.sh/v121/merge-anything@^3.0.3?deps=react@18.2.0",
"mousetrap": "https://esm.sh/v121/mousetrap@^1.6.5?deps=react@18.2.0",
"query-string": "https://esm.sh/v121/query-string@^7.1.3?deps=react@18.2.0",
"react": "https://esm.sh/v121/[email protected]?[email protected]",
"react/jsx-runtime": "https://esm.sh/v121/[email protected]/jsx-runtime?[email protected]",
"react-dom": "https://esm.sh/v121/[email protected]?[email protected]",
"react-fast-compare": "https://esm.sh/v121/react-fast-compare@^3.2.0?deps=react@18.2.0",
"react-is": "https://esm.sh/v121/react-is@^18.1.0?deps=react@18.2.0",
"react-spring": "https://esm.sh/v121/react-spring@^9.5.5?deps=react@18.2.0",
"react-swipeable": "https://esm.sh/v121/react-swipeable@^7.0.0?deps=react@18.2.0",
"react-syntax-highlighter": "https://esm.sh/v121/react-syntax-highlighter@^15.5.0?deps=react@18.2.0",
"react-syntax-highlighter/dist/cjs/styles/prism/vs-dark.js": "https://esm.sh/v121/react-syntax-highlighter@^15.5.0/dist/esm/styles/prism/vs-dark.js?deps=react@18.2.0",
"react-syntax-highlighter/dist/cjs/styles/prism/index.js": "https://esm.sh/v121/react-syntax-highlighter@^15.5.0/dist/esm/styles/prism/index.js?deps=react@18.2.0",
"rehype-raw": "https://esm.sh/v121/rehype-raw@^5.1.0?deps=react@18.2.0",
"rehype-react": "https://esm.sh/v121/rehype-react@^6.0.0?deps=react@18.2.0",
"remark-parse": "https://esm.sh/v121/remark-parse@^8.0.3?deps=react@18.2.0",
"remark-rehype": "https://esm.sh/v121/remark-rehype@^7.0.0?deps=react@18.2.0",
"styled-components": "https://esm.sh/v121/styled-components@^5.3.6?deps=react@18.2.0",
"styled-system": "https://esm.sh/v121/[email protected]?deps=react@18.2.0",
"unified": "https://esm.sh/v121/unified@^9.0.0?deps=react@18.2.0",
"unist-util-visit": "https://esm.sh/v121/unist-util-visit@^2.0.3?deps=react@18.2.0",
"use-resize-observer": "https://esm.sh/v121/use-resize-observer@^9.0.2?deps=react@18.2.0"
"htm": "https://esm.sh/htm@^3?external=react,react-dom&dev",
"spectacle": "https://esm.sh/spectacle@10?external=react,react-dom&bundle&dev",
"broadcast-channel": "https://esm.sh/broadcast-channel@^4.17.0?external=react,react-dom&dev",
"history": "https://esm.sh/history@^5.3.0?external=react,react-dom&dev",
"kbar": "https://esm.sh/[email protected]?external=react,react-dom&dev",
"lodash.clonedeep": "https://esm.sh/lodash.clonedeep@^4.5.0?external=react,react-dom&dev",
"mdast-builder": "https://esm.sh/mdast-builder@^1.1.1?external=react,react-dom&dev",
"mdast-zone": "https://esm.sh/mdast-zone@^4.0.0?external=react,react-dom&dev",
"merge-anything": "https://esm.sh/merge-anything@^3.0.3?external=react,react-dom&dev",
"mousetrap": "https://esm.sh/mousetrap@^1.6.5?external=react,react-dom&dev",
"query-string": "https://esm.sh/query-string@^7.1.3?external=react,react-dom&dev",
"react": "https://esm.sh/[email protected]?&dev",
"react/jsx-runtime": "https://esm.sh/[email protected]/jsx-runtime?&dev",
"react-dom": "https://esm.sh/[email protected]?&dev",
"react-fast-compare": "https://esm.sh/react-fast-compare@^3.2.0?external=react,react-dom&dev",
"react-is": "https://esm.sh/react-is@^18.1.0?external=react,react-dom&dev",
"react-spring": "https://esm.sh/react-spring@^9.5.5?external=react,react-dom&dev",
"react-swipeable": "https://esm.sh/react-swipeable@^7.0.0?external=react,react-dom&dev",
"react-syntax-highlighter": "https://esm.sh/react-syntax-highlighter@^15.5.0?external=react,react-dom&dev",
"react-syntax-highlighter/dist/cjs/styles/prism/vs-dark.js": "https://esm.sh/react-syntax-highlighter@^15.5.0/dist/esm/styles/prism/vs-dark.js?external=react,react-dom&dev",
"react-syntax-highlighter/dist/cjs/styles/prism/index.js": "https://esm.sh/react-syntax-highlighter@^15.5.0/dist/esm/styles/prism/index.js?external=react,react-dom&dev",
"rehype-raw": "https://esm.sh/rehype-raw@^5.1.0?external=react,react-dom&dev",
"rehype-react": "https://esm.sh/rehype-react@^6.0.0?external=react,react-dom&dev",
"remark-parse": "https://esm.sh/remark-parse@^8.0.3?external=react,react-dom&dev",
"remark-rehype": "https://esm.sh/remark-rehype@^7.0.0?external=react,react-dom&dev",
"styled-components": "https://esm.sh/styled-components@^5.3.6?external=react,react-dom&dev",
"styled-system": "https://esm.sh/[email protected]?external=react,react-dom&dev",
"unified": "https://esm.sh/unified@^9.0.0?external=react,react-dom&dev",
"unist-util-visit": "https://esm.sh/unist-util-visit@^2.0.3?external=react,react-dom&dev",
"use-resize-observer": "https://esm.sh/use-resize-observer@^9.0.2?external=react,react-dom&dev"
}
}
</script>
Expand All @@ -60,7 +61,6 @@
Slide,
Deck,
Text,
FitText,
Grid,
Box,
Image,
Expand All @@ -74,6 +74,8 @@

import htm from 'htm';
const html = htm.bind(React.createElement);
const FitText = Text; // TODO: NEED PUBLISH

const formidableLogo = 'https://avatars2.githubusercontent.com/u/5078602?s=280&v=4';


Expand Down
14 changes: 8 additions & 6 deletions examples/one-page/scripts/one-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const SRC_FILE = path.join(EXAMPLES, 'js/index.js');
const DEST_FILE = path.join(EXAMPLES, 'one-page/index.html');

// Dependencies.
const ESM_SH_VERSION = 'v121'; // v121, stable, etc.
const ESM_SH_VERSION = ''; // 'v121/, stable, etc.
const {
dependencies,
peerDependencies
Expand All @@ -25,10 +25,10 @@ const reactPkgPath = require.resolve('react/package.json', {
paths: [SPECTACLE_PATH]
});
const { version: reactVersion } = require(reactPkgPath);
const DEPS = `deps=react@${reactVersion}`;
const EXTERNAL = `external=react,react-dom`;

// Toggle dev resources. (Use if debugging load / dependency errors).
const IS_DEV = false;
const IS_DEV = true;
const DEV = IS_DEV ? '&dev' : '';

// Use local built spectacle? Toggle to `true` for dev-only.
Expand All @@ -39,13 +39,15 @@ const USE_LOCAL = false;
// ================================================================================================
// Import Map
// ================================================================================================
const importUrl = (k, v, extra = '') => {
const importUrl = (k, v, extra = '', params = '') => {
let external = EXTERNAL;
// Pin react and react-dom.
if (k === 'react' || k === 'react-dom') {
v = reactVersion;
external = '';
}

return `https://esm.sh/${ESM_SH_VERSION}/${k}@${v}${extra}?${DEPS}${DEV}`;
return `https://esm.sh/${ESM_SH_VERSION}${k}@${v}${extra}?${external}${params}${DEV}`;
};

const getImportMap = () => {
Expand All @@ -54,7 +56,7 @@ const getImportMap = () => {
htm: importUrl('htm', '^3'),
spectacle: USE_LOCAL
? '../../packages/spectacle/lib/index.mjs'
: 'https://esm.sh/spectacle@10?bundle'
: importUrl('spectacle', '10', '', '&bundle')
};

Object.entries(Object.assign({}, dependencies, peerDependencies))
Expand Down
Loading