From f1e6a71561f9bd32dd21bf7bd930339700e2416c Mon Sep 17 00:00:00 2001 From: Mark Dalgleish Date: Wed, 12 Apr 2023 11:05:13 +1000 Subject: [PATCH] feat(dev): enable all CSS bundling features --- .changeset/css-bundling.md | 118 ++ docs/guides/styling.md | 59 +- docs/pages/api-development-strategy.md | 3 - integration/css-modules-test.ts | 5 - integration/css-side-effect-imports-test.ts | 5 - .../deterministic-build-output-test.ts | 67 - integration/hmr-test.ts | 13 - integration/postcss-test.ts | 3 - integration/tailwind-test.ts | 5 - integration/vanilla-extract-test.ts | 1220 ++++++++--------- .../remix-dev/__tests__/readConfig-test.ts | 6 - packages/remix-dev/compiler/assets/css.ts | 43 +- packages/remix-dev/compiler/assets/js.ts | 42 +- .../cached.ts => vanillaExtract.ts} | 110 +- .../compiler/plugins/vanillaExtract/index.ts | 30 - .../plugins/vanillaExtract/sideEffects.ts | 40 - .../plugins/vanillaExtract/uncached.ts | 182 --- packages/remix-dev/compiler/server/index.ts | 19 +- packages/remix-dev/config.ts | 49 +- packages/remix-react/entry.ts | 7 - packages/remix-server-runtime/entry.ts | 7 - packages/remix-testing/create-remix-stub.tsx | 3 - 22 files changed, 842 insertions(+), 1194 deletions(-) create mode 100644 .changeset/css-bundling.md rename packages/remix-dev/compiler/plugins/{vanillaExtract/cached.ts => vanillaExtract.ts} (50%) delete mode 100644 packages/remix-dev/compiler/plugins/vanillaExtract/index.ts delete mode 100644 packages/remix-dev/compiler/plugins/vanillaExtract/sideEffects.ts delete mode 100644 packages/remix-dev/compiler/plugins/vanillaExtract/uncached.ts diff --git a/.changeset/css-bundling.md b/.changeset/css-bundling.md new file mode 100644 index 00000000000..b918ae92e1e --- /dev/null +++ b/.changeset/css-bundling.md @@ -0,0 +1,118 @@ +--- +"@remix-run/dev": minor +"@remix-run/react": minor +"@remix-run/server-runtime": minor +"@remix-run/testing": minor +--- + +Enable support for [CSS Modules](https://github.com/css-modules/css-modules), [Vanilla Extract](http://vanilla-extract.style) and CSS side-effect imports + +These CSS bundling features were previously only available via `future.unstable_cssModules`, `future.unstable_vanillaExtract` and `future.unstable_cssSideEffectImports` options in `remix.config.js`, but they have now been stabilized. + +**CSS Bundle Setup** + +In order to use these features, you first need to set up CSS bundling in your project. First install the `@remix-run/css-bundle` package. + +```sh +npm i @remix-run/css-bundle +``` + +Then return the exported `cssBundleHref` as a stylesheet link descriptor from the `links` function at the root of your app. + +```tsx +import type { LinksFunction } from "@remix-run/node"; // or cloudflare/deno +import { cssBundleHref } from "@remix-run/css-bundle"; + +export const links: LinksFunction = () => { + return [ + ...(cssBundleHref + ? [{ rel: "stylesheet", href: cssBundleHref }] + : []), + // ... + ]; +}; +``` + +**CSS Modules** + +To use [CSS Modules](https://github.com/css-modules/css-modules), you can opt in via the `.module.css` file name convention. For example: + +```css +.root { + border: solid 1px; + background: white; + color: #454545; +} +``` + +```tsx +import styles from "./styles.module.css"; + +export const Button = React.forwardRef( + ({ children, ...props }, ref) => { + return ( +