@@ -17,7 +17,7 @@ import type { TurboLoaderOptions } from '@vanilla-extract/turbopack-plugin';
1717const require = createRequire ( import . meta. url ) ;
1818
1919type PluginOptions = ConstructorParameters < typeof VanillaExtractPlugin > [ 0 ] & {
20- turbopackGlob ?: string ;
20+ turbopackGlob ?: string [ ] ;
2121} ;
2222
2323const NextMiniCssExtractPlugin = NextMiniCssExtractPluginDefault as any ;
@@ -140,35 +140,39 @@ export const createVanillaExtractPlugin = (
140140) => {
141141 return ( nextConfig : NextConfig = { } ) : NextConfig => {
142142 const {
143- turbopackGlob = '**/*.css.{ts,tsx,js,jsx}' ,
143+ turbopackGlob = [ '**/*.css.{ts,tsx,js,jsx}' ] ,
144144 ...webpackPluginOptions
145145 } = pluginOptions ;
146146 const turbopack = { ...( nextConfig . turbopack || { } ) } ;
147147
148148 if (
149- turbopack . rules ?. [ turbopackGlob ] ||
149+ turbopackGlob . some ( ( glob ) => turbopack . rules ?. [ glob ] ) ||
150150 turbopack . rules ?. [ 'vanilla.virtual.css' ]
151151 ) {
152152 throw new Error (
153153 'Vanilla extract could not be applied automatically due to conflicting turbopack rules' ,
154154 ) ;
155155 }
156156
157+ const vanillaExtractRule = {
158+ as : '*.js' ,
159+ loaders : [
160+ {
161+ loader : require . resolve ( '@vanilla-extract/turbopack-plugin' ) ,
162+ options : {
163+ nextEnv : nextConfig . env ?? null ,
164+ outputCss : pluginOptions . outputCss ?? null ,
165+ identifiers : pluginOptions . identifiers ?? null ,
166+ } satisfies TurboLoaderOptions ,
167+ } ,
168+ ] ,
169+ } as const ;
170+
157171 turbopack . rules = {
158172 ...( turbopack . rules || { } ) ,
159- [ turbopackGlob ] : {
160- as : '*.js' ,
161- loaders : [
162- {
163- loader : require . resolve ( '@vanilla-extract/turbopack-plugin' ) ,
164- options : {
165- nextEnv : nextConfig . env ?? null ,
166- outputCss : pluginOptions . outputCss ?? null ,
167- identifiers : pluginOptions . identifiers ?? null ,
168- } satisfies TurboLoaderOptions ,
169- } ,
170- ] ,
171- } ,
173+ ...Object . fromEntries (
174+ turbopackGlob . map ( ( glob ) => [ glob , vanillaExtractRule ] ) ,
175+ ) ,
172176 'vanilla.virtual.css' : {
173177 loaders : [ require . resolve ( '@vanilla-extract/turbopack-plugin' ) ] ,
174178 } ,
0 commit comments