Skip to content

Commit

Permalink
Fix hot reload for dependencies of cursorless-org (#2286)
Browse files Browse the repository at this point in the history
## Checklist

- [x] I have not broken the web cheatsheet / homepage / docs
- [-] I have added
[tests](https://www.cursorless.org/docs/contributing/test-case-recorder/)
- [-] I have updated the
[docs](https://github.com/cursorless-dev/cursorless/tree/main/docs) and
[cheatsheet](https://github.com/cursorless-dev/cursorless/tree/main/cursorless-talon/src/cheatsheet)
- [-] I have not broken the cheatsheet
  • Loading branch information
pokey authored Apr 7, 2024
1 parent f02014f commit c0b1c41
Showing 1 changed file with 32 additions and 0 deletions.
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

0 comments on commit c0b1c41

Please sign in to comment.