Skip to content

Commit

Permalink
perf(dev): skip Remix/React packages in CSS build (#6654)
Browse files Browse the repository at this point in the history
  • Loading branch information
markdalgleish authored Jun 21, 2023
1 parent a52e2b8 commit 286545e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
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

0 comments on commit 286545e

Please sign in to comment.