Skip to content
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

perf(dev): skip Remix/React packages in CSS build #6654

Merged
merged 3 commits into from
Jun 21, 2023
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions .changeset/css-bundle-skip-packages.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@remix-run/dev": patch
---

Improve performance of CSS bundle build by skipping compilation of Remix/React packages that are known not to contain CSS imports
4 changes: 4 additions & 0 deletions packages/remix-dev/compiler/css/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ const createEsbuildConfig = (ctx: Context): esbuild.BuildOptions => {
absoluteCssUrlsPlugin(),
externalPlugin(/^https?:\/\//, { sideEffects: false }),
mdxPlugin(ctx),
// Skip compilation of common packages/scopes known not to include CSS imports
emptyModulesPlugin(ctx, /^(@remix-run|react|react-dom)(\/.*)?$/, {
includeNodeModules: true,
}),
emptyModulesPlugin(ctx, /\.server(\.[jt]sx?)?$/),
externalPlugin(/^node:.*/, { sideEffects: false }),
],
Expand Down
9 changes: 6 additions & 3 deletions packages/remix-dev/compiler/plugins/emptyModules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,21 @@ import type { Context } from "../context";
*/
export function emptyModulesPlugin(
{ config }: Context,
filter: RegExp
filter: RegExp,
{ includeNodeModules = false } = {}
): esbuild.Plugin {
return {
name: "empty-modules",
setup(build) {
build.onResolve({ filter }, (args) => {
let resolved = path.resolve(args.resolveDir, args.path);
if (
includeNodeModules ||
// Limit this behavior to modules found in only the `app` directory.
// This allows node_modules to use the `.server.js` and `.client.js`
// naming conventions with different semantics.
resolved.startsWith(config.appDirectory)
path
.resolve(args.resolveDir, args.path)
.startsWith(config.appDirectory)
) {
return { path: args.path, namespace: "empty-module" };
}
Expand Down