@pithyjs/vite-plugin 0.1.0-beta.0
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/LICENSE +21 -0
- package/README.md +237 -0
- package/dist/aotCodegen/generateBindings.d.ts +184 -0
- package/dist/aotCodegen/generateBindings.d.ts.map +1 -0
- package/dist/aotCodegen/generateBindings.js +326 -0
- package/dist/aotCodegen/generateBindings.js.map +1 -0
- package/dist/aotCodegen/generateDomFactory.d.ts +59 -0
- package/dist/aotCodegen/generateDomFactory.d.ts.map +1 -0
- package/dist/aotCodegen/generateDomFactory.js +302 -0
- package/dist/aotCodegen/generateDomFactory.js.map +1 -0
- package/dist/aotCodegen/index.d.ts +18 -0
- package/dist/aotCodegen/index.d.ts.map +1 -0
- package/dist/aotCodegen/index.js +17 -0
- package/dist/aotCodegen/index.js.map +1 -0
- package/dist/aotCodegen/serializeNode.d.ts +74 -0
- package/dist/aotCodegen/serializeNode.d.ts.map +1 -0
- package/dist/aotCodegen/serializeNode.js +169 -0
- package/dist/aotCodegen/serializeNode.js.map +1 -0
- package/dist/aotCodegen/structuralCodegen.d.ts +38 -0
- package/dist/aotCodegen/structuralCodegen.d.ts.map +1 -0
- package/dist/aotCodegen/structuralCodegen.js +56 -0
- package/dist/aotCodegen/structuralCodegen.js.map +1 -0
- package/dist/aotCodegen/utils.d.ts +38 -0
- package/dist/aotCodegen/utils.d.ts.map +1 -0
- package/dist/aotCodegen/utils.js +48 -0
- package/dist/aotCodegen/utils.js.map +1 -0
- package/dist/babelPlugin/babelPlugin.d.ts +44 -0
- package/dist/babelPlugin/babelPlugin.d.ts.map +1 -0
- package/dist/babelPlugin/babelPlugin.js +392 -0
- package/dist/babelPlugin/babelPlugin.js.map +1 -0
- package/dist/babelPlugin/extractOriginalTagNames.d.ts +20 -0
- package/dist/babelPlugin/extractOriginalTagNames.d.ts.map +1 -0
- package/dist/babelPlugin/extractOriginalTagNames.js +44 -0
- package/dist/babelPlugin/extractOriginalTagNames.js.map +1 -0
- package/dist/babelPlugin/extractUsedIdentifiers.d.ts +26 -0
- package/dist/babelPlugin/extractUsedIdentifiers.d.ts.map +1 -0
- package/dist/babelPlugin/extractUsedIdentifiers.js +206 -0
- package/dist/babelPlugin/extractUsedIdentifiers.js.map +1 -0
- package/dist/buildPlugin/plugin.d.ts +79 -0
- package/dist/buildPlugin/plugin.d.ts.map +1 -0
- package/dist/buildPlugin/plugin.js +142 -0
- package/dist/buildPlugin/plugin.js.map +1 -0
- package/dist/designSystemPlugin/collector.d.ts +63 -0
- package/dist/designSystemPlugin/collector.d.ts.map +1 -0
- package/dist/designSystemPlugin/collector.js +175 -0
- package/dist/designSystemPlugin/collector.js.map +1 -0
- package/dist/designSystemPlugin/cssTokens.d.ts +34 -0
- package/dist/designSystemPlugin/cssTokens.d.ts.map +1 -0
- package/dist/designSystemPlugin/cssTokens.js +56 -0
- package/dist/designSystemPlugin/cssTokens.js.map +1 -0
- package/dist/designSystemPlugin/enumerate.d.ts +24 -0
- package/dist/designSystemPlugin/enumerate.d.ts.map +1 -0
- package/dist/designSystemPlugin/enumerate.js +430 -0
- package/dist/designSystemPlugin/enumerate.js.map +1 -0
- package/dist/designSystemPlugin/extractor.d.ts +95 -0
- package/dist/designSystemPlugin/extractor.d.ts.map +1 -0
- package/dist/designSystemPlugin/extractor.js +150 -0
- package/dist/designSystemPlugin/extractor.js.map +1 -0
- package/dist/designSystemPlugin/generator.d.ts +33 -0
- package/dist/designSystemPlugin/generator.d.ts.map +1 -0
- package/dist/designSystemPlugin/generator.js +256 -0
- package/dist/designSystemPlugin/generator.js.map +1 -0
- package/dist/designSystemPlugin/index.d.ts +18 -0
- package/dist/designSystemPlugin/index.d.ts.map +1 -0
- package/dist/designSystemPlugin/index.js +19 -0
- package/dist/designSystemPlugin/index.js.map +1 -0
- package/dist/designSystemPlugin/patterns/a11y.d.ts +19 -0
- package/dist/designSystemPlugin/patterns/a11y.d.ts.map +1 -0
- package/dist/designSystemPlugin/patterns/a11y.js +230 -0
- package/dist/designSystemPlugin/patterns/a11y.js.map +1 -0
- package/dist/designSystemPlugin/patterns/borders.d.ts +18 -0
- package/dist/designSystemPlugin/patterns/borders.d.ts.map +1 -0
- package/dist/designSystemPlugin/patterns/borders.js +474 -0
- package/dist/designSystemPlugin/patterns/borders.js.map +1 -0
- package/dist/designSystemPlugin/patterns/colors.d.ts +18 -0
- package/dist/designSystemPlugin/patterns/colors.d.ts.map +1 -0
- package/dist/designSystemPlugin/patterns/colors.js +134 -0
- package/dist/designSystemPlugin/patterns/colors.js.map +1 -0
- package/dist/designSystemPlugin/patterns/iconography.d.ts +18 -0
- package/dist/designSystemPlugin/patterns/iconography.d.ts.map +1 -0
- package/dist/designSystemPlugin/patterns/iconography.js +61 -0
- package/dist/designSystemPlugin/patterns/iconography.js.map +1 -0
- package/dist/designSystemPlugin/patterns/index.d.ts +22 -0
- package/dist/designSystemPlugin/patterns/index.d.ts.map +1 -0
- package/dist/designSystemPlugin/patterns/index.js +44 -0
- package/dist/designSystemPlugin/patterns/index.js.map +1 -0
- package/dist/designSystemPlugin/patterns/layout.d.ts +34 -0
- package/dist/designSystemPlugin/patterns/layout.d.ts.map +1 -0
- package/dist/designSystemPlugin/patterns/layout.js +917 -0
- package/dist/designSystemPlugin/patterns/layout.js.map +1 -0
- package/dist/designSystemPlugin/patterns/motion.d.ts +19 -0
- package/dist/designSystemPlugin/patterns/motion.d.ts.map +1 -0
- package/dist/designSystemPlugin/patterns/motion.js +162 -0
- package/dist/designSystemPlugin/patterns/motion.js.map +1 -0
- package/dist/designSystemPlugin/patterns/radius.d.ts +18 -0
- package/dist/designSystemPlugin/patterns/radius.d.ts.map +1 -0
- package/dist/designSystemPlugin/patterns/radius.js +107 -0
- package/dist/designSystemPlugin/patterns/radius.js.map +1 -0
- package/dist/designSystemPlugin/patterns/shadows.d.ts +19 -0
- package/dist/designSystemPlugin/patterns/shadows.d.ts.map +1 -0
- package/dist/designSystemPlugin/patterns/shadows.js +161 -0
- package/dist/designSystemPlugin/patterns/shadows.js.map +1 -0
- package/dist/designSystemPlugin/patterns/smartContainer.d.ts +18 -0
- package/dist/designSystemPlugin/patterns/smartContainer.d.ts.map +1 -0
- package/dist/designSystemPlugin/patterns/smartContainer.js +96 -0
- package/dist/designSystemPlugin/patterns/smartContainer.js.map +1 -0
- package/dist/designSystemPlugin/patterns/spacing.d.ts +18 -0
- package/dist/designSystemPlugin/patterns/spacing.d.ts.map +1 -0
- package/dist/designSystemPlugin/patterns/spacing.js +333 -0
- package/dist/designSystemPlugin/patterns/spacing.js.map +1 -0
- package/dist/designSystemPlugin/patterns/typography.d.ts +18 -0
- package/dist/designSystemPlugin/patterns/typography.d.ts.map +1 -0
- package/dist/designSystemPlugin/patterns/typography.js +416 -0
- package/dist/designSystemPlugin/patterns/typography.js.map +1 -0
- package/dist/designSystemPlugin/plugin.d.ts +39 -0
- package/dist/designSystemPlugin/plugin.d.ts.map +1 -0
- package/dist/designSystemPlugin/plugin.js +351 -0
- package/dist/designSystemPlugin/plugin.js.map +1 -0
- package/dist/designSystemPlugin/types.d.ts +156 -0
- package/dist/designSystemPlugin/types.d.ts.map +1 -0
- package/dist/designSystemPlugin/types.js +49 -0
- package/dist/designSystemPlugin/types.js.map +1 -0
- package/dist/htmlTransform/htmlTransform.d.ts +47 -0
- package/dist/htmlTransform/htmlTransform.d.ts.map +1 -0
- package/dist/htmlTransform/htmlTransform.js +86 -0
- package/dist/htmlTransform/htmlTransform.js.map +1 -0
- package/dist/iconsPlugin/index.d.ts +18 -0
- package/dist/iconsPlugin/index.d.ts.map +1 -0
- package/dist/iconsPlugin/index.js +17 -0
- package/dist/iconsPlugin/index.js.map +1 -0
- package/dist/iconsPlugin/optimize.d.ts +54 -0
- package/dist/iconsPlugin/optimize.d.ts.map +1 -0
- package/dist/iconsPlugin/optimize.js +253 -0
- package/dist/iconsPlugin/optimize.js.map +1 -0
- package/dist/iconsPlugin/plugin.d.ts +49 -0
- package/dist/iconsPlugin/plugin.d.ts.map +1 -0
- package/dist/iconsPlugin/plugin.js +242 -0
- package/dist/iconsPlugin/plugin.js.map +1 -0
- package/dist/iconsPlugin/types.d.ts +49 -0
- package/dist/iconsPlugin/types.d.ts.map +1 -0
- package/dist/iconsPlugin/types.js +30 -0
- package/dist/iconsPlugin/types.js.map +1 -0
- package/dist/index.d.ts +31 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +37 -0
- package/dist/index.js.map +1 -0
- package/dist/pithyPlugin/plugin.d.ts +38 -0
- package/dist/pithyPlugin/plugin.d.ts.map +1 -0
- package/dist/pithyPlugin/plugin.js +119 -0
- package/dist/pithyPlugin/plugin.js.map +1 -0
- package/dist/routerPlugin/manifest.d.ts +33 -0
- package/dist/routerPlugin/manifest.d.ts.map +1 -0
- package/dist/routerPlugin/manifest.js +223 -0
- package/dist/routerPlugin/manifest.js.map +1 -0
- package/dist/routerPlugin/plugin.d.ts +51 -0
- package/dist/routerPlugin/plugin.d.ts.map +1 -0
- package/dist/routerPlugin/plugin.js +164 -0
- package/dist/routerPlugin/plugin.js.map +1 -0
- package/dist/routerPlugin/scanner.d.ts +69 -0
- package/dist/routerPlugin/scanner.d.ts.map +1 -0
- package/dist/routerPlugin/scanner.js +290 -0
- package/dist/routerPlugin/scanner.js.map +1 -0
- package/dist/ssrPlugin/plugin.d.ts +76 -0
- package/dist/ssrPlugin/plugin.d.ts.map +1 -0
- package/dist/ssrPlugin/plugin.js +439 -0
- package/dist/ssrPlugin/plugin.js.map +1 -0
- package/package.json +57 -0
|
@@ -0,0 +1,351 @@
|
|
|
1
|
+
/** @codex
|
|
2
|
+
{
|
|
3
|
+
"id": "pithy.vite-plugin-design-system",
|
|
4
|
+
"title": "Vite Plugin for Design System CSS Tree-Shaking",
|
|
5
|
+
"category": "plugin",
|
|
6
|
+
"description": "CSS tree-shaking plugin that extracts used utility classes from source files and generates only the CSS needed.",
|
|
7
|
+
"since": "0.0.1",
|
|
8
|
+
"stability": "experimental",
|
|
9
|
+
"testing": {
|
|
10
|
+
"unit": { "required": false, "covered": false },
|
|
11
|
+
"integration": { "required": true, "covered": true, "file": "integration.test.ts" },
|
|
12
|
+
"e2e": { "required": false, "covered": false }
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
*/
|
|
16
|
+
import { readFileSync, readdirSync, statSync } from 'fs';
|
|
17
|
+
import { join, dirname } from 'path';
|
|
18
|
+
import { createCollector } from './collector';
|
|
19
|
+
import { generateCSS } from './generator';
|
|
20
|
+
import { enumerateAllUtilities } from './enumerate';
|
|
21
|
+
import { VIRTUAL_MODULE_ID, RESOLVED_VIRTUAL_MODULE_ID, resolveOptions, } from './types';
|
|
22
|
+
/**
|
|
23
|
+
* Format byte count to human-readable string
|
|
24
|
+
*/
|
|
25
|
+
function formatBytes(bytes) {
|
|
26
|
+
if (bytes < 1024)
|
|
27
|
+
return `${bytes} B`;
|
|
28
|
+
const kb = bytes / 1024;
|
|
29
|
+
return `${kb.toFixed(1)} KB`;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Check if a file path matches the include/exclude patterns
|
|
33
|
+
*/
|
|
34
|
+
function shouldProcessFile(filePath, include, exclude) {
|
|
35
|
+
// Simple pattern matching - could use micromatch for more robust matching
|
|
36
|
+
const normalizedPath = filePath.replace(/\\/g, '/');
|
|
37
|
+
// Check excludes first
|
|
38
|
+
for (const pattern of exclude) {
|
|
39
|
+
if (matchPattern(normalizedPath, pattern)) {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
// Check includes
|
|
44
|
+
for (const pattern of include) {
|
|
45
|
+
if (matchPattern(normalizedPath, pattern)) {
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Simple glob pattern matching
|
|
53
|
+
*
|
|
54
|
+
* Converts glob patterns to regex:
|
|
55
|
+
* `**\/` → zero or more directory segments (including none)
|
|
56
|
+
* `*` → any characters within a single path segment
|
|
57
|
+
*
|
|
58
|
+
* The pattern is tested both anchored and with an arbitrary prefix
|
|
59
|
+
* so that `src/**\/*.ts` matches both `src/main.ts` and
|
|
60
|
+
* `/project/src/pages/App.ts`.
|
|
61
|
+
*/
|
|
62
|
+
function matchPattern(path, pattern) {
|
|
63
|
+
// Convert glob pattern to regex
|
|
64
|
+
const regexPattern = pattern
|
|
65
|
+
.replace(/\./g, '\\.')
|
|
66
|
+
.replace(/\*\*\//g, '{{GLOBSTAR_SLASH}}')
|
|
67
|
+
.replace(/\*\*/g, '{{GLOBSTAR}}')
|
|
68
|
+
.replace(/\*/g, '[^/]*')
|
|
69
|
+
.replace(/{{GLOBSTAR_SLASH}}/g, '(.*/)?')
|
|
70
|
+
.replace(/{{GLOBSTAR}}/g, '.*');
|
|
71
|
+
const regex = new RegExp(`^${regexPattern}$|^.*/${regexPattern}$`);
|
|
72
|
+
return regex.test(path);
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Vite plugin for Pithy Design System CSS tree-shaking
|
|
76
|
+
*
|
|
77
|
+
* Extracts used utility classes from source files and generates
|
|
78
|
+
* only the CSS needed for those utilities.
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* // vite.config.ts
|
|
82
|
+
* import { designSystemPlugin } from '@pithyjs/vite-plugin';
|
|
83
|
+
*
|
|
84
|
+
* export default defineConfig({
|
|
85
|
+
* plugins: [
|
|
86
|
+
* designSystemPlugin({
|
|
87
|
+
* safelist: ['u-bg-success', /^u-text-/],
|
|
88
|
+
* debug: true,
|
|
89
|
+
* })
|
|
90
|
+
* ]
|
|
91
|
+
* });
|
|
92
|
+
*/
|
|
93
|
+
/** @codexApi {"parent":"pithy.vite-plugin-design-system","name":"designSystemPlugin","stability":"experimental","signature":"(options?: DesignSystemPluginOptions) => Plugin"} */
|
|
94
|
+
export function designSystemPlugin(options = {}) {
|
|
95
|
+
const resolvedOptions = resolveOptions(options);
|
|
96
|
+
const { include, exclude, debug, devMode } = resolvedOptions;
|
|
97
|
+
let config;
|
|
98
|
+
let devServer = null;
|
|
99
|
+
let collector;
|
|
100
|
+
let cachedCSS = null;
|
|
101
|
+
let lastHash = '';
|
|
102
|
+
let fullCSSBytes = null;
|
|
103
|
+
/**
|
|
104
|
+
* Log debug messages if debug mode is enabled
|
|
105
|
+
*/
|
|
106
|
+
function log(...args) {
|
|
107
|
+
if (debug) {
|
|
108
|
+
console.log('[pithy-design-system]', ...args);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Resolve the @pithyjs/ui-kit source directory from Vite aliases.
|
|
113
|
+
* Returns the absolute path if found, undefined otherwise.
|
|
114
|
+
*
|
|
115
|
+
* The alias replacement may point to a file (e.g. `.../src/index.ts`)
|
|
116
|
+
* rather than a directory. In that case we normalize to the containing
|
|
117
|
+
* directory so that `walk()` can enumerate the source tree.
|
|
118
|
+
*/
|
|
119
|
+
function resolveUiKitDir() {
|
|
120
|
+
const aliases = config.resolve?.alias;
|
|
121
|
+
if (!aliases)
|
|
122
|
+
return undefined;
|
|
123
|
+
// Vite normalizes aliases to an array of { find, replacement }
|
|
124
|
+
if (Array.isArray(aliases)) {
|
|
125
|
+
for (const alias of aliases) {
|
|
126
|
+
const find = typeof alias.find === 'string' ? alias.find : alias.find?.source;
|
|
127
|
+
if (find === '@pithyjs/ui-kit' && alias.replacement) {
|
|
128
|
+
return normalizeToDir(alias.replacement);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return undefined;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Ensure a path points to a directory. If the path is a file, return
|
|
136
|
+
* its parent directory. Returns undefined if the path doesn't exist.
|
|
137
|
+
*/
|
|
138
|
+
function normalizeToDir(p) {
|
|
139
|
+
try {
|
|
140
|
+
const stat = statSync(p);
|
|
141
|
+
if (stat.isDirectory())
|
|
142
|
+
return p;
|
|
143
|
+
// It's a file — use the parent directory
|
|
144
|
+
return dirname(p);
|
|
145
|
+
}
|
|
146
|
+
catch {
|
|
147
|
+
return undefined;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Pre-scan source files on disk to populate the collector.
|
|
152
|
+
* Called during buildStart so the virtual CSS module has all
|
|
153
|
+
* utilities available on first load — no timing dependency.
|
|
154
|
+
*
|
|
155
|
+
* Also scans @pithyjs/ui-kit source (via Vite alias) since ui-kit
|
|
156
|
+
* components build utility class names dynamically from maps that
|
|
157
|
+
* the standard app-root walk would miss.
|
|
158
|
+
*/
|
|
159
|
+
function scanSourceFiles() {
|
|
160
|
+
const files = [];
|
|
161
|
+
function walk(dir) {
|
|
162
|
+
let entries;
|
|
163
|
+
try {
|
|
164
|
+
entries = readdirSync(dir, { withFileTypes: true });
|
|
165
|
+
}
|
|
166
|
+
catch {
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
for (const entry of entries) {
|
|
170
|
+
const fullPath = join(dir, entry.name);
|
|
171
|
+
if (entry.isDirectory()) {
|
|
172
|
+
if (entry.name === 'node_modules' ||
|
|
173
|
+
entry.name === '.git' ||
|
|
174
|
+
entry.name === 'dist')
|
|
175
|
+
continue;
|
|
176
|
+
walk(fullPath);
|
|
177
|
+
}
|
|
178
|
+
else if (entry.isFile() &&
|
|
179
|
+
shouldProcessFile(fullPath, include, exclude)) {
|
|
180
|
+
files.push(fullPath);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
// Scan app source files
|
|
185
|
+
walk(config.root);
|
|
186
|
+
// Scan @pithyjs/ui-kit source for dynamic utility class maps
|
|
187
|
+
const uiKitDir = resolveUiKitDir();
|
|
188
|
+
if (uiKitDir) {
|
|
189
|
+
walk(uiKitDir);
|
|
190
|
+
log(`Also scanning ui-kit source: ${uiKitDir}`);
|
|
191
|
+
}
|
|
192
|
+
for (const file of files) {
|
|
193
|
+
try {
|
|
194
|
+
const content = readFileSync(file, 'utf-8');
|
|
195
|
+
collector.updateFile(file, content);
|
|
196
|
+
}
|
|
197
|
+
catch {
|
|
198
|
+
// Skip unreadable files
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
log(`Pre-scanned ${files.length} files, found ${collector.getAllUtilities().size} utilities`);
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Invalidate the virtual CSS module and send an HMR update.
|
|
205
|
+
* Used for incremental updates during dev (file edits, additions, deletions).
|
|
206
|
+
*/
|
|
207
|
+
function sendHMRUpdate() {
|
|
208
|
+
if (!devServer)
|
|
209
|
+
return;
|
|
210
|
+
const module = devServer.moduleGraph.getModuleById(RESOLVED_VIRTUAL_MODULE_ID);
|
|
211
|
+
if (module) {
|
|
212
|
+
devServer.moduleGraph.invalidateModule(module);
|
|
213
|
+
const updatePath = module.url || VIRTUAL_MODULE_ID;
|
|
214
|
+
devServer.ws.send({
|
|
215
|
+
type: 'update',
|
|
216
|
+
updates: [
|
|
217
|
+
{
|
|
218
|
+
type: 'css-update',
|
|
219
|
+
path: updatePath,
|
|
220
|
+
acceptedPath: updatePath,
|
|
221
|
+
timestamp: Date.now(),
|
|
222
|
+
},
|
|
223
|
+
],
|
|
224
|
+
});
|
|
225
|
+
log('HMR update sent for changed utilities');
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Generate CSS from collected utilities
|
|
230
|
+
*/
|
|
231
|
+
function generateAndCacheCSS() {
|
|
232
|
+
const utilities = collector.getAllUtilities();
|
|
233
|
+
const currentHash = collector.getHash();
|
|
234
|
+
// Return cached CSS if nothing changed
|
|
235
|
+
if (cachedCSS && currentHash === lastHash) {
|
|
236
|
+
log('Using cached CSS');
|
|
237
|
+
return cachedCSS;
|
|
238
|
+
}
|
|
239
|
+
log(`Generating CSS for ${utilities.size} utilities...`);
|
|
240
|
+
const isJitMode = resolvedOptions.jit || (config.command === 'serve' && devMode === 'jit');
|
|
241
|
+
if (isJitMode) {
|
|
242
|
+
const result = generateCSS(utilities, resolvedOptions);
|
|
243
|
+
cachedCSS = result.css;
|
|
244
|
+
if (debug) {
|
|
245
|
+
const { stats } = result;
|
|
246
|
+
log(`Generated: ${stats.matched} matched, ${stats.unknown} unknown`, Object.entries(stats.byCategory)
|
|
247
|
+
.map(([cat, n]) => `${cat}:${n}`)
|
|
248
|
+
.join(', '));
|
|
249
|
+
// Compute full CSS size once for comparison
|
|
250
|
+
if (fullCSSBytes === null) {
|
|
251
|
+
const allUtils = enumerateAllUtilities();
|
|
252
|
+
const fullResult = generateCSS(allUtils, resolvedOptions);
|
|
253
|
+
fullCSSBytes = fullResult.stats.cssBytes;
|
|
254
|
+
}
|
|
255
|
+
const pct = fullCSSBytes > 0
|
|
256
|
+
? ((1 - stats.cssBytes / fullCSSBytes) * 100).toFixed(1)
|
|
257
|
+
: '0';
|
|
258
|
+
log(`CSS size: ${formatBytes(stats.cssBytes)} (tree-shaken) / ${formatBytes(fullCSSBytes)} (full) — ${pct}% smaller`);
|
|
259
|
+
if (result.unknown.size > 0) {
|
|
260
|
+
log('Unknown utilities:', [...result.unknown].slice(0, 10));
|
|
261
|
+
if (result.unknown.size > 10) {
|
|
262
|
+
log(` ... and ${result.unknown.size - 10} more`);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
else {
|
|
268
|
+
// Full mode - include all utilities
|
|
269
|
+
const allUtils = enumerateAllUtilities();
|
|
270
|
+
const result = generateCSS(allUtils, resolvedOptions);
|
|
271
|
+
cachedCSS = result.css;
|
|
272
|
+
}
|
|
273
|
+
lastHash = currentHash;
|
|
274
|
+
return cachedCSS;
|
|
275
|
+
}
|
|
276
|
+
return {
|
|
277
|
+
name: 'pithy-design-system',
|
|
278
|
+
configResolved(resolvedConfig) {
|
|
279
|
+
config = resolvedConfig;
|
|
280
|
+
// Initialize collector — pass all enumerated utilities so regex
|
|
281
|
+
// safelist entries (e.g. /^u-text-/) can be expanded correctly.
|
|
282
|
+
collector = createCollector({
|
|
283
|
+
safelist: resolvedOptions.safelist,
|
|
284
|
+
allPossibleUtilities: enumerateAllUtilities(),
|
|
285
|
+
});
|
|
286
|
+
log('Plugin initialized');
|
|
287
|
+
log('Include patterns:', include);
|
|
288
|
+
log('Exclude patterns:', exclude);
|
|
289
|
+
log('JIT mode:', resolvedOptions.jit);
|
|
290
|
+
log('Dev mode:', devMode);
|
|
291
|
+
},
|
|
292
|
+
resolveId(id) {
|
|
293
|
+
if (id === VIRTUAL_MODULE_ID) {
|
|
294
|
+
return RESOLVED_VIRTUAL_MODULE_ID;
|
|
295
|
+
}
|
|
296
|
+
return null;
|
|
297
|
+
},
|
|
298
|
+
load(id) {
|
|
299
|
+
if (id === RESOLVED_VIRTUAL_MODULE_ID) {
|
|
300
|
+
return generateAndCacheCSS();
|
|
301
|
+
}
|
|
302
|
+
return null;
|
|
303
|
+
},
|
|
304
|
+
transform(code, id) {
|
|
305
|
+
// Skip if collector not yet initialized or file doesn't match
|
|
306
|
+
if (!collector || !shouldProcessFile(id, include, exclude)) {
|
|
307
|
+
return null;
|
|
308
|
+
}
|
|
309
|
+
// Extract utilities from the file
|
|
310
|
+
const diff = collector.updateFile(id, code);
|
|
311
|
+
if (diff.hasChanges) {
|
|
312
|
+
// Invalidate cached CSS
|
|
313
|
+
cachedCSS = null;
|
|
314
|
+
if (debug) {
|
|
315
|
+
if (diff.added.size > 0) {
|
|
316
|
+
log(`[${id}] Added:`, [...diff.added]);
|
|
317
|
+
}
|
|
318
|
+
if (diff.removed.size > 0) {
|
|
319
|
+
log(`[${id}] Removed:`, [...diff.removed]);
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
// Trigger HMR so the virtual CSS module reloads
|
|
323
|
+
sendHMRUpdate();
|
|
324
|
+
}
|
|
325
|
+
// Don't transform the code, just extract utilities
|
|
326
|
+
return null;
|
|
327
|
+
},
|
|
328
|
+
configureServer(srv) {
|
|
329
|
+
devServer = srv;
|
|
330
|
+
srv.watcher.on('unlink', filePath => {
|
|
331
|
+
if (!shouldProcessFile(filePath, include, exclude)) {
|
|
332
|
+
return;
|
|
333
|
+
}
|
|
334
|
+
log(`File removed: ${filePath}`);
|
|
335
|
+
collector.removeFile(filePath);
|
|
336
|
+
cachedCSS = null;
|
|
337
|
+
sendHMRUpdate();
|
|
338
|
+
});
|
|
339
|
+
},
|
|
340
|
+
buildStart() {
|
|
341
|
+
collector.clear();
|
|
342
|
+
cachedCSS = null;
|
|
343
|
+
lastHash = '';
|
|
344
|
+
// Pre-scan source files so the collector is populated
|
|
345
|
+
// before the virtual CSS module is first loaded
|
|
346
|
+
scanSourceFiles();
|
|
347
|
+
log('Build started - collector ready');
|
|
348
|
+
},
|
|
349
|
+
};
|
|
350
|
+
}
|
|
351
|
+
//# sourceMappingURL=plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../../src/designSystemPlugin/plugin.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;EAcE;AAGF,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,IAAI,CAAC;AACzD,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AACrC,OAAO,EAAE,eAAe,EAAkB,MAAM,aAAa,CAAC;AAC9D,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EACL,iBAAiB,EACjB,0BAA0B,EAC1B,cAAc,GAEf,MAAM,SAAS,CAAC;AAEjB;;GAEG;AACH,SAAS,WAAW,CAAC,KAAa;IAChC,IAAI,KAAK,GAAG,IAAI;QAAE,OAAO,GAAG,KAAK,IAAI,CAAC;IACtC,MAAM,EAAE,GAAG,KAAK,GAAG,IAAI,CAAC;IACxB,OAAO,GAAG,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC;AA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,EAAE,QAAQ,CAAC,EAAE;gBAClC,IAAI,CAAC,iBAAiB,CAAC,QAAQ,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,CAAC;oBACnD,OAAO;gBACT,CAAC;gBAED,GAAG,CAAC,iBAAiB,QAAQ,EAAE,CAAC,CAAC;gBACjC,SAAS,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;gBAC/B,SAAS,GAAG,IAAI,CAAC;gBAEjB,aAAa,EAAE,CAAC;YAClB,CAAC,CAAC,CAAC;QACL,CAAC;QAED,UAAU;YACR,SAAS,CAAC,KAAK,EAAE,CAAC;YAClB,SAAS,GAAG,IAAI,CAAC;YACjB,QAAQ,GAAG,EAAE,CAAC;YAEd,sDAAsD;YACtD,gDAAgD;YAChD,eAAe,EAAE,CAAC;YAElB,GAAG,CAAC,iCAAiC,CAAC,CAAC;QACzC,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
/** @codex
|
|
2
|
+
{
|
|
3
|
+
"id": "pithy.vite-plugin-design-system.types",
|
|
4
|
+
"title": "Design System Plugin Types",
|
|
5
|
+
"category": "types",
|
|
6
|
+
"description": "TypeScript interfaces and types for the design system CSS tree-shaking plugin.",
|
|
7
|
+
"since": "0.0.1",
|
|
8
|
+
"stability": "experimental",
|
|
9
|
+
"testing": {
|
|
10
|
+
"unit": { "required": false, "covered": false },
|
|
11
|
+
"integration": { "required": false, "covered": false },
|
|
12
|
+
"e2e": { "required": false, "covered": false }
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* Configuration options for the design system tree-shaking plugin
|
|
18
|
+
*/
|
|
19
|
+
export interface DesignSystemPluginOptions {
|
|
20
|
+
/**
|
|
21
|
+
* Enable JIT (Just-In-Time) mode that only includes used utilities
|
|
22
|
+
* @default true in production, false in development
|
|
23
|
+
*/
|
|
24
|
+
jit?: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Development mode behavior
|
|
27
|
+
* - 'full': Include all utilities (faster builds, larger CSS)
|
|
28
|
+
* - 'jit': Only include used utilities (slower builds, smaller CSS)
|
|
29
|
+
* @default 'full'
|
|
30
|
+
*/
|
|
31
|
+
devMode?: 'full' | 'jit';
|
|
32
|
+
/**
|
|
33
|
+
* Classes to always include regardless of usage detection
|
|
34
|
+
* Supports strings and RegExp patterns
|
|
35
|
+
*/
|
|
36
|
+
safelist?: Array<string | RegExp>;
|
|
37
|
+
/**
|
|
38
|
+
* File patterns to scan for utility classes
|
|
39
|
+
* @default ['src/**\/*.ts', 'src/**\/*.tsx', 'src/**\/*.pithy']
|
|
40
|
+
*/
|
|
41
|
+
include?: string[];
|
|
42
|
+
/**
|
|
43
|
+
* File patterns to exclude from scanning
|
|
44
|
+
* @default ['**\/*.test.ts', '**\/*.spec.ts', 'node_modules/**']
|
|
45
|
+
*/
|
|
46
|
+
exclude?: string[];
|
|
47
|
+
/**
|
|
48
|
+
* Enable debug logging
|
|
49
|
+
* @default false
|
|
50
|
+
*/
|
|
51
|
+
debug?: boolean;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Resolved plugin options with all defaults applied
|
|
55
|
+
*/
|
|
56
|
+
export interface ResolvedPluginOptions {
|
|
57
|
+
jit: boolean;
|
|
58
|
+
devMode: 'full' | 'jit';
|
|
59
|
+
safelist: Array<string | RegExp>;
|
|
60
|
+
include: string[];
|
|
61
|
+
exclude: string[];
|
|
62
|
+
debug: boolean;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Result of parsing a utility class with variant
|
|
66
|
+
*/
|
|
67
|
+
export interface ParsedUtility {
|
|
68
|
+
/** The full class name as written (e.g., 'hover:u-bg-primary') */
|
|
69
|
+
full: string;
|
|
70
|
+
/** The variant prefix if any (e.g., 'hover', 'dark') */
|
|
71
|
+
variant: string | null;
|
|
72
|
+
/** The base utility without variant (e.g., 'u-bg-primary') */
|
|
73
|
+
utility: string;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Definition for a utility pattern that can generate CSS
|
|
77
|
+
*/
|
|
78
|
+
export interface UtilityPattern {
|
|
79
|
+
/** Pattern name for debugging */
|
|
80
|
+
name: string;
|
|
81
|
+
/** Category for grouping in output */
|
|
82
|
+
category: UtilityCategory;
|
|
83
|
+
/** Regular expression to match utility class names */
|
|
84
|
+
pattern: RegExp;
|
|
85
|
+
/** Generate CSS for a matched utility class */
|
|
86
|
+
generate: (className: string, match: RegExpMatchArray) => string | null;
|
|
87
|
+
/**
|
|
88
|
+
* Mark as externally provided (e.g. by SCSS).
|
|
89
|
+
* When true, the utility is recognized as valid but no CSS is generated
|
|
90
|
+
* (CSS is already provided by another source like compiled SCSS).
|
|
91
|
+
*/
|
|
92
|
+
external?: boolean;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Categories of utilities for organization (10 categories)
|
|
96
|
+
*/
|
|
97
|
+
export type UtilityCategory = 'colors' | 'spacing' | 'borders' | 'typography' | 'layout' | 'a11y' | 'radius' | 'shadows' | 'motion' | 'iconography';
|
|
98
|
+
/**
|
|
99
|
+
* Result of CSS generation
|
|
100
|
+
*/
|
|
101
|
+
export interface GenerationResult {
|
|
102
|
+
/** Generated CSS string */
|
|
103
|
+
css: string;
|
|
104
|
+
/** Utilities that were successfully matched */
|
|
105
|
+
matched: Set<string>;
|
|
106
|
+
/** Utilities that couldn't be matched to any pattern */
|
|
107
|
+
unknown: Set<string>;
|
|
108
|
+
/** Stats for debugging */
|
|
109
|
+
stats: GenerationStats;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Statistics from CSS generation
|
|
113
|
+
*/
|
|
114
|
+
export interface GenerationStats {
|
|
115
|
+
total: number;
|
|
116
|
+
matched: number;
|
|
117
|
+
unknown: number;
|
|
118
|
+
byCategory: Partial<Record<UtilityCategory, number>>;
|
|
119
|
+
/** Generated CSS size in bytes */
|
|
120
|
+
cssBytes: number;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Collector state tracking utility usage per file
|
|
124
|
+
*/
|
|
125
|
+
export interface CollectorState {
|
|
126
|
+
/** Map of file path to Set of utilities used in that file */
|
|
127
|
+
fileUtilities: Map<string, Set<string>>;
|
|
128
|
+
/** All unique utilities collected across all files */
|
|
129
|
+
allUtilities: Set<string>;
|
|
130
|
+
/** Utilities from safelist */
|
|
131
|
+
safelistedUtilities: Set<string>;
|
|
132
|
+
/** Hash of current state for cache invalidation */
|
|
133
|
+
hash: string;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Diff result when utilities change
|
|
137
|
+
*/
|
|
138
|
+
export interface UtilityDiff {
|
|
139
|
+
added: Set<string>;
|
|
140
|
+
removed: Set<string>;
|
|
141
|
+
hasChanges: boolean;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Virtual module ID for the generated CSS
|
|
145
|
+
*/
|
|
146
|
+
export declare const VIRTUAL_MODULE_ID = "virtual:pithy-design-system";
|
|
147
|
+
/**
|
|
148
|
+
* Resolved virtual module ID (with null byte prefix per Vite convention)
|
|
149
|
+
* The .css suffix tells Vite to process this through its CSS pipeline
|
|
150
|
+
*/
|
|
151
|
+
export declare const RESOLVED_VIRTUAL_MODULE_ID = "\0virtual:pithy-design-system.css";
|
|
152
|
+
/**
|
|
153
|
+
* Resolve user options with defaults
|
|
154
|
+
*/
|
|
155
|
+
export declare function resolveOptions(options?: DesignSystemPluginOptions): ResolvedPluginOptions;
|
|
156
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/designSystemPlugin/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;EAcE;AAEF;;GAEG;AACH,MAAM,WAAW,yBAAyB;IACxC;;;OAGG;IACH,GAAG,CAAC,EAAE,OAAO,CAAC;IAEd;;;;;OAKG;IACH,OAAO,CAAC,EAAE,MAAM,GAA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|
|
2
|
+
{
|
|
3
|
+
"id": "pithy.vite-plugin-design-system.types",
|
|
4
|
+
"title": "Design System Plugin Types",
|
|
5
|
+
"category": "types",
|
|
6
|
+
"description": "TypeScript interfaces and types for the design system CSS tree-shaking plugin.",
|
|
7
|
+
"since": "0.0.1",
|
|
8
|
+
"stability": "experimental",
|
|
9
|
+
"testing": {
|
|
10
|
+
"unit": { "required": false, "covered": false },
|
|
11
|
+
"integration": { "required": false, "covered": false },
|
|
12
|
+
"e2e": { "required": false, "covered": false }
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* Virtual module ID for the generated CSS
|
|
18
|
+
*/
|
|
19
|
+
export const VIRTUAL_MODULE_ID = 'virtual:pithy-design-system';
|
|
20
|
+
/**
|
|
21
|
+
* Resolved virtual module ID (with null byte prefix per Vite convention)
|
|
22
|
+
* The .css suffix tells Vite to process this through its CSS pipeline
|
|
23
|
+
*/
|
|
24
|
+
export const RESOLVED_VIRTUAL_MODULE_ID = '\0virtual:pithy-design-system.css';
|
|
25
|
+
/**
|
|
26
|
+
* Default plugin options
|
|
27
|
+
*/
|
|
28
|
+
const DEFAULT_OPTIONS = {
|
|
29
|
+
jit: process.env.NODE_ENV === 'production',
|
|
30
|
+
devMode: 'full',
|
|
31
|
+
safelist: [],
|
|
32
|
+
include: ['src/**/*.ts', 'src/**/*.tsx', 'src/**/*.pithy'],
|
|
33
|
+
exclude: ['**/*.test.ts', '**/*.spec.ts', 'node_modules/**'],
|
|
34
|
+
debug: false,
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Resolve user options with defaults
|
|
38
|
+
*/
|
|
39
|
+
export function resolveOptions(options = {}) {
|
|
40
|
+
return {
|
|
41
|
+
...DEFAULT_OPTIONS,
|
|
42
|
+
...options,
|
|
43
|
+
// Ensure arrays are not undefined
|
|
44
|
+
safelist: options.safelist ?? DEFAULT_OPTIONS.safelist,
|
|
45
|
+
include: options.include ?? DEFAULT_OPTIONS.include,
|
|
46
|
+
exclude: options.exclude ?? DEFAULT_OPTIONS.exclude,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/designSystemPlugin/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;EAcE;AAyJF;;GAEG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,6BAA6B,CAAC;AAE/D;;;GAGG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAG,mCAAmC,CAAC;AAE9E;;GAEG;AACH,MAAM,eAAe,GAA0B;IAC7C,GAAG,EAAE,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY;IAC1C,OAAO,EAAE,MAAM;IACf,QAAQ,EAAE,EAAE;IACZ,OAAO,EAAE,CAAC,aAAa,EAAE,cAAc,EAAE,gBAAgB,CAAC;IAC1D,OAAO,EAAE,CAAC,cAAc,EAAE,cAAc,EAAE,iBAAiB,CAAC;IAC5D,KAAK,EAAE,KAAK;CACb,CAAC;AAEF;;GAEG;AACH,MAAM,UAAU,cAAc,CAC5B,UAAqC,EAAE;IAEvC,OAAO;QACL,GAAG,eAAe;QAClB,GAAG,OAAO;QACV,kCAAkC;QAClC,QAAQ,EAAE,OAAO,CAAC,QAAQ,IAAI,eAAe,CAAC,QAAQ;QACtD,OAAO,EAAE,OAAO,CAAC,OAAO,IAAI,eAAe,CAAC,OAAO;QACnD,OAAO,EAAE,OAAO,CAAC,OAAO,IAAI,eAAe,CAAC,OAAO;KACpD,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/** @codex
|
|
2
|
+
{
|
|
3
|
+
"id": "pithy.vite.html-transform-plugin",
|
|
4
|
+
"title": "HTML Transform Vite Plugin",
|
|
5
|
+
"category": "plugin",
|
|
6
|
+
"description": "Babel-based Vite plugin that transforms html`…` tagged template literals, with optional AOT compilation to eliminate runtime HTML parsing.",
|
|
7
|
+
"since": "0.0.1",
|
|
8
|
+
"stability": "stable",
|
|
9
|
+
"testing": {
|
|
10
|
+
"unit": { "required": true, "covered": true, "file": "htmlTransformAot.test.ts" },
|
|
11
|
+
"integration": { "required": true, "covered": false },
|
|
12
|
+
"e2e": { "required": false, "covered": false }
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
*/
|
|
16
|
+
import type { PluginOption } from 'vite';
|
|
17
|
+
import type { ComponentScopesMap } from '../babelPlugin/extractUsedIdentifiers';
|
|
18
|
+
/** @codexApi {"parent":"pithy.vite.html-transform-plugin","name":"HtmlTransformPluginOptions","stability":"stable","signature":"interface HtmlTransformPluginOptions"} */
|
|
19
|
+
export interface HtmlTransformPluginOptions {
|
|
20
|
+
/** Map of component names to variables they inject into children's scope */
|
|
21
|
+
componentScopes?: ComponentScopesMap;
|
|
22
|
+
/** Enable AOT template compilation. Default: true in build mode, false in dev. */
|
|
23
|
+
aot?: boolean;
|
|
24
|
+
/** Fail the build if any template falls back to JIT (uses ${expr} syntax). Default: false. */
|
|
25
|
+
strictAot?: boolean;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Vite plugin that transforms `html\`\`` tagged templates using Babel.
|
|
29
|
+
*
|
|
30
|
+
* In build mode, templates are AOT-compiled to eliminate runtime HTML parsing.
|
|
31
|
+
* In dev mode, templates are left as-is for faster HMR unless `aot` is explicitly enabled.
|
|
32
|
+
*
|
|
33
|
+
* @param options - Plugin configuration for AOT mode, strict AOT, and component scopes
|
|
34
|
+
* @returns A Vite plugin that transforms html tagged templates
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```ts
|
|
38
|
+
* import { htmlTransformPlugin } from '@pithyjs/vite-plugin';
|
|
39
|
+
*
|
|
40
|
+
* export default defineConfig({
|
|
41
|
+
* plugins: [htmlTransformPlugin({ aot: true })],
|
|
42
|
+
* });
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
/** @codexApi {"parent":"pithy.vite.html-transform-plugin","name":"htmlTransformPlugin","stability":"stable","signature":"(options?: HtmlTransformPluginOptions) => PluginOption"} */
|
|
46
|
+
export declare function htmlTransformPlugin(options?: HtmlTransformPluginOptions): PluginOption;
|
|
47
|
+
//# sourceMappingURL=htmlTransform.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"htmlTransform.d.ts","sourceRoot":"","sources":["../../src/htmlTransform/htmlTransform.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;EAcE;AAEF,OAAO,KAAK,EAAE,YAAY,EAAkB,MAAM,MAAM,CAAC;AAIzD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,uCAAuC,CAAC;AAGhF,0KAA0K;AAC1K,MAAM,WAAW,0BAA0B;IACzC,4EAA4E;IAC5E,eAAe,CAAC,EAAE,kBAAkB,CAAC;IACrC,kFAAkF;IAClF,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,8FAA8F;IAC9F,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,qLAAqL;AACrL,wBAAgB,mBAAmB,CACjC,OAAO,CAAC,EAAE,0BAA0B,GACnC,YAAY,CAyDd"}
|