Skip to content

Commit

Permalink
Use esbuild for the compiler -wip
Browse files Browse the repository at this point in the history
  • Loading branch information
mjackson committed Mar 26, 2021
1 parent d59386b commit d87b60c
Show file tree
Hide file tree
Showing 24 changed files with 590 additions and 117 deletions.
4 changes: 2 additions & 2 deletions fixtures/tutorial/app/entry.client.tsx
@@ -1,8 +1,8 @@
import ReactDOM from "react-dom";
import Remix from "@remix-run/react/browser";
import { RemixBrowser } from "@remix-run/react";

ReactDOM.hydrate(
// @ts-ignore
<Remix />,
<RemixBrowser />,
document
);
4 changes: 2 additions & 2 deletions fixtures/tutorial/app/entry.server.tsx
@@ -1,6 +1,6 @@
import ReactDOMServer from "react-dom/server";
import type { EntryContext } from "@remix-run/node";
import Remix from "@remix-run/react/server";
import { RemixServer } from "@remix-run/react";

export default function handleRequest(
request: Request,
Expand All @@ -9,7 +9,7 @@ export default function handleRequest(
remixContext: EntryContext
) {
let markup = ReactDOMServer.renderToString(
<Remix context={remixContext} url={request.url} />
<RemixServer context={remixContext} url={request.url} />
);

return new Response("<!DOCTYPE html>" + markup, {
Expand Down
8 changes: 4 additions & 4 deletions fixtures/tutorial/app/root.tsx
Expand Up @@ -2,15 +2,15 @@ import { Link, Outlet } from "react-router-dom";
import type { LoaderFunction, LinksFunction } from "@remix-run/node";
import { Meta, Scripts, Links, useRouteData } from "@remix-run/react";

import styles from "url:./styles/global.css";
// import styles from "url:./styles/global.css";

export let loader: LoaderFunction = async () => {
return { date: new Date() };
};

export let links: LinksFunction = () => {
return [{ rel: "stylesheet", href: styles }];
};
// export let links: LinksFunction = () => {
// return [{ rel: "stylesheet", href: styles }];
// };

export default function App() {
let data = useRouteData();
Expand Down
8 changes: 4 additions & 4 deletions fixtures/tutorial/app/routes/gists.new.tsx
@@ -1,11 +1,11 @@
import type { LinksFunction } from "@remix-run/node";
import { Form, usePendingFormSubmit } from "@remix-run/react";

import styles from "url:../styles/gists.new.css";
// import styles from "url:../styles/gists.new.css";

export let links: LinksFunction = () => {
return [{ rel: "stylesheet", href: styles }];
};
// export let links: LinksFunction = () => {
// return [{ rel: "stylesheet", href: styles }];
// };

export default function NewGist() {
let pendingForm = usePendingFormSubmit();
Expand Down
8 changes: 4 additions & 4 deletions fixtures/tutorial/app/routes/index.tsx
@@ -1,15 +1,15 @@
import type { LoaderFunction, LinksFunction } from "@remix-run/node";
import { useRouteData } from "@remix-run/react";

import styles from "url:../styles/index.css";
// import styles from "url:../styles/index.css";

export let loader: LoaderFunction = async () => {
return { message: "this is awesome 😎" };
};

export let links: LinksFunction = () => {
return [{ rel: "stylesheet", href: styles }];
};
// export let links: LinksFunction = () => {
// return [{ rel: "stylesheet", href: styles }];
// };

export function meta() {
return {
Expand Down
9 changes: 5 additions & 4 deletions fixtures/tutorial/package.json
Expand Up @@ -3,11 +3,12 @@
"name": "tutorial",
"version": "1.0.0",
"scripts": {
"prebuild": "cp -r ../../build/node_modules/* node_modules",
"build": "node node_modules/@remix-run/cli build",
"predev": "cp -r ../../build/node_modules/* node_modules",
"install_remix": "mkdir -p node_modules && cp -r ../../build/node_modules/* node_modules",
"prebuild": "yarn run install_remix",
"build": "node node_modules/@remix-run/dev/cli build2",
"predev": "yarn run install_remix",
"dev": "pm2-dev pm2.config.js",
"prestart": "cp -r ../../build/node_modules/* node_modules",
"prestart": "yarn run install_remix",
"start": "node server.js"
},
"dependencies": {
Expand Down
1 change: 1 addition & 0 deletions fixtures/tutorial/server.js
Expand Up @@ -13,6 +13,7 @@ app.use(express.static("public"));
app.all(
"*",
createRequestHandler({
build: require("./build/app"),
getLoadContext() {
// Whatever you return here will be passed as `context` to your loaders.
}
Expand Down
9 changes: 7 additions & 2 deletions packages/dev/build.ts
Expand Up @@ -9,9 +9,14 @@ export function isBuildMode(mode: any): mode is BuildMode {

export enum BuildTarget {
Browser = "browser",
Server = "server"
Server = "server", // TODO: remove
Node14 = "node14"
}

export function isBuildTarget(target: any): target is BuildTarget {
return target === BuildTarget.Browser || target === BuildTarget.Server;
return (
target === BuildTarget.Browser ||
target === BuildTarget.Server ||
target === BuildTarget.Node14
);
}
3 changes: 3 additions & 0 deletions packages/dev/cli.ts
Expand Up @@ -39,6 +39,9 @@ switch (cli.input[0]) {
case "build":
commands.build(cli.input[1], process.env.NODE_ENV);
break;
case "build2":
commands.build2(cli.input[1], process.env.NODE_ENV);
break;
case "run":
commands.run(cli.input[1]);
break;
Expand Down
12 changes: 12 additions & 0 deletions packages/dev/cli/commands.ts
@@ -1,5 +1,6 @@
import { BuildMode, isBuildMode, BuildTarget } from "../build";
import * as compiler from "../compiler";
import * as compiler2 from "../compiler2";
import { readConfig } from "../config";
import { startDevServer } from "../server";

Expand Down Expand Up @@ -33,6 +34,17 @@ export async function build(remixRoot: string, mode?: string) {
console.log("done!");
}

export async function build2(remixRoot: string, mode?: string) {
let buildMode = isBuildMode(mode) ? mode : BuildMode.Production;

console.log(`Building Remix app for ${buildMode}...`);

let config = await readConfig(remixRoot);
await compiler2.build(config);

console.log("done!");
}

/**
* Runs the dev server for a Remix app.
*/
Expand Down
24 changes: 12 additions & 12 deletions packages/dev/compiler.ts
Expand Up @@ -281,18 +281,18 @@ function getBuildPlugins({ mode, target }: Required<BuildOptions>): Plugin[] {
})
];

if (target === BuildTarget.Browser) {
plugins.push(
alias({
entries: [
{
find: "@remix-run/react",
replacement: "@remix-run/react/esm"
}
]
})
);
}
// if (target === BuildTarget.Browser) {
// plugins.push(
// alias({
// entries: [
// {
// find: "@remix-run/react",
// replacement: "@remix-run/react/esm"
// }
// ]
// })
// );
// }

plugins.push(
clientServer({ target }),
Expand Down

0 comments on commit d87b60c

Please sign in to comment.