Repository navigation
feat: add @griffel/turbopack-loader - #1150
Closed
Aziz Gazanchiian (creage) wants to merge 1 commit into
Closed
Aziz Gazanchiian (creage) wants to merge 1 commit into
Aziz Gazanchiian (creage) wants to merge 1 commit into
Conversation
Next.js 16 uses Turbopack by default, which has no ahead-of-time compilation option for Griffel. The loader compiles makeStyles() & makeResetStyles() calls and keeps CSS in the code, it is inserted in runtime to preserve the order of rules. - transform: add "extractCSS" option to keep CSS rules in the code - transform, transform-shaker: support JSX in ".js" & ".mjs" ES modules - vite-plugin, webpack-plugin: exclude "extractCSS" from options Closes microsoft#730
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Next.js 16 uses Turbopack by default, and Griffel has no ahead-of-time compilation for it. Turbopack runs webpack-style loaders but has no plugin API, so
@griffel/webpack-plugindoes not work there.What
@griffel/turbopack-loader(new) compilesmakeStyles()andmakeResetStyles()calls with@griffel/transform.@griffel/transformgets anextractCSSoption (default:true). Withfalse, calls are compiled to__styles()/__resetStyles()/__staticStyles()and the rules stay in the code.@griffel/transformand@griffel/transform-shakernow parse JSX in.jsand.mjsES modules. Next.js projects without TypeScript keep styles and JSX in the same.jsfile, and these failed to parse.@griffel/vite-pluginand@griffel/webpack-pluginomitextractCSSfrom their options (types only).CSS extraction is not part of this PR. Turbopack strips comments that mark style buckets and does not allow sorting rules across chunks. A naive version of extraction produced a wrong cascade in the browser, for example
padding-left: 1pxinstead of10px. Rules are inserted at runtime instead, so the bucket order is kept.How it works
oxc-resolverwithpathsfrom the closesttsconfig.jsonorjsconfig.json.Limitations
These are listed in the README, with workarounds where they exist:
envinnext.config.jsevaluate toundefined, so styles that use them are dropped.next/font,import.metaand browser globals in evaluated code cause a build error./* griffel-css-extraction-disable */opts a file out.turbopack.resolveAliasandturbopack.resolveExtensionsare not supported.makeStaticStyles()is not compiled by default, because@fluentui/react-componentsdoes not export__staticStyles.Testing
@fluentui/react-components. A build on Next.js 16.0.0 also works.transform,css-extraction-utils,webpack-pluginandpostcss-syntaxfail both on this branch and onmain.