@@ -21,6 +21,26 @@ import babel from 'esbuild-plugin-babel';
2121import { camelCase } from 'change-case' ;
2222import { NodePackageImporter } from 'sass-embedded' ;
2323
24+ // Optional dependency: @wordpress /theme provides plugins that inject fallback
25+ // values for design system tokens. Fails gracefully when the package is not
26+ // installed (it is an optional peerDependency).
27+ let dsTokenFallbacks ;
28+ let dsTokenFallbacksJs ;
29+ try {
30+ const { default : postcssPlugin } = await import (
31+ // eslint-disable-next-line import/no-unresolved
32+ '@wordpress/theme/postcss-plugins/postcss-ds-token-fallbacks'
33+ ) ;
34+ const { default : esbuildPlugin } = await import (
35+ // eslint-disable-next-line import/no-unresolved
36+ '@wordpress/theme/esbuild-plugins/esbuild-ds-token-fallbacks'
37+ ) ;
38+ dsTokenFallbacks = postcssPlugin ;
39+ dsTokenFallbacksJs = esbuildPlugin ;
40+ } catch {
41+ // @wordpress /theme is optional; skip token fallbacks if not available.
42+ }
43+
2444/**
2545 * Internal dependencies
2646 */
@@ -150,8 +170,9 @@ function compileInlineStyle( { cssModules = false, minify = true } = {} ) {
150170
151171 let moduleExports = null ;
152172
153- // Transform the code: CSS modules and minification.
173+ // Transform the code: token fallbacks, CSS modules and minification.
154174 const plugins = [
175+ dsTokenFallbacks ,
155176 cssModules &&
156177 postcssModules ( {
157178 generateScopedName : '[contenthash]__[local]' ,
@@ -1242,6 +1263,7 @@ async function transpilePackage( packageName ) {
12421263 } ,
12431264 } ;
12441265 const plugins = [
1266+ dsTokenFallbacksJs ,
12451267 needsEmotionPlugin && emotionPlugin ,
12461268 wasmInlinePlugin ,
12471269 externalizeAllExceptCssPlugin ,
0 commit comments