Skip to content

Fix hot reload for dependencies of cursorless-org #2286

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

Merged
merged 2 commits into from
Apr 7, 2024
Merged
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
32 changes: 32 additions & 0 deletions packages/cursorless-org/next.config.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,29 @@
import mdx from "@next/mdx";
import { readFileSync } from "fs";
import { join, dirname } from "path";
import { fileURLToPath } from "url";

const withMDX = mdx({
options: {
providerImportSource: "@mdx-js/react",
},
});

const __dirname = dirname(fileURLToPath(import.meta.url));

/**
* The names of the packages that come from the same monorepo as this package.
* We want these to be transpiled by Next.js because we are directly importing
* the source typescript files from these packages.
*/
const references = JSON.parse(
readFileSync(join(__dirname, "tsconfig.json"), "utf-8"),
).references.map(({ path }) => {
return JSON.parse(
readFileSync(join(__dirname, path, "package.json"), "utf-8"),
).name;
});

/** @type {import('next').NextConfig} */
const nextConfig = {
webpack(config) {
Expand All @@ -14,11 +33,24 @@ const nextConfig = {
use: ["@svgr/webpack"],
});

// Set our custom condition for the bundler so that we directly use
// typescript from packages in our monorepo, which makes hot-reloading
// smoother. Based on
// https://github.com/vercel/next.js/discussions/33813#discussioncomment-7457277
config.plugins.push({
apply(compiler) {
compiler.hooks.afterEnvironment.tap("NextEntryPlugin", () => {
compiler.options.resolve.conditionNames.push("cursorless:bundler");
});
},
});

return config;
},
experimental: {
mdxRs: true,
},
transpilePackages: references,
reactStrictMode: true,
output: "export",
};
Expand Down
Loading