diff --git a/examples/js/index.js b/examples/js/index.js index b4e063b4..cdf0b1f4 100644 --- a/examples/js/index.js +++ b/examples/js/index.js @@ -1,5 +1,5 @@ import React from 'react'; -import ReactDOM from 'react-dom'; +import { createRoot } from 'react-dom/client'; import { FlexBox, Heading, @@ -38,10 +38,10 @@ const theme = { const SlideFragments = () => ( <> - + This is a slide fragment. - + This is also a slide fragment. This item shows up! @@ -267,5 +267,5 @@ const Presentation = () => ( ); -const root = ReactDOM.createRoot(document.getElementById('root')); +const root = createRoot(document.getElementById('root')); root.render(); diff --git a/examples/one-page/index.html b/examples/one-page/index.html index b7adc7c6..37d6341b 100644 --- a/examples/one-page/index.html +++ b/examples/one-page/index.html @@ -12,42 +12,43 @@ diff --git a/examples/one-page/scripts/one-page.js b/examples/one-page/scripts/one-page.js index 3b1f1e5e..051c301d 100644 --- a/examples/one-page/scripts/one-page.js +++ b/examples/one-page/scripts/one-page.js @@ -2,6 +2,16 @@ /** * Generate the JS `index.html` from `examples/js/index.js` + * + * To rebuild: + * ```sh + * pnpm run build:one-page + * ``` + * + * To do dev builds and testing: + * ```sh + * USE_LOCAL=true IS_DEV=true pnpm run build:one-page && pnpm run start:one-page + * ``` */ const fs = require('fs').promises; const path = require('path'); @@ -16,7 +26,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 @@ -25,27 +35,30 @@ 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 = process.env.IS_DEV === 'true'; const DEV = IS_DEV ? '&dev' : ''; // Use local built spectacle? Toggle to `true` for dev-only. // Note: Due to CORS, you'll need to run `pnpm run --filter ./examples/one-page start` and // open http://localhost:5000/examples/one-page to work. -const USE_LOCAL = false; +const USE_LOCAL = process.env.USE_LOCAL === 'true'; // ================================================================================================ // 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 = () => { @@ -54,7 +67,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)) @@ -67,6 +80,9 @@ const getImportMap = () => { if (k === 'react') { importMap[`${k}/jsx-runtime`] = importUrl(k, v, '/jsx-runtime'); } + if (k === 'react-dom') { + importMap[`${k}/client`] = importUrl(k, v, '/client'); + } if (k === 'react-syntax-highlighter') { importMap[`${k}/dist/cjs/styles/prism/vs-dark.js`] = importUrl( k, diff --git a/package.json b/package.json index c31807a6..f671a54e 100644 --- a/package.json +++ b/package.json @@ -56,6 +56,7 @@ "start:md": "concurrently --raw pnpm:build:spectacle:watch \"pnpm run --filter ./examples/md start\"", "start:mdx": "concurrently --raw pnpm:build:spectacle:watch \"pnpm run --filter ./examples/mdx start\"", "start:ts": "concurrently --raw pnpm:build:spectacle:watch \"pnpm run --filter ./examples/typescript start\"", + "start:one-page": "concurrently --raw pnpm:build:spectacle:watch \"pnpm run --filter ./examples/one-page start\"", "start:examples": "concurrently --raw pnpm:build:spectacle:watch \"pnpm run --parallel --filter \\\"./examples/*\\\" start\"", "start:create-spectacle": "pnpm run --filter ./packages/create-spectacle build --watch", "start:docs": "pnpm run --filter spectacle-docs start",