@teacss/rsbuild 0.9.0-alpha.3 → 0.9.0-alpha.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +10 -7
- package/dist/index.js +1 -1
- package/package.json +7 -7
package/dist/index.d.ts
CHANGED
|
@@ -18,7 +18,9 @@ interface TeacssPluginOptions extends TeacssGenerateOptions {
|
|
|
18
18
|
/**
|
|
19
19
|
* Optimize the output with lightningcss (minify + vendor prefixing).
|
|
20
20
|
* `true`/`false` toggles it; `{ minify }` overrides just minification.
|
|
21
|
-
* @default
|
|
21
|
+
* @default in production, only when Rspack's own lightningcss loader or CSS
|
|
22
|
+
* minifier is off or `targets` is set (otherwise they optimize this output);
|
|
23
|
+
* skip in development.
|
|
22
24
|
*/
|
|
23
25
|
optimize?: boolean | {
|
|
24
26
|
minify?: boolean;
|
|
@@ -39,20 +41,20 @@ interface TeacssPluginOptions extends TeacssGenerateOptions {
|
|
|
39
41
|
test?: RegExp;
|
|
40
42
|
};
|
|
41
43
|
}
|
|
42
|
-
/** Build a `readSources` that scans `@source` include/exclude globs relative to the entry dir. */
|
|
44
|
+
/** Build a `readSources` that scans `@source` include/exclude globs relative to the entry dir; the runtime reads the files. */
|
|
43
45
|
export declare function makeReadSources(base: string, ignore?: string[]): (includes: string[], excludes: string[]) => Promise<{
|
|
44
46
|
files: string[];
|
|
45
|
-
sources
|
|
47
|
+
sources?: string[];
|
|
46
48
|
}>;
|
|
47
49
|
interface GenerateEntryCssOptions {
|
|
48
50
|
/** Entry file directory — base for `@presets` relative specifiers and `@source` globs. */
|
|
49
51
|
base: string;
|
|
50
52
|
/** Entry filename, when known, so local `@import` cycles include the root identity. */
|
|
51
53
|
entryFile?: string;
|
|
52
|
-
/**
|
|
54
|
+
/** Scan content for include/exclude globs; `sources` may be omitted so the runtime reads the files. Omit when `contents` is given. */
|
|
53
55
|
readSources?: (includes: string[], excludes: string[]) => Promise<{
|
|
54
56
|
files: string[];
|
|
55
|
-
sources
|
|
57
|
+
sources?: string[];
|
|
56
58
|
}>;
|
|
57
59
|
/** Inline content (tests / programmatic use) — skips `readSources`. */
|
|
58
60
|
contents?: string[];
|
|
@@ -75,8 +77,9 @@ export declare function generateEntryCss(entryCss: string, options: GenerateEntr
|
|
|
75
77
|
* utilities, optimized with lightningcss, and inline `@apply` in any `.css`.
|
|
76
78
|
* PostCSS-free.
|
|
77
79
|
*
|
|
78
|
-
* -
|
|
79
|
-
*
|
|
80
|
+
* - Leaves production optimization (minify + prefix) to Rspack's lightningcss
|
|
81
|
+
* loader and minimizer; runs its own pass only when those are off or
|
|
82
|
+
* `optimize`/`targets` asks for it. Development emits the raw layers.
|
|
80
83
|
* - Registers scanned files as build dependencies, so editing content re-runs
|
|
81
84
|
* generation in watch/dev mode.
|
|
82
85
|
* - `@apply` (+ `@screen`/`theme()`/`icon()`) is inlined in every `.css`
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createRequire as e}from"node:module";import{statSync as t}from"node:fs";import{dirname as n,isAbsolute as r,posix as i,resolve as a}from"node:path";import o from"node:process";import{fileURLToPath as s}from"node:url";import{DEFAULT_SOURCE_IGNORE as c,generateSources as l,readSourceFile as u}from"@teacss/runtime/source-generation";import{bundledAssetName as d,collectBundledAssets as f}from"@teacss/runtime/internal/bundled-assets";var p=class{apply(e){e.hooks.thisCompilation.tap(`teacss-fonts`,t=>{t.hooks.processAssets.tap({name:`teacss-fonts`,stage:e.webpack.Compilation.PROCESS_ASSETS_STAGE_PRE_PROCESS},()=>{let{RawSource:n,ReplaceSource:r}=e.webpack.sources;for(let{name:e,source:a}of t.getAssets()){if(!e.endsWith(`.css`))continue;let o=f(a.source().toString());if(!o.length)continue;let s=new r(a);for(let{start:r,end:a,asset:c}of o){let o=`teacss-fonts/${d(c)}`;t.getAsset(o)||t.emitAsset(o,new n(Buffer.from(c.bytes)),{immutable:!0}),s.replace(r,a-1,`url(${JSON.stringify(`./${i.relative(i.dirname(e),o)}`)})`)}t.updateAsset(e,s)}})})}};const m=/\.(css|postcss|sass|scss|less|stylus|styl)(\?|$)/,h=(e,t=0)=>e<<16|t<<8,g={safari:h(14),chrome:h(90),firefox:h(88),edge:h(90)};function _(e,t){e.lastIndex=0;let n=e.test(t);return e.lastIndex=0,n}function ee(e){return/@(presets?|primary|neutral|success|warning|failure|general|focused|custom|source|shortcut|safelist)\b/.test(e)||e.includes(`@apply`)||e.includes(`--at-apply`)||e.includes(`@screen`)||e.includes(`theme(`)||e.includes(`icon(`)}function v(e,n,r,i){let a=t(e,{throwIfNoEntry:!1});a?a.isDirectory()?i(e):n(e):r(e)}const y=/[*?[\]{}()]/;function b(e,t){let r=t;for(;y.test(r);)r=n(r);return a(e,r)}async function x(e,t,n){let{scanSourceFiles:r}=await import(`@teacss/config/internal/source-scan`),i=await r(t,{cwd:e,expandDirectories:!0,ignore:n});return{files:i,sources:i.map(u)}}async function te(e,t,r,i=[]){let{cwd:a=o.cwd(),contents:s}=e,u=r??(await import(`@teacss/runtime`)).defaultFilesystemGlobs,d=i[0]?n(i[0]):a,f=t.config.content?.filesystem,p=f??u,m=e.ignore??(f===void 0?c:[]),{files:h,sources:g}=s?{files:[],sources:s}:await x(d,p,m),_=await l(t,h,g);return{css:_.getLayers()||``,utilities:_.matched.size,files:h}}function S(e,t=[]){return async(n,r)=>{let{scanSourceFiles:i}=await import(`@teacss/config/internal/source-scan`),a=await i(n,{cwd:e,expandDirectories:!0,ignore:[...r,...t]});return{files:a,sources:await Promise.all(a.map(u))}}}const C={icons:`@teacss/preset-icons`,official:`@teacss/preset-official`,standard:`@teacss/preset-standard`};function w(t,n){try{return n.resolve(t)}catch(r){let i;try{i=n.resolve(`teacss/package.json`)}catch{throw r}return e(i).resolve(t)}}function ne(e){return e.filter(e=>!e.startsWith(`.`)&&!r(e))}function re(t,n){let r=e(a(n,`_`));return t.map(e=>{let t=Object.hasOwn(C,e)?C[e]:void 0;return t?w(t,r):r.resolve(e)})}function ie(e,t){return e.length===t.length&&e.every((e,n)=>e===t[n])}async function T(e,t){return D(e,t,await M(e,t.base,t.entryFile))}async function E(e){let t=e.config.content?.filesystem,n=t??(await import(`@teacss/runtime`)).defaultFilesystemGlobs;return{includes:n.filter(e=>!e.startsWith(`!`)),excludes:[...n.filter(e=>e.startsWith(`!`)).map(e=>e.slice(1)),...t===void 0?c:[]]}}async function D(e,t,n){let{spliceEntry:r}=await import(`@teacss/directives`),{includes:i,excludes:a}=await E(n.generator),{files:o,sources:s}=t.contents?{files:[],sources:t.contents}:t.readSources?await t.readSources(i,a):{files:[],sources:[]},c=await l(n.generator,o,s);return{css:r(e,c.getLayers()||``),files:o,matched:c.matched.size,unknown:n.unknown,hasPreset:n.hasPreset}}async function ae(e,{minify:t=!0,targets:n,browserslist:r}={}){let{transform:i,browserslistToTargets:a,Features:o}=await import(`lightningcss`),{prepareEasingStylesheet:s}=await import(`@teacss/directives/internal/easing`),c=n??(r?.length?a(r):g),l=k(s(e)),u=i({filename:`teacss.css`,code:Buffer.from(l.css),minify:t,errorRecovery:!0,targets:c,exclude:o.DirSelector});return{css:l.restore(u.code.toString()),skipped:u.warnings?.length??0}}const O=/(^|[;{])((?:\s|\/\*[\s\S]*?\*\/)*)all((?:\s|\/\*[\s\S]*?\*\/)*):((?:\s|\/\*[\s\S]*?\*\/)*)(?=(?:var|env)\()/gi;function k(e){let t=`--teacss-optimized-all`;for(;e.includes(t);)t+=`-x`;return{css:e.replace(O,(e,n,r,i,a)=>`${n}${r}${t}${i}:${a}`),restore:e=>e.replaceAll(t,`all`)}}function A(e,t){return typeof e==`boolean`||e==null?(e??!0)&&t:e.css!==!1&&(e.css===`always`||t)}async function j(e,t,n=[]){let{cwd:r=o.cwd(),configPath:i,config:a}=e,{createGenerator:s}=await import(`@teacss/core`),c=t??(await import(`@teacss/config`)).createRecoveryConfigLoader(),l=a?{config:a,sources:[]}:await c(r,i);return{generator:await s(n.length?{...l.config,safelist:[...l.config.safelist??[],...n]}:l.config,{engine:`auto`}),sources:l.sources}}async function M(e,t,n){let[{resolveEntryConfig:r},{createGenerator:i}]=await Promise.all([import(`@teacss/config`),import(`@teacss/core`)]),{config:a,sources:o,unknown:s}=await r(e,t,n);return{generator:await i(a,{engine:`auto`}),sources:o,unknown:s,hasPreset:!!a.presets?.length,hasEntryConfig:!!(a.presets?.length||a.content||a.shortcuts||Object.keys(a.theme??{}).length||s.length),safelist:(a.safelist??[]).filter(e=>typeof e==`string`)}}async function oe(e,t,n){let[{transformDirectives:r},{default:i}]=await Promise.all([import(`@teacss/directives`),import(`magic-string`)]),a=new i(e);return await r(a,n,{},t),a.toString()}function N(e={}){let{optimize:r,targets:i,test:c=/index\.css$/,apply:l,...u}=e,d=l!==!1,f=typeof l==`object`&&l.test||m;return{name:`teacss`,setup(e){e.modifyRspackConfig(e=>{e.plugins??=[],e.plugins.push(new p)}),e.modifyRsbuildConfig((e,{mergeRsbuildConfig:t})=>t({tools:{lightningcssLoader:{exclude:{dirSelector:!0}}}},e)),e.modifyBundlerChain({order:`post`,handler(e,{CHAIN_ID:t,environment:n}){let r=n.config;if(r.tools.lightningcssLoader===!1&&!A(r.output.minify,r.mode===`production`))return;let i=s(new URL(import.meta.url.endsWith(`.ts`)?`./easing-loader.ts`:`./easing-loader.js`,import.meta.url)),a=[...e.module.rules.values()];for(let e of a){if(a.push(...e.rules.values(),...e.oneOfs.values()),!e.uses.has(t.USE.CSS))continue;let n=e.uses.has(`teacss-easing`),r=e.uses.has(t.USE.LIGHTNINGCSS)?t.USE.LIGHTNINGCSS:t.USE.CSS;e.use(`teacss-easing`).loader(i).after(r),n||e.use(t.USE.CSS).tap(e=>{let t=e;return{...t,importLoaders:(t.importLoaders??0)+1}})}}});let l,h=()=>l??=import(`@teacss/config`).then(({createRecoveryConfigLoader:e})=>e()),g=new Map,y=new Map,x=new Map,C=e=>{let t=g.get(e);if(t)return t;let n=h().then(e=>j(u,e));return g.set(e,n),n};e.onBeforeEnvironmentCompile(({environment:e})=>{g.delete(e.name),y.delete(e.name)}),e.transform({test:d?[m,c]:c},async({code:s,environment:l,addDependency:p,addMissingDependency:m,addContextDependency:w,resourcePath:T})=>{let O=T||``,k=_(c,O),N=d&&ee(s),P=N&&_(f,O);if(!k&&!P)return s;let{parseEntry:se,scanTopLevelAtRules:ce,diagnoseEntry:le}=await import(`@teacss/config`),F=k?se(s):void 0,I=F?.hasTeacss===!0;if(!I&&!P)return s;let L=!!(F&&(le(s).length||F.rolePalettes||F.presets.length>0||F.sources.length>0||F.custom.length>0||F.shortcuts.length>0)),ue=I&&ce(s).some(e=>e.name===`import`&&e.terminator===`;`),R=L||ue,z=n(T||`${u.cwd??o.cwd()}/index.css`),B=T||a(z,`index.css`);for(let e of F?.sources??[])e.exclude||v(b(z,e.glob),p,m,w);let V=ne(F?.presets??[]),H,U,W;if(I){if(R)H=M(s,z,B).then(async e=>{if(!L&&!e.hasEntryConfig){let t=await j(u,await h(),e.safelist);e={...e,generator:t.generator,sources:[...e.sources,...t.sources],hasPreset:!!t.generator.config.presets.length,scanBase:t.sources[0]?n(t.sources[0]):u.cwd??o.cwd()}}return U={...e,sources:Array.from(new Set([B,...e.sources]))},U}).catch(async t=>{let{getConfigSourcesFromError:n}=await import(`@teacss/config`),r=n(t);for(let e of r)v(e,p,m,w);let i=x.get(l.name);if(!i||i.id!==B)throw t;let a=Array.from(new Set([...i.state.sources,...r]));return e.logger.warn(`@teacss/rsbuild: keeping the last valid config for ${B} while its preset graph is invalid`),a.length===i.state.sources.length?i.state:{...i.state,sources:a}}),y.set(l.name,H),d?g.set(l.name,H):g.delete(l.name);else if(F.safelist.length>0){let{expandClassGroups:e,splitClassTokens:t}=await import(`@teacss/core`),n=F.safelist.flatMap(n=>t(e(n))),r=h().then(e=>j(u,e,n));g.set(l.name,r),y.delete(l.name),x.delete(l.name)}else g.delete(l.name),y.delete(l.name),x.delete(l.name)}let G=()=>{U&&W&&H&&y.get(l.name)===H&&x.set(l.name,{id:B,packagePresetDependencies:W,packagePresetSpecifiers:V,state:U})},K=s,q;if(N&&(I||P)){try{q=await C(l.name)}catch(e){if(!H){let{getConfigSourcesFromError:t}=await import(`@teacss/config`);for(let n of t(e))v(n,p,m,w)}throw e}for(let e of q.sources)v(e,p,m,w);K=await oe(s,O,q.generator)}if(!I)return K===s?s:{code:K};let J,Y,X,Z=[],Q=!0,$=[];if(R){let n=H?await H:await M(K,z,B),r=n.scanBase??z;for(let e of(await E(n.generator)).includes)v(b(r,e),p,m,w);({css:J,files:X,matched:Y,unknown:Z,hasPreset:Q}=await D(K,{base:z,contents:u.contents,readSources:S(r,u.ignore)},n));try{W=re(V,z)}catch(n){let r=x.get(l.name);if(!(r?.id===B&&ie(r.packagePresetSpecifiers,V)&&r.packagePresetDependencies.some(e=>!t(e,{throwIfNoEntry:!1}))))throw n;W=r.packagePresetDependencies,e.logger.warn(`@teacss/rsbuild: keeping the last valid package preset dependencies for ${B} while package entries are unavailable`)}$=Array.from(new Set([...W,...n.sources]))}else{q??=await C(l.name);let e=await te(u,q.generator,void 0,q.sources),{spliceEntry:t}=await import(`@teacss/directives`);J=t(K,e.css),Y=e.utilities,X=e.files,$=q.sources}Q||e.logger.warn(`@teacss/rsbuild: ${T||`entry`} declares no @presets — no utilities generated. Add one, e.g. \`@presets "standard";\``),Z.length&&e.logger.warn(`@teacss/rsbuild: ${Z.length} @custom var(s) not registered (unknown namespace / illegal color step): ${Z.join(`, `)}`);for(let e of X)p(e);for(let e of $)v(e,p,m,w);let de=(l.config.mode??o.env.NODE_ENV)===`production`;if(!(r??de))return e.logger.info(`@teacss/rsbuild: ${Y} utilities (dev, unoptimized) → ${(J.length/1024).toFixed(1)}KB`),G(),{code:J};let fe=typeof r==`object`&&r.minify!==void 0?r.minify:A(l.config.output.minify,de),{css:pe,skipped:me}=await ae(J,{minify:fe,targets:i,browserslist:l.browserslist});return e.logger.info(`@teacss/rsbuild: ${Y} utilities${me?`, ${me} skipped`:``} → ${(pe.length/1024).toFixed(1)}KB`),G(),{code:pe}})}}}export{T as generateEntryCss,S as makeReadSources,N as pluginTeacss};
|
|
1
|
+
import{createRequire as e}from"node:module";import{statSync as t}from"node:fs";import{dirname as n,isAbsolute as r,posix as i,resolve as a}from"node:path";import o from"node:process";import{fileURLToPath as s}from"node:url";import{DEFAULT_SOURCE_IGNORE as c,generateSources as l}from"@teacss/runtime/source-generation";import{bundledAssetName as u,collectBundledAssets as d}from"@teacss/runtime/internal/bundled-assets";var f=class{apply(e){e.hooks.thisCompilation.tap(`teacss-fonts`,t=>{t.hooks.processAssets.tap({name:`teacss-fonts`,stage:e.webpack.Compilation.PROCESS_ASSETS_STAGE_PRE_PROCESS},()=>{let{RawSource:n,ReplaceSource:r}=e.webpack.sources;for(let{name:e,source:a}of t.getAssets()){if(!e.endsWith(`.css`))continue;let o=d(a.source().toString());if(!o.length)continue;let s=new r(a);for(let{start:r,end:a,asset:c}of o){let o=`teacss-fonts/${u(c)}`;t.getAsset(o)||t.emitAsset(o,new n(Buffer.from(c.bytes)),{immutable:!0}),s.replace(r,a-1,`url(${JSON.stringify(`./${i.relative(i.dirname(e),o)}`)})`)}t.updateAsset(e,s)}})})}};const p=/\.(css|postcss|sass|scss|less|stylus|styl)(\?|$)/,m=(e,t=0)=>e<<16|t<<8,h={safari:m(14),chrome:m(90),firefox:m(88),edge:m(90)};function g(e,t){e.lastIndex=0;let n=e.test(t);return e.lastIndex=0,n}function ee(e){return/@(presets?|primary|neutral|success|warning|failure|general|focused|custom|source|shortcut|safelist)\b/.test(e)||e.includes(`@apply`)||e.includes(`--at-apply`)||e.includes(`@screen`)||e.includes(`theme(`)||e.includes(`icon(`)}function _(e,n,r,i){let a=t(e,{throwIfNoEntry:!1});a?a.isDirectory()?i(e):n(e):r(e)}const v=/[*?[\]{}()]/;function te(e,t){let r=t;for(;v.test(r);)r=n(r);return a(e,r)}async function y(e,t,n){let{scanSourceFiles:r}=await import(`@teacss/config/internal/source-scan`);return r(t,{cwd:e,expandDirectories:!0,ignore:n})}async function ne(e,t,r,i=[]){let{cwd:a=o.cwd(),contents:s}=e,u=r??(await import(`@teacss/runtime`)).defaultFilesystemGlobs,d=i[0]?n(i[0]):a,f=t.config.content?.filesystem,p=f??u,m=e.ignore??(f===void 0?c:[]),h=s?[]:await y(d,p,m),g=await l(t,h,s);return{css:g.getLayers()||``,utilities:g.matched.size,files:h}}function b(e,t=[]){return async(n,r)=>{let{scanSourceFiles:i}=await import(`@teacss/config/internal/source-scan`);return{files:await i(n,{cwd:e,expandDirectories:!0,ignore:[...r,...t]})}}}const x={icons:`@teacss/preset-icons`,official:`@teacss/preset-official`,standard:`@teacss/preset-standard`};function S(t,n){try{return n.resolve(t)}catch(r){let i;try{i=n.resolve(`teacss/package.json`)}catch{throw r}return e(i).resolve(t)}}function re(e){return e.filter(e=>!e.startsWith(`.`)&&!r(e))}function ie(t,n){let r=e(a(n,`_`));return t.map(e=>{let t=Object.hasOwn(x,e)?x[e]:void 0;return t?S(t,r):r.resolve(e)})}function ae(e,t){return e.length===t.length&&e.every((e,n)=>e===t[n])}async function C(e,t){return E(e,t,await j(e,t.base,t.entryFile))}async function w(e,n){let r=[];for(let i of e.sources){let e;try{e=t(i,{throwIfNoEntry:!1})}catch{return}if(e&&n!==void 0&&Math.max(e.mtimeMs,e.ctimeMs)>=n)return;r.push(e?`${e.mtimeMs}:${e.ctimeMs}:${e.size}:${e.ino}`:`missing`)}let{probeSourceDeclarations:i}=await import(`@teacss/config/internal/source-scan`),a=await i(e.declarations,n!==void 0);return JSON.stringify([r,a.signature])}async function T(e){let t=e.config.content?.filesystem,n=t??(await import(`@teacss/runtime`)).defaultFilesystemGlobs;return{includes:n.filter(e=>!e.startsWith(`!`)),excludes:[...n.filter(e=>e.startsWith(`!`)).map(e=>e.slice(1)),...t===void 0?c:[]]}}async function E(e,t,n){let{spliceEntry:r}=await import(`@teacss/directives`),{includes:i,excludes:a}=await T(n.generator),{files:o,sources:s}=t.contents?{files:[],sources:t.contents}:t.readSources?await t.readSources(i,a):{files:[],sources:[]},c=await l(n.generator,o,s);return{css:r(e,c.getLayers()||``),files:o,matched:c.matched.size,unknown:n.unknown,hasPreset:n.hasPreset}}async function oe(e,{minify:t=!0,targets:n,browserslist:r}={}){let{transform:i,browserslistToTargets:a,Features:o}=await import(`lightningcss`),{prepareEasingStylesheet:s}=await import(`@teacss/directives/internal/easing`),c=n??(r?.length?a(r):h),l=O(s(e)),u=i({filename:`teacss.css`,code:Buffer.from(l.css),minify:t,errorRecovery:!0,targets:c,exclude:o.DirSelector});return{css:l.restore(u.code.toString()),skipped:u.warnings?.length??0}}const D=/(^|[;{])((?:\s|\/\*[\s\S]*?\*\/)*)all((?:\s|\/\*[\s\S]*?\*\/)*):((?:\s|\/\*[\s\S]*?\*\/)*)(?=(?:var|env)\()/gi;function O(e){let t=`--teacss-optimized-all`;for(;e.includes(t);)t+=`-x`;return{css:e.replace(D,(e,n,r,i,a)=>`${n}${r}${t}${i}:${a}`),restore:e=>e.replaceAll(t,`all`)}}function k(e,t){return typeof e==`boolean`||e==null?(e??!0)&&t:e.css!==!1&&(e.css===`always`||t)}async function A(e,t,n=[]){let{cwd:r=o.cwd(),configPath:i,config:a}=e,{createGenerator:s}=await import(`@teacss/core`),c=t??(await import(`@teacss/config`)).createRecoveryConfigLoader(),l=a?{config:a,sources:[]}:await c(r,i);return{generator:await s(n.length?{...l.config,safelist:[...l.config.safelist??[],...n]}:l.config,{engine:`auto`}),sources:l.sources}}async function j(e,t,n){let[{resolveEntryConfig:r},{sourceDeclarationStateOf:i},{createGenerator:a}]=await Promise.all([import(`@teacss/config`),import(`@teacss/config/internal/source-scan`),import(`@teacss/core`)]),o=await r(e,t,n),{config:s,sources:c,unknown:l}=o;return{generator:await a(s,{engine:`auto`}),sources:c,unknown:l,declarations:i(o),hasPreset:!!s.presets?.length,hasEntryConfig:!!(s.presets?.length||s.content||s.shortcuts||Object.keys(s.theme??{}).length||l.length),safelist:(s.safelist??[]).filter(e=>typeof e==`string`)}}async function se(e,t,n){let[{transformDirectives:r},{default:i}]=await Promise.all([import(`@teacss/directives`),import(`magic-string`)]),a=new i(e);return await r(a,n,{},t),a.toString()}function M(e={}){let{optimize:r,targets:i,test:c=/index\.css$/,apply:l,...u}=e,d=l!==!1,m=typeof l==`object`&&l.test||p;return{name:`teacss`,setup(e){e.modifyRspackConfig(e=>{e.plugins??=[],e.plugins.push(new f)}),e.modifyRsbuildConfig((e,{mergeRsbuildConfig:t})=>t({tools:{lightningcssLoader:{exclude:{dirSelector:!0}}}},e)),e.modifyBundlerChain({order:`post`,handler(e,{CHAIN_ID:t,environment:n}){let r=n.config;if(r.tools.lightningcssLoader===!1&&!k(r.output.minify,r.mode===`production`))return;let i=s(new URL(import.meta.url.endsWith(`.ts`)?`./easing-loader.ts`:`./easing-loader.js`,import.meta.url)),a=[...e.module.rules.values()];for(let e of a){if(a.push(...e.rules.values(),...e.oneOfs.values()),!e.uses.has(t.USE.CSS))continue;let n=e.uses.has(`teacss-easing`),r=e.uses.has(t.USE.LIGHTNINGCSS)?t.USE.LIGHTNINGCSS:t.USE.CSS;e.use(`teacss-easing`).loader(i).after(r),n||e.use(t.USE.CSS).tap(e=>{let t=e;return{...t,importLoaders:(t.importLoaders??0)+1}})}}});let l,h=()=>l??=import(`@teacss/config`).then(({createRecoveryConfigLoader:e})=>e()),v=new Map,y=new Map,x=new Map,S=e=>{let t=v.get(e);if(t)return t;let n=h().then(e=>A(u,e));return v.set(e,n),n};e.onBeforeEnvironmentCompile(({environment:e})=>{v.delete(e.name),y.delete(e.name)}),e.transform({test:d?[p,c]:c},async({code:s,environment:l,addDependency:f,addMissingDependency:p,addContextDependency:C,resourcePath:D})=>{let O=D||``,M=g(c,O),ce=d&&ee(s),N=ce&&g(m,O);if(!M&&!N)return s;let{parseEntry:le,scanTopLevelAtRules:ue,diagnoseEntry:de}=await import(`@teacss/config`),P=M?le(s):void 0,F=P?.hasTeacss===!0;if(!F&&!N)return s;let I=!!(P&&(de(s).length||P.rolePalettes||P.presets.length>0||P.sources.length>0||P.custom.length>0||P.shortcuts.length>0)),fe=F&&ue(s).some(e=>e.name===`import`&&e.terminator===`;`),L=I||fe,R=n(D||`${u.cwd??o.cwd()}/index.css`),z=D||a(R,`index.css`);for(let e of P?.sources??[])e.exclude||_(te(R,e.glob),f,p,C);let B=re(P?.presets??[]),V,H,U,W;if(F){if(L)V=(async()=>{let e=x.get(l.name);if(e?.id===z&&e.code===s&&e.signature!==void 0&&await w(e.state)===e.signature)return W=e.signature,e.state})().then(async e=>{if(e)return H=e;let t=Date.now(),r=await j(s,R,z),i=!I&&!r.hasEntryConfig;if(i){let e=await A(u,await h(),r.safelist);r={...r,generator:e.generator,sources:[...r.sources,...e.sources],hasPreset:!!e.generator.config.presets.length,scanBase:e.sources[0]?n(e.sources[0]):u.cwd??o.cwd()}}return H={...r,sources:Array.from(new Set([z,...r.sources]))},i||(W=await w(H,t)),H}).catch(async t=>{let{getConfigSourcesFromError:n}=await import(`@teacss/config`),r=n(t);for(let e of r)_(e,f,p,C);let i=x.get(l.name);if(!i||i.id!==z)throw t;let a=Array.from(new Set([...i.state.sources,...r]));return e.logger.warn(`@teacss/rsbuild: keeping the last valid config for ${z} while its preset graph is invalid`),a.length===i.state.sources.length?i.state:{...i.state,sources:a}}),y.set(l.name,V),d?v.set(l.name,V):v.delete(l.name);else if(P.safelist.length>0){let{expandClassGroups:e,splitClassTokens:t}=await import(`@teacss/core`),n=P.safelist.flatMap(n=>t(e(n))),r=h().then(e=>A(u,e,n));v.set(l.name,r),y.delete(l.name),x.delete(l.name)}else v.delete(l.name),y.delete(l.name),x.delete(l.name)}let G=()=>{H&&U&&V&&y.get(l.name)===V&&x.set(l.name,{id:z,code:s,signature:W,packagePresetDependencies:U,packagePresetSpecifiers:B,state:H})},K=s,q;if(ce&&(F||N)){try{q=await S(l.name)}catch(e){if(!V){let{getConfigSourcesFromError:t}=await import(`@teacss/config`);for(let n of t(e))_(n,f,p,C)}throw e}for(let e of q.sources)_(e,f,p,C);K=await se(s,O,q.generator)}if(!F)return K===s?s:{code:K};let J,Y,X,Z=[],pe=!0,Q=[];if(L){let n=V?await V:await j(K,R,z),r=n.scanBase??R;for(let e of(await T(n.generator)).includes)_(te(r,e),f,p,C);({css:J,files:X,matched:Y,unknown:Z,hasPreset:pe}=await E(K,{base:R,contents:u.contents,readSources:b(r,u.ignore)},n));try{U=ie(B,R)}catch(n){let r=x.get(l.name);if(!(r?.id===z&&ae(r.packagePresetSpecifiers,B)&&r.packagePresetDependencies.some(e=>!t(e,{throwIfNoEntry:!1}))))throw n;U=r.packagePresetDependencies,e.logger.warn(`@teacss/rsbuild: keeping the last valid package preset dependencies for ${z} while package entries are unavailable`)}Q=Array.from(new Set([...U,...n.sources]))}else{q??=await S(l.name);let e=await ne(u,q.generator,void 0,q.sources),{spliceEntry:t}=await import(`@teacss/directives`);J=t(K,e.css),Y=e.utilities,X=e.files,Q=q.sources}pe||e.logger.warn(`@teacss/rsbuild: ${D||`entry`} declares no @presets — no utilities generated. Add one, e.g. \`@presets "standard";\``),Z.length&&e.logger.warn(`@teacss/rsbuild: ${Z.length} @custom var(s) not registered (unknown namespace / illegal color step): ${Z.join(`, `)}`);for(let e of X)f(e);for(let e of Q)_(e,f,p,C);let $=(l.config.mode??o.env.NODE_ENV)===`production`,me=i===void 0&&l.config.tools?.lightningcssLoader!==!1&&k(l.config.output.minify,$);if(!(r??($&&!me)))return e.logger.info(`@teacss/rsbuild: ${Y} utilities (${$?`optimized by Rspack`:`dev, unoptimized`}) → ${(J.length/1024).toFixed(1)}KB`),G(),{code:J};let he=typeof r==`object`&&r.minify!==void 0?r.minify:k(l.config.output.minify,$),{css:ge,skipped:_e}=await oe(J,{minify:he,targets:i,browserslist:l.browserslist});return e.logger.info(`@teacss/rsbuild: ${Y} utilities${_e?`, ${_e} skipped`:``} → ${(ge.length/1024).toFixed(1)}KB`),G(),{code:ge}})}}}export{C as generateEntryCss,b as makeReadSources,M as pluginTeacss};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@teacss/rsbuild",
|
|
3
|
-
"version": "0.9.0-alpha.
|
|
3
|
+
"version": "0.9.0-alpha.4",
|
|
4
4
|
"description": "Rsbuild integration for TeaCSS — generate utilities and optimize with lightningcss, no PostCSS.",
|
|
5
5
|
"homepage": "https://css.teasim.com",
|
|
6
6
|
"funding": "https://github.com/sponsors/billgo",
|
|
@@ -23,18 +23,18 @@
|
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"@jridgewell/remapping": "^2.3.5",
|
|
26
|
-
"@teacss/config": "0.9.0-alpha.
|
|
27
|
-
"@teacss/core": "0.9.0-alpha.
|
|
28
|
-
"@teacss/directives": "0.9.0-alpha.
|
|
26
|
+
"@teacss/config": "0.9.0-alpha.4",
|
|
27
|
+
"@teacss/core": "0.9.0-alpha.4",
|
|
28
|
+
"@teacss/directives": "0.9.0-alpha.4",
|
|
29
29
|
"@teacss/engine": "0.9.0-alpha.3",
|
|
30
|
-
"@teacss/runtime": "0.9.0-alpha.
|
|
30
|
+
"@teacss/runtime": "0.9.0-alpha.4",
|
|
31
31
|
"lightningcss": "^1.33.0",
|
|
32
32
|
"magic-string": "^1.2.3"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"@rsbuild/core": "^2.2.3",
|
|
36
|
-
"@teacss/preset-official": "0.9.0-alpha.
|
|
37
|
-
"@teacss/preset-standard": "0.9.0-alpha.
|
|
36
|
+
"@teacss/preset-official": "0.9.0-alpha.4",
|
|
37
|
+
"@teacss/preset-standard": "0.9.0-alpha.4",
|
|
38
38
|
"consola": "^3.4.2"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|