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

fix: decouple css-bundle from dev #6982

Merged
merged 3 commits into from
Jul 30, 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
7 changes: 7 additions & 0 deletions .changeset/decouple-css-bundle-from-dev.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@remix-run/css-bundle": patch
"@remix-run/dev": patch
---
Decouple the `@remix-run/dev` package from the contents of the `@remix-run/css-bundle` package.

The contents of the `@remix-run/css-bundle` package are now entirely managed by the Remix compiler. Even though it's still recommended that your Remix dependencies all share the same version, this change ensures that there are no runtime errors when upgrading `@remix-run/dev` without upgrading `@remix-run/css-bundle`.
13 changes: 4 additions & 9 deletions packages/remix-css-bundle/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
declare const __INJECT_CSS_BUNDLE_HREF__: string | undefined;

// Injected by `cssBundlePlugin`
let cssBundleHref: string | undefined =
typeof __INJECT_CSS_BUNDLE_HREF__ === "string"
? __INJECT_CSS_BUNDLE_HREF__
: undefined;

export { cssBundleHref };
// This file's contents are replaced by `cssBundlePlugin`. This file only exists
// to provide type definitions and a graceful fallback when importing this
// package outside of the Remix compiler.
export const cssBundleHref: string | undefined = undefined;
16 changes: 5 additions & 11 deletions packages/remix-dev/compiler/plugins/cssBundlePlugin.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import type { Plugin } from "esbuild";
import { readFile } from "fs-extra";

import type { LazyValue } from "../lazyValue";

const pluginName = "css-bundle-update-plugin";
const pluginName = "css-bundle-plugin";
const namespace = `${pluginName}-ns`;

/**
Expand Down Expand Up @@ -38,19 +37,14 @@ export function cssBundlePlugin(refs: {
};
});

build.onLoad({ filter: /.*/, namespace }, async (args) => {
build.onLoad({ filter: /.*/, namespace }, async () => {
let cssBundleHref = await refs.lazyCssBundleHref.get();

let contents = await readFile(args.path, "utf8");

contents = contents.replace(
/__INJECT_CSS_BUNDLE_HREF__/g,
cssBundleHref ? JSON.stringify(cssBundleHref) : "undefined"
);

return {
loader: "js",
contents,
contents: `export const cssBundleHref = ${
cssBundleHref ? JSON.stringify(cssBundleHref) : "undefined"
};`,
};
});
},
Expand Down