diff --git a/guide/.gitignore b/guide/.gitignore index 0eab507e..37c7a348 100644 --- a/guide/.gitignore +++ b/guide/.gitignore @@ -1,6 +1,9 @@ node_modules /.cache +/functions/\[\[path\]\].js +/functions/\[\[path\]\].js.map +/functions/metafile.* /public/build /public/docs .env diff --git a/guide/app/components.tsx b/guide/app/components.tsx index 6cc64b5c..9f63e707 100644 --- a/guide/app/components.tsx +++ b/guide/app/components.tsx @@ -2,10 +2,10 @@ import type { RenderableTreeNodes } from '@markdoc/markdoc'; import { renderers } from '@markdoc/markdoc'; import { Link as RouterLink, useMatches } from '@remix-run/react'; import * as React from 'react'; -import ReactSyntaxHighlighter from 'react-syntax-highlighter/dist/cjs/prism-light'; -import tsx from 'react-syntax-highlighter/dist/cjs/languages/prism/tsx'; -import css from 'react-syntax-highlighter/dist/cjs/languages/prism/css'; -import darcula from 'react-syntax-highlighter/dist/cjs/styles/prism/darcula'; +import ReactSyntaxHighlighter from 'react-syntax-highlighter/dist/esm/prism-light'; +import tsx from 'react-syntax-highlighter/dist/esm/languages/prism/tsx'; +import css from 'react-syntax-highlighter/dist/esm/languages/prism/css'; +import darcula from 'react-syntax-highlighter/dist/esm/styles/prism/darcula'; import { getChildren, isTag } from './markdoc'; const style = { diff --git a/guide/functions/[[path]].ts b/guide/functions/[[path]].ts deleted file mode 100644 index cf1972de..00000000 --- a/guide/functions/[[path]].ts +++ /dev/null @@ -1,25 +0,0 @@ -import { createRequestHandler } from '@remix-run/cloudflare'; -import * as build from '../build'; - -let handleRequest: ReturnType; - -export const onRequest: PagesFunction = (context) => { - if (!handleRequest) { - handleRequest = createRequestHandler( - // @ts-expect-error - build, - context.env.ENVIRONMENT, - ); - } - - // This is where you can pass a custom load context to your app - return handleRequest(context.request, { - env: { - ...context.env, - CF_PAGES_BRANCH: 'main', - }, - waitUntil(promise: Promise) { - context.waitUntil(promise); - }, - }); -}; diff --git a/guide/package.json b/guide/package.json index b1335fb4..36742fdc 100644 --- a/guide/package.json +++ b/guide/package.json @@ -1,15 +1,13 @@ { "private": true, "sideEffects": false, + "type": "module", "scripts": { - "build": "run-s build:*", - "build:remix": "remix build", - "ci": "sed -i -e \"s/CF_PAGES_BRANCH:\\s'main'/CF_PAGES_BRANCH: '$CF_PAGES_BRANCH'/g\" ./functions/[[path]].ts", - "dev:remix": "cross-env NODE_ENV=development remix dev", - "dev:wrangler": "cross-env NODE_ENV=development wrangler pages dev public --port 3000 --kv CACHE -b ENVIRONMENT=development", - "dev": "run-p dev:*", + "build": "remix build", + "ci": "sed -i -e \"s/CF_PAGES_BRANCH:\\s'main'/CF_PAGES_BRANCH: '$CF_PAGES_BRANCH'/g\" ./server.ts", + "dev": "remix dev --manual -c \"npm run start\"", "predev": "remix build", - "start": "cross-env NODE_ENV=production npm run dev:wrangler" + "start": "wrangler pages dev public --port 3000 --kv CACHE -b ENVIRONMENT=development" }, "dependencies": { "@markdoc/markdoc": "^0.1.7", diff --git a/guide/remix.config.js b/guide/remix.config.js index 8dd4408d..cc064f2c 100644 --- a/guide/remix.config.js +++ b/guide/remix.config.js @@ -1,13 +1,25 @@ /** @type {import('@remix-run/dev').AppConfig} */ -module.exports = { +export default { + devServerBroadcastDelay: 1000, + ignoredRouteFiles: ['**/.*'], + server: './server.ts', + serverBuildPath: 'functions/[[path]].js', + serverConditions: ['workerd', 'worker', 'browser'], + serverDependenciesToBundle: 'all', + serverMainFields: ['browser', 'module', 'main'], + serverMinify: true, serverModuleFormat: 'esm', - serverDependenciesToBundle: ['@remix-run/react'], + serverPlatform: 'neutral', + // appDirectory: "app", + // assetsBuildDirectory: "public/build", + // publicPath: "/build/", future: { + v2_dev: true, + v2_errorBoundary: false, + v2_headers: false, + v2_meta: false, + v2_normalizeFormMethod: true, v2_routeConvention: true, - unstable_dev: { - appServerPort: 3000, - rebuildPollIntervalMs: 500, - }, - unstable_tailwind: true, }, + tailwind: true, }; diff --git a/guide/server.ts b/guide/server.ts new file mode 100644 index 00000000..549a3bd2 --- /dev/null +++ b/guide/server.ts @@ -0,0 +1,21 @@ +import { logDevReady } from '@remix-run/cloudflare'; +import { createPagesFunctionHandler } from '@remix-run/cloudflare-pages'; +import * as build from '@remix-run/dev/server-build'; + +if (process.env.NODE_ENV === 'development') { + logDevReady(build); +} + +export const onRequest = createPagesFunctionHandler({ + build, + getLoadContext: (context) => ({ + env: { + ...context.env, + CF_PAGES_BRANCH: 'main', + }, + waitUntil(promise: Promise) { + context.waitUntil(promise); + }, + }), + mode: process.env.NODE_ENV, +}); diff --git a/guide/tailwind.config.js b/guide/tailwind.config.cjs similarity index 100% rename from guide/tailwind.config.js rename to guide/tailwind.config.cjs