@master/css-vite 0.0.0-site.1793659883.g69c9aebcf628
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/README.md +348 -0
- package/dist/common.d.ts +14 -0
- package/dist/common.js +26 -0
- package/dist/core.d.ts +23 -0
- package/dist/core.js +165 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +1 -0
- package/dist/internal/src/emitted-globals-module.js +12 -0
- package/dist/internal/src/manifest-facade.js +68 -0
- package/dist/internal/src/manifest-loader.js +33 -0
- package/dist/internal/src/manifest-module.js +58 -0
- package/dist/internal/src/manifest-virtual-module.js +123 -0
- package/dist/internal/src/node.js +22 -0
- package/dist/internal/src/program-module.js +50 -0
- package/dist/internal/src/project.js +10 -0
- package/dist/internal/src/runtime-bootstrap.js +80 -0
- package/dist/internal/src/style-module.js +3 -0
- package/dist/modes/pre-render.d.ts +5 -0
- package/dist/modes/pre-render.js +6 -0
- package/dist/modes/progressive.d.ts +5 -0
- package/dist/modes/progressive.js +12 -0
- package/dist/modes/runtime.d.ts +5 -0
- package/dist/modes/runtime.js +17 -0
- package/dist/modes/static.d.ts +5 -0
- package/dist/modes/static.js +5 -0
- package/dist/options.d.ts +20 -0
- package/dist/options.js +23 -0
- package/dist/plugins/avoid-fouc.d.ts +5 -0
- package/dist/plugins/avoid-fouc.js +48 -0
- package/dist/plugins/build-stylesheet-recovery.d.ts +5 -0
- package/dist/plugins/build-stylesheet-recovery.js +26 -0
- package/dist/plugins/context.d.ts +5 -0
- package/dist/plugins/context.js +12 -0
- package/dist/plugins/dev-stylesheet.d.ts +4 -0
- package/dist/plugins/dev-stylesheet.js +63 -0
- package/dist/plugins/emitted-globals-virtual-module.d.ts +14 -0
- package/dist/plugins/emitted-globals-virtual-module.js +167 -0
- package/dist/plugins/inject-runtime.d.ts +5 -0
- package/dist/plugins/inject-runtime.js +51 -0
- package/dist/plugins/inline-stylesheet.d.ts +5 -0
- package/dist/plugins/inline-stylesheet.js +197 -0
- package/dist/plugins/local-styles.d.ts +5 -0
- package/dist/plugins/local-styles.js +214 -0
- package/dist/plugins/manifest-loader.d.ts +4 -0
- package/dist/plugins/manifest-loader.js +102 -0
- package/dist/plugins/manifest-virtual-module.d.ts +4 -0
- package/dist/plugins/manifest-virtual-module.js +70 -0
- package/dist/plugins/pre-render.d.ts +5 -0
- package/dist/plugins/pre-render.js +224 -0
- package/dist/plugins/program-preload.d.ts +5 -0
- package/dist/plugins/program-preload.js +37 -0
- package/dist/plugins/runtime-bootstrap.d.ts +3 -0
- package/dist/plugins/runtime-bootstrap.js +14 -0
- package/dist/plugins/runtime-preload.d.ts +4 -0
- package/dist/plugins/runtime-preload.js +38 -0
- package/dist/plugins/sass-source.d.ts +5 -0
- package/dist/plugins/sass-source.js +176 -0
- package/dist/plugins/scanner.d.ts +5 -0
- package/dist/plugins/scanner.js +24 -0
- package/dist/plugins/style-entry-build.d.ts +5 -0
- package/dist/plugins/style-entry-build.js +121 -0
- package/dist/plugins/style-entry-hmr.d.ts +6 -0
- package/dist/plugins/style-entry-hmr.js +78 -0
- package/dist/plugins/style-entry.d.ts +5 -0
- package/dist/plugins/style-entry.js +89 -0
- package/dist/plugins/stylesheet-recovery.d.ts +5 -0
- package/dist/plugins/stylesheet-recovery.js +70 -0
- package/dist/plugins/usage-graph.d.ts +5 -0
- package/dist/plugins/usage-graph.js +48 -0
- package/dist/preset/src/default-manifest.js +15913 -0
- package/dist/utils/build-import-resolver.d.ts +29 -0
- package/dist/utils/build-import-resolver.js +101 -0
- package/dist/utils/build-sass-source.d.ts +38 -0
- package/dist/utils/build-sass-source.js +225 -0
- package/dist/utils/build-stylesheet-delivery.d.ts +12 -0
- package/dist/utils/build-stylesheet-delivery.js +130 -0
- package/dist/utils/build-watch-recovery.d.ts +10 -0
- package/dist/utils/build-watch-recovery.js +119 -0
- package/dist/utils/coalesced-task.d.ts +3 -0
- package/dist/utils/coalesced-task.js +25 -0
- package/dist/utils/dev-module-refresh.d.ts +9 -0
- package/dist/utils/dev-module-refresh.js +17 -0
- package/dist/utils/dev-stylesheet-delivery.d.ts +21 -0
- package/dist/utils/dev-stylesheet-delivery.js +98 -0
- package/dist/utils/environment-closing.d.ts +3 -0
- package/dist/utils/environment-closing.js +28 -0
- package/dist/utils/extracted-css.d.ts +4 -0
- package/dist/utils/extracted-css.js +34 -0
- package/dist/utils/failed-dependency-reconciliation.d.ts +15 -0
- package/dist/utils/failed-dependency-reconciliation.js +150 -0
- package/dist/utils/failed-stylesheet-dependencies.d.ts +16 -0
- package/dist/utils/failed-stylesheet-dependencies.js +92 -0
- package/dist/utils/html.d.ts +8 -0
- package/dist/utils/html.js +36 -0
- package/dist/utils/inline-stylesheet.d.ts +37 -0
- package/dist/utils/inline-stylesheet.js +129 -0
- package/dist/utils/local-stylesheet.d.ts +10 -0
- package/dist/utils/local-stylesheet.js +25 -0
- package/dist/utils/manifest-recovery.d.ts +11 -0
- package/dist/utils/manifest-recovery.js +77 -0
- package/dist/utils/module-sources.d.ts +26 -0
- package/dist/utils/module-sources.js +131 -0
- package/dist/utils/path.d.ts +5 -0
- package/dist/utils/path.js +27 -0
- package/dist/utils/recovery-error.d.ts +3 -0
- package/dist/utils/recovery-error.js +17 -0
- package/dist/utils/register-style-source.d.ts +4 -0
- package/dist/utils/register-style-source.js +23 -0
- package/dist/utils/sass-diagnostics.d.ts +4 -0
- package/dist/utils/sass-diagnostics.js +109 -0
- package/dist/utils/sass-proxy-access.d.ts +4 -0
- package/dist/utils/sass-proxy-access.js +28 -0
- package/dist/utils/sass-source-markers.d.ts +8 -0
- package/dist/utils/sass-source-markers.js +50 -0
- package/dist/utils/scanner-context.d.ts +12 -0
- package/dist/utils/scanner-context.js +100 -0
- package/dist/utils/scoped-plugins.d.ts +4 -0
- package/dist/utils/scoped-plugins.js +81 -0
- package/dist/utils/write-file.d.ts +3 -0
- package/dist/utils/write-file.js +9 -0
- package/package.json +62 -0
package/README.md
ADDED
|
@@ -0,0 +1,348 @@
|
|
|
1
|
+
<br>
|
|
2
|
+
<div align="center">
|
|
3
|
+
|
|
4
|
+
<p align="center">
|
|
5
|
+
<a href="https://css.master.co">
|
|
6
|
+
<picture>
|
|
7
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://user-images.githubusercontent.com/33840671/201701649-3bb7d698-abec-4d5f-ac30-ccc4d7bafcd4.svg">
|
|
8
|
+
<source media="(prefers-color-scheme: light)" srcset="https://user-images.githubusercontent.com/33840671/201703010-77bf2373-9899-40cc-98f5-30cf9b546941.svg">
|
|
9
|
+
<img alt="Master CSS" src="https://user-images.githubusercontent.com/33840671/201703010-77bf2373-9899-40cc-98f5-30cf9b546941.svg" width="100%">
|
|
10
|
+
</picture>
|
|
11
|
+
</a>
|
|
12
|
+
</p>
|
|
13
|
+
<p align="center">Vite plugin for Master CSS</p>
|
|
14
|
+
|
|
15
|
+
<p align="center">
|
|
16
|
+
<a aria-label="GitHub release (latest by date including pre-releases)" href="https://github.com/master-co/css/releases">
|
|
17
|
+
<picture>
|
|
18
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://img.shields.io/github/v/release/master-co/css?include_prereleases&color=212022&label=&style=for-the-badge&logo=github&logoColor=fff">
|
|
19
|
+
<source media="(prefers-color-scheme: light)" srcset="https://img.shields.io/github/v/release/master-co/css?include_prereleases&color=f6f7f8&label=&style=for-the-badge&logo=github&logoColor=%23000">
|
|
20
|
+
<img alt="NPM Version" src="https://img.shields.io/github/v/release/master-co/css?include_prereleases&color=f6f7f8&label=&style=for-the-badge&logo=github">
|
|
21
|
+
</picture>
|
|
22
|
+
</a>
|
|
23
|
+
<a aria-label="NPM Package" href="https://www.npmjs.com/package/@master/css-vite">
|
|
24
|
+
<picture>
|
|
25
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://img.shields.io/npm/dm/@master/css-vite?color=212022&label=%20&logo=npm&style=for-the-badge">
|
|
26
|
+
<source media="(prefers-color-scheme: light)" srcset="https://img.shields.io/npm/dm/@master/css-vite?color=f6f7f8&label=%20&logo=npm&style=for-the-badge">
|
|
27
|
+
<img alt="NPM package ( download / month )" src="https://img.shields.io/npm/dm/@master/css-vite?color=f6f7f8&label=%20&logo=npm&style=for-the-badge">
|
|
28
|
+
</picture>
|
|
29
|
+
</a>
|
|
30
|
+
<a aria-label="Discord Community" href="https://discord.gg/sZNKpAAAw6">
|
|
31
|
+
<picture>
|
|
32
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://img.shields.io/discord/917780624314613760?color=212022&label=%20&logo=discord&style=for-the-badge">
|
|
33
|
+
<source media="(prefers-color-scheme: light)" srcset="https://img.shields.io/discord/917780624314613760?color=f6f7f8&label=%20&logo=discord&style=for-the-badge">
|
|
34
|
+
<img alt="Discord online" src="https://img.shields.io/discord/917780624314613760?color=f6f7f8&label=%20&logo=discord&style=for-the-badge">
|
|
35
|
+
</picture>
|
|
36
|
+
</a>
|
|
37
|
+
<a aria-label="Follow @mastercorg" href="https://twitter.com/mastercorg">
|
|
38
|
+
<picture>
|
|
39
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://img.shields.io/static/v1?label=%20&message=twitter&color=212022&logo=twitter&style=for-the-badge">
|
|
40
|
+
<source media="(prefers-color-scheme: light)" srcset="https://img.shields.io/static/v1?label=%20&message=twitter&color=f6f7f8&logo=twitter&style=for-the-badge">
|
|
41
|
+
<img alt="Follow @mastercorg" src="https://img.shields.io/static/v1?label=%20&message=twitter&color=f6f7f8&logo=twitter&style=for-the-badge">
|
|
42
|
+
</picture>
|
|
43
|
+
</a>
|
|
44
|
+
<a aria-label="Github Actions" href="https://github.com/master-co/css/actions/workflows/ci-release.yml">
|
|
45
|
+
<picture>
|
|
46
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://img.shields.io/github/actions/workflow/status/master-co/css/ci-release.yml?branch=rc&label=%20&message=twitter&color=212022&logo=githubactions&style=for-the-badge">
|
|
47
|
+
<source media="(prefers-color-scheme: light)" srcset="https://img.shields.io/github/actions/workflow/status/master-co/css/ci-release.yml?branch=rc&label=%20&message=twitter&color=f6f7f8&logo=githubactions&style=for-the-badge&logoColor=%23000">
|
|
48
|
+
<img alt="Github release actions" src="https://img.shields.io/github/actions/workflow/status/master-co/css/ci-release.yml?branch=rc&label=%20&message=twitter&color=f6f7f8&logo=githubactions&style=for-the-badge&logoColor=%23000">
|
|
49
|
+
</picture>
|
|
50
|
+
</a>
|
|
51
|
+
</p>
|
|
52
|
+
|
|
53
|
+
</div>
|
|
54
|
+
|
|
55
|
+
## Installation
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
npm install @master/css-vite
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Usage
|
|
62
|
+
|
|
63
|
+
```js
|
|
64
|
+
import masterCSS from '@master/css-vite'
|
|
65
|
+
|
|
66
|
+
/** @type {import('vite').UserConfig} */
|
|
67
|
+
const config = {
|
|
68
|
+
plugins: [
|
|
69
|
+
masterCSS()
|
|
70
|
+
]
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export default config
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
Import the default stylesheet from the CSS entry your app already loads:
|
|
77
|
+
|
|
78
|
+
```css
|
|
79
|
+
@import '@master/css';
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
During development, `runtime` and `progressive` modes load the injected runtime
|
|
83
|
+
under Vite's resolved `base`, including nested HTML pages. The `runtime` mode
|
|
84
|
+
preload uses the same URL. Relative or empty bases follow Vite's development normalization.
|
|
85
|
+
|
|
86
|
+
## Client types
|
|
87
|
+
Add the client type reference when TypeScript source files import Master CSS virtual manifest, emittedGlobals, or generated CSS modules:
|
|
88
|
+
|
|
89
|
+
```ts
|
|
90
|
+
/// <reference types="vite/client" />
|
|
91
|
+
/// <reference types="@master/css/client" />
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## Master CSS imports
|
|
95
|
+
|
|
96
|
+
In static mode, import the generated stylesheet from a source stylesheet.
|
|
97
|
+
|
|
98
|
+
```css
|
|
99
|
+
@import '@master/css';
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
Static mode is the default and does not inject the browser runtime. Source stylesheets that import `@master/css` receive generated Master CSS and the complete preset. Ordinary native CSS is preserved. Enable `pruneNativeCSS: true` only for intentional project pruning, or use `@prune native;` for one stylesheet. With pruning enabled, `@preserve native;` protects one stylesheet.
|
|
103
|
+
|
|
104
|
+
## Production CSS asset names
|
|
105
|
+
|
|
106
|
+
When Vite uses an `assetFileNames` pattern containing `[hash]`, managed CSS participates in the asset hash before Vite generates HTML and JavaScript references. Changing the managed stylesheet therefore changes its URL; identical inputs produce stable output names. This also applies to CSS loaded by dynamic imports and builds with `cssCodeSplit: false`.
|
|
107
|
+
|
|
108
|
+
Custom `assetFileNames` callbacks receive the CSS entry at the naming stage, including its content-sensitive import URL when managed output is delivered as separate assets. Hash length and `hashCharacters` settings are honored. Vite can still include its own naming metadata and perform later output processing, so the filename hash is not a checksum of the final file on disk. Fixed filename patterns remain fixed and require the application's own cache invalidation policy.
|
|
109
|
+
|
|
110
|
+
Production builds retain managed stylesheet imports as separate CSS assets. Local
|
|
111
|
+
and external imports keep their order, media/supports conditions and layer scopes;
|
|
112
|
+
ordinary rules before or after the managed entry keep their positions. Deploy the
|
|
113
|
+
complete output directory, including the generated `master-css-*` CSS and resource
|
|
114
|
+
files. Additional CSS files are placed beside Vite's CSS entry so ordinary relative
|
|
115
|
+
resource URLs retain their base. Managed and Node-resolved package resources receive
|
|
116
|
+
content-sensitive filenames and preserve query strings and fragments.
|
|
117
|
+
|
|
118
|
+
Node-resolved package CSS imports retain native rules when project CSS is pruned.
|
|
119
|
+
Production CSS import resolution uses Vite's resolver, including string and regular
|
|
120
|
+
expression aliases, package import conditions, and custom plugins that resolve to
|
|
121
|
+
CSS files on disk. This also discovers entry markers and definitions through
|
|
122
|
+
aliased imports. Null-prefixed virtual `.css` modules supplied by plugin loaders
|
|
123
|
+
can also provide managed entries or imported definitions. Their original CSS is
|
|
124
|
+
retained before transforms, and imports preserve their conditions and layers;
|
|
125
|
+
graph-only loaded modules do not create extra unconditional entries. Virtual ID
|
|
126
|
+
query suffixes retain distinct source identities. Virtual
|
|
127
|
+
resource ownership and alias resolution for `@reference`
|
|
128
|
+
or resource URLs still require further integration. Build watch and development
|
|
129
|
+
HMR for virtual sources need separate validation; physical development entries
|
|
130
|
+
use graph delivery as described below.
|
|
131
|
+
|
|
132
|
+
Vite production builds preprocess Sass entries and imports using the configured
|
|
133
|
+
Sass options, aliases and partial dependencies. String or function `additionalData`
|
|
134
|
+
runs once per source in each build. CSS imports left by Sass retain their conditions
|
|
135
|
+
and source order in the compiler graph. Relative partial resources keep their
|
|
136
|
+
original owner, and changing a partial triggers a rebuild. CSS Modules retain Vite's
|
|
137
|
+
scoped class names and exports; raw text requests bypass stylesheet compilation.
|
|
138
|
+
Managed `?inline` imports return compiled CSS without injecting a stylesheet:
|
|
139
|
+
|
|
140
|
+
```js
|
|
141
|
+
import css from './style.css?inline'
|
|
142
|
+
|
|
143
|
+
const style = document.createElement('style')
|
|
144
|
+
style.textContent = css
|
|
145
|
+
document.head.append(style)
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
Each inline request has its own stylesheet output, including when another file is
|
|
149
|
+
loaded automatically. Safe local imports are expanded; imports that protect CSS
|
|
150
|
+
scope or external loading remain linked assets. Import-free strings can also be
|
|
151
|
+
used with `CSSStyleSheet.replaceSync()`. Asset URLs retain the emitted asset base
|
|
152
|
+
when the string is inserted into another document location. Inline CSS content
|
|
153
|
+
participates in hashed JavaScript filenames.
|
|
154
|
+
|
|
155
|
+
During an SSR build, inline CSS uses the configured public `base` for asset URLs.
|
|
156
|
+
With Vite’s default `ssrEmitAssets: false`, deploy the matching client build’s
|
|
157
|
+
assets. Enable `ssrEmitAssets` when the server build should also publish them.
|
|
158
|
+
|
|
159
|
+
Inline asset URLs also use Vite’s `experimental.renderBuiltUrl` callback. The
|
|
160
|
+
callback receives `hostType: "js"` for inline strings and `hostType: "css"` for
|
|
161
|
+
retained stylesheet files. JavaScript URLs can use runtime expressions; stylesheet
|
|
162
|
+
files use static URLs or relative-path decisions. URL mapping changes participate
|
|
163
|
+
in retained stylesheet filenames as well as the importing JavaScript hash.
|
|
164
|
+
|
|
165
|
+
Production Sass compiler diagnostics use Vite's preprocessing maps to identify
|
|
166
|
+
the original file or partial, including inline requests and Sass imported by CSS.
|
|
167
|
+
Unchanged tokens retain their original ranges. Sass expansion can provide only
|
|
168
|
+
the originating segment; diagnostics explain when an exact token range is
|
|
169
|
+
unavailable. Injected content or an `additionalData` callback without a usable map
|
|
170
|
+
can retain a clearly identified preprocessed location. Internal diagnostic maps
|
|
171
|
+
do not enable published source maps.
|
|
172
|
+
|
|
173
|
+
Production CSS Modules, including Sass modules, retain Vite's scoped names,
|
|
174
|
+
named/default exports, cross-file `composes`, global selectors and
|
|
175
|
+
`localsConvention`. Exported scoped names participate in native CSS usage so
|
|
176
|
+
the default pruning policy keeps their rules.
|
|
177
|
+
|
|
178
|
+
Production build-watch tracks resolved CSS Modules `composes` dependencies,
|
|
179
|
+
including nested compositions. Editing a composed file rebuilds its consumers;
|
|
180
|
+
correcting an invalid Master CSS directive in that file recovers the build.
|
|
181
|
+
When Vite provides no original location for composed CSS, diagnostics explicitly
|
|
182
|
+
identify the preprocessed location.
|
|
183
|
+
|
|
184
|
+
Development CSS and Sass modules retain their scoped exports and native rules.
|
|
185
|
+
Editing the module or a resolved `composes` dependency updates both its CSS and
|
|
186
|
+
exports through HMR, including modules that use local `@apply`.
|
|
187
|
+
|
|
188
|
+
During development, editing a CSS project entry updates ordinary stylesheet
|
|
189
|
+
imports and its `?inline` and `?raw` consumers. Inline requests export processed
|
|
190
|
+
CSS without injecting a stylesheet; raw requests retain the original source.
|
|
191
|
+
Sass stylesheets attached through a `?url` value update in place during development,
|
|
192
|
+
including paths under a configured base, aliases, and allowed files outside the project root.
|
|
193
|
+
For CSS and Sass Modules, `?inline` exports the scoped CSS without injecting it,
|
|
194
|
+
while `?raw` retains the authored source. Vite 8.2.2 rejects `?url` for
|
|
195
|
+
`.module.css` and `.module.scss` paths, even with `css.modules: false`.
|
|
196
|
+
|
|
197
|
+
Ordinary Sass `@use` and nested `@forward` partials update their stylesheet
|
|
198
|
+
consumers during development, including `?inline` and attached `?url` values.
|
|
199
|
+
Deleting a partial reports the Sass error; restoring it recovers the stylesheet
|
|
200
|
+
without reloading the page. Relative resources keep the partial’s directory as
|
|
201
|
+
their source location.
|
|
202
|
+
Server-side `?inline` consumers also receive updated Sass output. After restarting
|
|
203
|
+
the Vite dev server, connected pages reload and reconnect; stylesheet requests
|
|
204
|
+
and subsequent edits use the new server state. This also works in middleware
|
|
205
|
+
mode when Vite’s WebSocket connection is attached to the host HTTP server.
|
|
206
|
+
Closing one configured development environment leaves stylesheet loading and
|
|
207
|
+
updates available in the remaining environments. An initialized replacement can
|
|
208
|
+
stay idle while the other environments close, then load styles when needed.
|
|
209
|
+
With per-environment start/end hooks enabled, existing Sass partials continue
|
|
210
|
+
updating as other environments start.
|
|
211
|
+
The plugin array can also be reused across concurrent Vite roots. Each resolved
|
|
212
|
+
configuration keeps its own stylesheet, manifest, and rendering state; restarting
|
|
213
|
+
or closing one development server leaves the others available. Client and SSR
|
|
214
|
+
builds retain their own configured asset bases.
|
|
215
|
+
|
|
216
|
+
Pre-render and progressive builds and development CSS entries support qualified
|
|
217
|
+
local imports whose descendants retain external imports. The browser applies the
|
|
218
|
+
original layer, supports, and media conditions to the delivered child stylesheets.
|
|
219
|
+
Development entries serve retained child CSS and resources under the configured
|
|
220
|
+
base. Loading an entry normally and through SSR `?inline` shares its source identity.
|
|
221
|
+
In pre-render mode, changing the project manifest reloads the page to refresh
|
|
222
|
+
server-rendered rules; progressive mode applies the update through its runtime.
|
|
223
|
+
Native-only CSS edits do not require a manifest reload.
|
|
224
|
+
Editing a retained development CSS child or an image resource updates connected
|
|
225
|
+
pages without reloading them. Resource filenames can include percent-encoded
|
|
226
|
+
spaces, Unicode, `#`, `?`, and `%`, while separate query strings and fragments
|
|
227
|
+
retain their meaning. Resources respect the original file's `server.fs.deny`.
|
|
228
|
+
Previously published CSS and resource URLs retain their contents until their
|
|
229
|
+
server context closes, including URLs held by SSR inline CSS consumers. Closing
|
|
230
|
+
another root that uses the same plugin array, or closing the SSR environment,
|
|
231
|
+
leaves the remaining client's resource delivery available. Retained versions use
|
|
232
|
+
server memory and temporary files until that context closes.
|
|
233
|
+
Each development resource version uses the same captured bytes for its URL and
|
|
234
|
+
published contents, even when the source is replaced or deleted before the CSS
|
|
235
|
+
is delivered. Deleting a referenced resource reports a development compilation
|
|
236
|
+
error while previously published versions remain readable. Restoring the resource
|
|
237
|
+
updates connected pages and dismisses the error overlay without reloading them.
|
|
238
|
+
An initialized replacement environment can remain idle while the old environment,
|
|
239
|
+
client, and SSR environments close, then load new retained graphs and receive
|
|
240
|
+
child stylesheet updates. This works with either value of
|
|
241
|
+
`server.perEnvironmentStartEndDuringDev`.
|
|
242
|
+
Restarting a standalone or middleware development server releases the previous
|
|
243
|
+
context's resource copies. Connected pages reload and reconnect to new asset URLs;
|
|
244
|
+
subsequent child CSS and image edits update without another page reload.
|
|
245
|
+
Local stylesheets compile imported local rules and retain qualified child imports
|
|
246
|
+
and resources in development and production builds. This also applies when the
|
|
247
|
+
root and intermediate stylesheets contain only native CSS, and `@apply` appears
|
|
248
|
+
only in an imported descendant. These graphs remain local stylesheets rather than
|
|
249
|
+
becoming project entries or native CSS pruning roots.
|
|
250
|
+
CSS Modules keep the root module's scoped exports; SSR inline requests return
|
|
251
|
+
compiled CSS, and raw requests retain the authored source. Child CSS and resource
|
|
252
|
+
edits update connected development pages; CSS Module consumers need the HMR
|
|
253
|
+
handling described below to retain page state. Production inline
|
|
254
|
+
strings publish their retained assets as well. Local entries keep their positions
|
|
255
|
+
within the built stylesheet, and content-based asset names are independent of
|
|
256
|
+
asynchronous entry registration order.
|
|
257
|
+
Local CSS and Sass imported through `?url` deliver their compiled stylesheet
|
|
258
|
+
and retained child assets. When that URL is attached as a stylesheet link,
|
|
259
|
+
editing a retained CSS child or its image updates the styles without reloading
|
|
260
|
+
the page, including when only an imported descendant contains `@apply`.
|
|
261
|
+
CSS Modules that import local CSS files expose the imported classes through the
|
|
262
|
+
root module's exports, with the same scope as its own classes. Imports retain their
|
|
263
|
+
conditions and layers, and relative resources keep their original file's directory.
|
|
264
|
+
Shared inputs retain each importing root's scope; identical CSS files in different
|
|
265
|
+
directories retain their own resource paths. This applies in development and builds.
|
|
266
|
+
Imported SCSS and indented Sass files also keep the root module's scope when
|
|
267
|
+
different source files compile to identical CSS. Each file retains its own resource
|
|
268
|
+
directory, and processing the import graph does not repeat its `additionalData`
|
|
269
|
+
callback. String values and callbacks that return source maps are supported.
|
|
270
|
+
Consumers must accept CSS Module updates, directly or through their framework's
|
|
271
|
+
HMR handling, to apply changed exported names without reloading the page.
|
|
272
|
+
Relative CSS `@reference` directives emitted from Sass partials resolve from the
|
|
273
|
+
mapped partial's directory, including through CSS Modules. Referenced definitions
|
|
274
|
+
retain their own image and font bases.
|
|
275
|
+
Stylesheet URLs emitted for CSS Modules also support direct CSS requests through
|
|
276
|
+
`?direct` or a CSS Accept header. They retain Vite's base and original-file access
|
|
277
|
+
policy, including allowed directories and denied files. A supplied map that cannot identify an
|
|
278
|
+
original filesystem source produces an error.
|
|
279
|
+
|
|
280
|
+
During development, local CSS and Sass variants retain their attempted CSS
|
|
281
|
+
reference dependencies after a compilation error. Creating a missing reference
|
|
282
|
+
retries its consumers; a failed initial page load reloads after compilation succeeds.
|
|
283
|
+
Deleting and restoring a reference after a successful load updates the stylesheet
|
|
284
|
+
through HMR. Once a local stylesheet removes a reference, later changes to that
|
|
285
|
+
reference no longer invalidate the stylesheet.
|
|
286
|
+
With default build-watch filters, creating a reference missing at startup retries
|
|
287
|
+
failed CSS and Sass compilations, including managed entries and pre-rendering.
|
|
288
|
+
Failed builds recheck dependency metadata and use an owned cache file to request
|
|
289
|
+
host rebuilds. Successful compilation stops these checks; closing the watcher
|
|
290
|
+
releases its recovery files. Custom watch filters that exclude the cache trigger
|
|
291
|
+
can still prevent recovery and require further integration.
|
|
292
|
+
Managed stylesheet entries also retain resource dependencies after a compilation
|
|
293
|
+
error. Manifest-loading errors remain visible until their dependencies are repaired.
|
|
294
|
+
Failed development transforms also recheck dependency metadata every 100 ms, so
|
|
295
|
+
changes missed while filesystem watches are being registered can recover. These
|
|
296
|
+
checks stop after successful compilation or environment closure and respect
|
|
297
|
+
Vite watch exclusions and disabled watching. Unchanged failures are not retried;
|
|
298
|
+
new compilation errors update the development error overlay.
|
|
299
|
+
|
|
300
|
+
Diagnostics for imported CSS and Sass use their original files and source maps,
|
|
301
|
+
including Sass partials and mapped `additionalData`. Imported Sass is preprocessed
|
|
302
|
+
once per prepared Module graph; temporary map data is removed before CSS delivery.
|
|
303
|
+
Interpolation can identify an originating segment without an exact token range.
|
|
304
|
+
When a callback changes source without supplying a map, diagnostics explicitly
|
|
305
|
+
identify a preprocessed location instead of inventing an original Sass position.
|
|
306
|
+
Root-relative public CSS URLs that already include Vite's `base` can fail during
|
|
307
|
+
Vite Modules preprocessing. Virtual sources and retained-graph Sass edge cases
|
|
308
|
+
still require further validation.
|
|
309
|
+
|
|
310
|
+
Missing CSS Modules composition recovery, other development request modes, other preprocessors
|
|
311
|
+
and user PostCSS transformations still require integration and validation.
|
|
312
|
+
|
|
313
|
+
For production graph delivery, an alias or custom resolver pointing to project
|
|
314
|
+
CSS follows the project's native CSS pruning policy. A bare-looking import name
|
|
315
|
+
alone does not make the file package CSS: the resolved file must belong to the
|
|
316
|
+
named package. Package export conditions may select another CSS file within that
|
|
317
|
+
package while retaining its native rules. `@preserve native;` explicitly keeps
|
|
318
|
+
project-native rules regardless of class usage.
|
|
319
|
+
|
|
320
|
+
In development, a missing or invalid project manifest keeps the server available to report the original error over HTTP. Fixing its watched CSS imports or references reloads the page, including failures before the first module request. Pre-rendering does not serve a previous manifest while the current one is invalid. Production builds still fail on manifest errors. Loaded manifest modules recover through Vite HMR and its existing acceptance boundaries. Closing an environment cancels its pending manifest recovery without discarding a renderer still used by another environment.
|
|
321
|
+
|
|
322
|
+
## Runtime input imports
|
|
323
|
+
|
|
324
|
+
The plugin exposes canonical project-level runtime input modules:
|
|
325
|
+
|
|
326
|
+
```ts
|
|
327
|
+
import manifest from 'virtual:master-css-manifest'
|
|
328
|
+
import program from 'virtual:master-css-program'
|
|
329
|
+
import emittedGlobals from 'virtual:master-css-emitted-globals'
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
Use these virtual modules when application code should receive the same manifest graph and emittedGlobals global CSS state that the plugin discovered from the project CSS entry. Browser code passes `program`, the manifest compiled for the browser engine, to `MasterCSSRuntime.start()`; browsers cannot execute manifests.
|
|
333
|
+
|
|
334
|
+
In production `runtime` mode, the plugin modulepreloads the runtime chunk and preloads the emitted runtime program with `<link rel="preload" as="fetch">` when it injects its private runtime bootstrap. In `progressive` mode, the bootstrap passes the program as a loader and adds no preloads, so a page whose classes are all pre-rendered loads neither the program nor the runtime engine. Applications that need manual startup should import `MasterCSSRuntime` from `@master/css-runtime` and use these virtual inputs; on progressive pages, pass `program: () => import('virtual:master-css-program').then(module => module.default)`. The bootstrap itself is intentionally not a public subpath.
|
|
335
|
+
|
|
336
|
+
## Options
|
|
337
|
+
|
|
338
|
+
Pass the `options` object to `masterCSS(options)`.
|
|
339
|
+
|
|
340
|
+
| Option | Type | Default | Description |
|
|
341
|
+
| --- | --- | --- | --- |
|
|
342
|
+
| `enabled` | `boolean` | `true` | Enables the integration. Use `false` to disable it. |
|
|
343
|
+
| `mode` | `'runtime' \| 'static' \| 'progressive' \| 'pre-render'` | `'static'` | Integration rendering mode. |
|
|
344
|
+
| `scanner` | `MasterCSSScannerConfiguration` | `{}` | Class usage scanning configuration. |
|
|
345
|
+
| `runtime` | `boolean \| { enabled?: boolean; avoidFOUC?: boolean }` | Mode-dependent | Enabled for runtime and progressive modes; disabled for static and pre-render modes. |
|
|
346
|
+
| `pruneNativeCSS` | `boolean` | `false` | Opt into pruning native CSS in project-owned sources. |
|
|
347
|
+
|
|
348
|
+
See the [Vite installation guide](https://rc.css.master.co/guide/installation/vite) for a full project setup.
|
package/dist/common.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
declare const HTML_ENTRIES: string[];
|
|
2
|
+
declare const VIRTUAL_MANIFEST_ID = "virtual:master-css-manifest";
|
|
3
|
+
declare const RESOLVED_VIRTUAL_MANIFEST_ID = "\0virtual:master-css-manifest";
|
|
4
|
+
declare const VIRTUAL_PROGRAM_ID = "virtual:master-css-program";
|
|
5
|
+
declare const RESOLVED_VIRTUAL_PROGRAM_ID = "\0virtual:master-css-program";
|
|
6
|
+
declare const VIRTUAL_EMITTED_GLOBALS_ID = "virtual:master-css-emitted-globals";
|
|
7
|
+
declare const RESOLVED_VIRTUAL_EMITTED_GLOBALS_ID = "\0virtual:master-css-emitted-globals";
|
|
8
|
+
declare const RUNTIME_ENTRY_ID = "virtual:master-css-runtime";
|
|
9
|
+
declare const DEV_RUNTIME_ENTRY_ID = "/@id/__x00__virtual:master-css-runtime";
|
|
10
|
+
declare const MASTER_CSS_MANIFEST_QUERY = "?master-css-manifest";
|
|
11
|
+
declare const RESOLVED_MASTER_CSS_MANIFEST_QUERY_PREFIX = "\0master-css-manifest:";
|
|
12
|
+
declare const MASTER_CSS_PROGRAM_QUERY = "?master-css-program";
|
|
13
|
+
declare const RESOLVED_MASTER_CSS_PROGRAM_QUERY_PREFIX = "\0master-css-program:";
|
|
14
|
+
export { DEV_RUNTIME_ENTRY_ID, HTML_ENTRIES, MASTER_CSS_MANIFEST_QUERY, MASTER_CSS_PROGRAM_QUERY, RESOLVED_MASTER_CSS_MANIFEST_QUERY_PREFIX, RESOLVED_MASTER_CSS_PROGRAM_QUERY_PREFIX, RESOLVED_VIRTUAL_EMITTED_GLOBALS_ID, RESOLVED_VIRTUAL_MANIFEST_ID, RESOLVED_VIRTUAL_PROGRAM_ID, RUNTIME_ENTRY_ID, VIRTUAL_EMITTED_GLOBALS_ID, VIRTUAL_MANIFEST_ID, VIRTUAL_PROGRAM_ID };
|
package/dist/common.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { MASTER_CSS_MANIFEST_QUERY as MASTER_CSS_MANIFEST_QUERY$1, RESOLVED_VIRTUAL_MANIFEST_ID as RESOLVED_VIRTUAL_MANIFEST_ID$1, VIRTUAL_MANIFEST_ID as VIRTUAL_MANIFEST_ID$1 } from "./internal/src/manifest-module.js";
|
|
2
|
+
import { MASTER_CSS_PROGRAM_QUERY as MASTER_CSS_PROGRAM_QUERY$1, RESOLVED_VIRTUAL_PROGRAM_ID as RESOLVED_VIRTUAL_PROGRAM_ID$1, VIRTUAL_PROGRAM_ID as VIRTUAL_PROGRAM_ID$1 } from "./internal/src/program-module.js";
|
|
3
|
+
import { VIRTUAL_EMITTED_GLOBALS_ID as VIRTUAL_EMITTED_GLOBALS_ID$1 } from "./internal/src/emitted-globals-module.js";
|
|
4
|
+
import { RESOLVED_MASTER_CSS_MANIFEST_QUERY_PREFIX as RESOLVED_MASTER_CSS_MANIFEST_QUERY_PREFIX$1, RESOLVED_MASTER_CSS_PROGRAM_QUERY_PREFIX as RESOLVED_MASTER_CSS_PROGRAM_QUERY_PREFIX$1 } from "./internal/src/node.js";
|
|
5
|
+
import { MASTER_CSS_RUNTIME_BOOTSTRAP_ID } from "./internal/src/runtime-bootstrap.js";
|
|
6
|
+
// src/common.ts
|
|
7
|
+
const HTML_ENTRIES = [
|
|
8
|
+
"src/layouts/Layout.astro",
|
|
9
|
+
"src/app.html",
|
|
10
|
+
"src/index.html",
|
|
11
|
+
"app.html",
|
|
12
|
+
"index.html"
|
|
13
|
+
];
|
|
14
|
+
const VIRTUAL_MANIFEST_ID = VIRTUAL_MANIFEST_ID$1;
|
|
15
|
+
const RESOLVED_VIRTUAL_MANIFEST_ID = RESOLVED_VIRTUAL_MANIFEST_ID$1;
|
|
16
|
+
const VIRTUAL_PROGRAM_ID = VIRTUAL_PROGRAM_ID$1;
|
|
17
|
+
const RESOLVED_VIRTUAL_PROGRAM_ID = RESOLVED_VIRTUAL_PROGRAM_ID$1;
|
|
18
|
+
const VIRTUAL_EMITTED_GLOBALS_ID = VIRTUAL_EMITTED_GLOBALS_ID$1;
|
|
19
|
+
const RESOLVED_VIRTUAL_EMITTED_GLOBALS_ID = `\0${VIRTUAL_EMITTED_GLOBALS_ID}`;
|
|
20
|
+
const RUNTIME_ENTRY_ID = MASTER_CSS_RUNTIME_BOOTSTRAP_ID;
|
|
21
|
+
const DEV_RUNTIME_ENTRY_ID = `/@id/__x00__${RUNTIME_ENTRY_ID}`;
|
|
22
|
+
const MASTER_CSS_MANIFEST_QUERY = MASTER_CSS_MANIFEST_QUERY$1;
|
|
23
|
+
const RESOLVED_MASTER_CSS_MANIFEST_QUERY_PREFIX = RESOLVED_MASTER_CSS_MANIFEST_QUERY_PREFIX$1;
|
|
24
|
+
const MASTER_CSS_PROGRAM_QUERY = MASTER_CSS_PROGRAM_QUERY$1;
|
|
25
|
+
const RESOLVED_MASTER_CSS_PROGRAM_QUERY_PREFIX = RESOLVED_MASTER_CSS_PROGRAM_QUERY_PREFIX$1;
|
|
26
|
+
export { DEV_RUNTIME_ENTRY_ID, HTML_ENTRIES, MASTER_CSS_MANIFEST_QUERY, MASTER_CSS_PROGRAM_QUERY, RESOLVED_MASTER_CSS_MANIFEST_QUERY_PREFIX, RESOLVED_MASTER_CSS_PROGRAM_QUERY_PREFIX, RESOLVED_VIRTUAL_EMITTED_GLOBALS_ID, RESOLVED_VIRTUAL_MANIFEST_ID, RESOLVED_VIRTUAL_PROGRAM_ID, RUNTIME_ENTRY_ID, VIRTUAL_EMITTED_GLOBALS_ID, VIRTUAL_MANIFEST_ID, VIRTUAL_PROGRAM_ID };
|
package/dist/core.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Plugin, ResolvedConfig } from "vite";
|
|
2
|
+
import { MasterCSSScanner } from "@master/css-tooling/scanner/node";
|
|
3
|
+
import { MasterCSSStylesheetCollection } from "@master/css-compiler/stylesheet";
|
|
4
|
+
import { MasterCSSEmittedGlobals } from "@master/css-schema/emitted-globals";
|
|
5
|
+
import { MasterCSSVitePluginOptions } from "./options.js";
|
|
6
|
+
interface MasterCSSVitePluginContext {
|
|
7
|
+
config?: ResolvedConfig;
|
|
8
|
+
scanner?: MasterCSSScanner;
|
|
9
|
+
virtualCSSImporters?: Set<string>;
|
|
10
|
+
virtualCSSPlaceholderEmitted?: boolean;
|
|
11
|
+
stylesheets?: MasterCSSStylesheetCollection;
|
|
12
|
+
pruneNativeCSS?: boolean;
|
|
13
|
+
includeGeneratedCSS?: boolean;
|
|
14
|
+
emittedGlobals?: MasterCSSEmittedGlobals;
|
|
15
|
+
onEmittedGlobalsChange?: () => void;
|
|
16
|
+
refreshEmittedGlobals?: () => Promise<void>;
|
|
17
|
+
defaultManifestAssetReferenceId?: string;
|
|
18
|
+
defaultManifestAssetSource?: string;
|
|
19
|
+
defaultProgramAssetReferenceId?: string;
|
|
20
|
+
defaultProgramAssetSource?: Uint8Array;
|
|
21
|
+
}
|
|
22
|
+
declare function createMasterCSSVitePlugin(specifiedOptions?: MasterCSSVitePluginOptions): Plugin[];
|
|
23
|
+
export { MasterCSSVitePluginContext, createMasterCSSVitePlugin, createMasterCSSVitePlugin as default };
|
package/dist/core.js
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import ManifestLoaderPlugin from "./plugins/manifest-loader.js";
|
|
2
|
+
import ManifestVirtualModulePlugin from "./plugins/manifest-virtual-module.js";
|
|
3
|
+
import EmittedGlobalsVirtualModulePlugin from "./plugins/emitted-globals-virtual-module.js";
|
|
4
|
+
import ContextPlugin from "./plugins/context.js";
|
|
5
|
+
import ScannerPlugin from "./plugins/scanner.js";
|
|
6
|
+
import UsageGraphPlugin from "./plugins/usage-graph.js";
|
|
7
|
+
import LocalStylesPlugin from "./plugins/local-styles.js";
|
|
8
|
+
import StylesheetRecoveryPlugin from "./plugins/stylesheet-recovery.js";
|
|
9
|
+
import BuildStylesheetRecoveryPlugin from "./plugins/build-stylesheet-recovery.js";
|
|
10
|
+
import SassSourcePlugin from "./plugins/sass-source.js";
|
|
11
|
+
import InlineStylesheetPlugin from "./plugins/inline-stylesheet.js";
|
|
12
|
+
import StyleEntryPlugin from "./plugins/style-entry.js";
|
|
13
|
+
import StyleEntryHMRPlugin from "./plugins/style-entry-hmr.js";
|
|
14
|
+
import StyleEntryBuildPlugin from "./plugins/style-entry-build.js";
|
|
15
|
+
import RuntimeBootstrapPlugin from "./plugins/runtime-bootstrap.js";
|
|
16
|
+
import DevStylesheetPlugin from "./plugins/dev-stylesheet.js";
|
|
17
|
+
import { scopePlugins } from "./utils/scoped-plugins.js";
|
|
18
|
+
import { resolveMasterCSSVitePluginOptions } from "./options.js";
|
|
19
|
+
// src/core.ts
|
|
20
|
+
function createMasterCSSVitePlugin(specifiedOptions = {}) {
|
|
21
|
+
const options = resolveMasterCSSVitePluginOptions(specifiedOptions);
|
|
22
|
+
if (!options.enabled) return [];
|
|
23
|
+
const emittedGlobalsAPI = {};
|
|
24
|
+
return scopePlugins(() => createPlugins(options, emittedGlobalsAPI));
|
|
25
|
+
}
|
|
26
|
+
function createPlugins(options, emittedGlobalsAPI) {
|
|
27
|
+
const runtimeBootstrap = RuntimeBootstrapPlugin(options.mode === "progressive");
|
|
28
|
+
const context = {
|
|
29
|
+
pruneNativeCSS: options.pruneNativeCSS,
|
|
30
|
+
includeGeneratedCSS: options.mode === "static"
|
|
31
|
+
};
|
|
32
|
+
const plugins = [
|
|
33
|
+
runtimeBootstrap,
|
|
34
|
+
ContextPlugin(options, context),
|
|
35
|
+
ManifestVirtualModulePlugin(context),
|
|
36
|
+
EmittedGlobalsVirtualModulePlugin(context, emittedGlobalsAPI),
|
|
37
|
+
ManifestLoaderPlugin(context),
|
|
38
|
+
ScannerPlugin(options, context),
|
|
39
|
+
UsageGraphPlugin(options, context),
|
|
40
|
+
StylesheetRecoveryPlugin(context),
|
|
41
|
+
BuildStylesheetRecoveryPlugin(context),
|
|
42
|
+
SassSourcePlugin(context),
|
|
43
|
+
LocalStylesPlugin(options, context),
|
|
44
|
+
StyleEntryPlugin(options, context),
|
|
45
|
+
StyleEntryHMRPlugin(options, context),
|
|
46
|
+
InlineStylesheetPlugin(context),
|
|
47
|
+
DevStylesheetPlugin(context),
|
|
48
|
+
StyleEntryBuildPlugin(options, context)
|
|
49
|
+
];
|
|
50
|
+
switch (options.mode) {
|
|
51
|
+
case "runtime":
|
|
52
|
+
if (options.injectRuntime) {
|
|
53
|
+
plugins.push(...InjectRuntimePlugins(options));
|
|
54
|
+
plugins.push(RuntimePreloadPlugin(context));
|
|
55
|
+
plugins.push(ProgramPreloadPlugin(context));
|
|
56
|
+
}
|
|
57
|
+
if (options.avoidFOUC) plugins.push(AvoidFOUCPlugin(options, context));
|
|
58
|
+
break;
|
|
59
|
+
case "static": break;
|
|
60
|
+
case "progressive":
|
|
61
|
+
plugins.push(PreRenderPlugin(options, context));
|
|
62
|
+
if (options.injectRuntime) plugins.push(...InjectRuntimePlugins(options));
|
|
63
|
+
break;
|
|
64
|
+
case "pre-render": plugins.push(PreRenderPlugin(options, context));
|
|
65
|
+
}
|
|
66
|
+
return plugins;
|
|
67
|
+
}
|
|
68
|
+
function InjectRuntimePlugins(options) {
|
|
69
|
+
return [createLazyPlugin({
|
|
70
|
+
name: "master-css:inject-runtime",
|
|
71
|
+
enforce: "pre",
|
|
72
|
+
apply: "build"
|
|
73
|
+
}, async () => (await import("./plugins/inject-runtime.js")).default(options), [{
|
|
74
|
+
name: "transformIndexHtml",
|
|
75
|
+
order: "pre"
|
|
76
|
+
}]), createLazyPlugin({
|
|
77
|
+
name: "master-css:inject-runtime:serve",
|
|
78
|
+
apply: "serve"
|
|
79
|
+
}, async () => (await import("./plugins/inject-runtime.js")).InjectRuntimeServePlugin(options), [{
|
|
80
|
+
name: "transformIndexHtml",
|
|
81
|
+
order: "post"
|
|
82
|
+
}])];
|
|
83
|
+
}
|
|
84
|
+
function ProgramPreloadPlugin(context) {
|
|
85
|
+
return createLazyPlugin({
|
|
86
|
+
name: "master-css:program-preload",
|
|
87
|
+
apply: "build"
|
|
88
|
+
}, async () => (await import("./plugins/program-preload.js")).default(context), [{
|
|
89
|
+
name: "transformIndexHtml",
|
|
90
|
+
order: "post"
|
|
91
|
+
}]);
|
|
92
|
+
}
|
|
93
|
+
function RuntimePreloadPlugin(context) {
|
|
94
|
+
return createLazyPlugin({ name: "master-css:runtime-preload" }, async () => (await import("./plugins/runtime-preload.js")).default(context), [{
|
|
95
|
+
name: "transformIndexHtml",
|
|
96
|
+
order: "post"
|
|
97
|
+
}]);
|
|
98
|
+
}
|
|
99
|
+
function AvoidFOUCPlugin(options, context) {
|
|
100
|
+
return createLazyPlugin({
|
|
101
|
+
name: "master-css:avoid-fouc",
|
|
102
|
+
enforce: "pre"
|
|
103
|
+
}, async () => (await import("./plugins/avoid-fouc.js")).default(options, context), ["transformIndexHtml", "transform"]);
|
|
104
|
+
}
|
|
105
|
+
function PreRenderPlugin(options, context) {
|
|
106
|
+
return createLazyPlugin({
|
|
107
|
+
name: "master-css:pre-render",
|
|
108
|
+
enforce: "pre"
|
|
109
|
+
}, async () => (await import("./plugins/pre-render.js")).default(options, context), [
|
|
110
|
+
"configResolved",
|
|
111
|
+
"buildStart",
|
|
112
|
+
"buildEnd",
|
|
113
|
+
"closeBundle",
|
|
114
|
+
"closeWatcher",
|
|
115
|
+
"handleHotUpdate",
|
|
116
|
+
"configureServer",
|
|
117
|
+
"transformIndexHtml",
|
|
118
|
+
"transform",
|
|
119
|
+
{
|
|
120
|
+
name: "generateBundle",
|
|
121
|
+
order: "post"
|
|
122
|
+
}
|
|
123
|
+
]);
|
|
124
|
+
}
|
|
125
|
+
function createLazyPlugin(shell, loadPlugin, hooks) {
|
|
126
|
+
let loadedPlugin;
|
|
127
|
+
let pluginPromise;
|
|
128
|
+
const load = () => {
|
|
129
|
+
if (loadedPlugin) return Promise.resolve(loadedPlugin);
|
|
130
|
+
pluginPromise ||= loadPlugin().then((plugin) => {
|
|
131
|
+
loadedPlugin = plugin;
|
|
132
|
+
return plugin;
|
|
133
|
+
});
|
|
134
|
+
return pluginPromise;
|
|
135
|
+
};
|
|
136
|
+
const call = (hookName, thisArg, args) => {
|
|
137
|
+
if (loadedPlugin) return callLazyPluginHook(loadedPlugin, hookName, thisArg, args);
|
|
138
|
+
return load().then((plugin) => callLazyPluginHook(plugin, hookName, thisArg, args));
|
|
139
|
+
};
|
|
140
|
+
const plugin = { ...shell };
|
|
141
|
+
for (const hook of hooks) {
|
|
142
|
+
if (typeof hook === "object") {
|
|
143
|
+
plugin[hook.name] = {
|
|
144
|
+
order: hook.order,
|
|
145
|
+
handler(...args) {
|
|
146
|
+
return call(hook.name, this, args);
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
151
|
+
plugin[hook] = function lazyPluginHook(...args) {
|
|
152
|
+
return call(hook, this, args);
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
return plugin;
|
|
156
|
+
}
|
|
157
|
+
function callLazyPluginHook(plugin, hookName, thisArg, args) {
|
|
158
|
+
const hook = plugin[hookName];
|
|
159
|
+
if (typeof hook === "function") return hook.apply(thisArg, args);
|
|
160
|
+
if (isHookObject(hook) && typeof hook.handler === "function") return hook.handler.apply(thisArg, args);
|
|
161
|
+
}
|
|
162
|
+
function isHookObject(value) {
|
|
163
|
+
return !!value && typeof value === "object";
|
|
164
|
+
}
|
|
165
|
+
export { createMasterCSSVitePlugin, createMasterCSSVitePlugin as default };
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { createMasterCSSVitePlugin, createMasterCSSVitePlugin as default } from "./core.js";
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// ../internal/src/emitted-globals-module.ts
|
|
2
|
+
const VIRTUAL_EMITTED_GLOBALS_ID = "virtual:master-css-emitted-globals";
|
|
3
|
+
function normalizeEmittedGlobals(emittedGlobals = {}) {
|
|
4
|
+
return {
|
|
5
|
+
variables: emittedGlobals.variables || {},
|
|
6
|
+
keyframes: emittedGlobals.keyframes || {}
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
function toEmittedGlobalsModule(emittedGlobals) {
|
|
10
|
+
return `export default ${JSON.stringify(normalizeEmittedGlobals(emittedGlobals))};`;
|
|
11
|
+
}
|
|
12
|
+
export { VIRTUAL_EMITTED_GLOBALS_ID, normalizeEmittedGlobals, toEmittedGlobalsModule };
|