@vertesia/plugin-builder 0.24.0-dev.202601221707
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 +13 -0
- package/README.md +119 -0
- package/lib/index.d.ts +18 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +63 -0
- package/lib/index.js.map +1 -0
- package/lib/parse-css.d.ts +2 -0
- package/lib/parse-css.d.ts.map +1 -0
- package/lib/parse-css.js +20 -0
- package/lib/parse-css.js.map +1 -0
- package/package.json +44 -0
- package/src/index.ts +74 -0
- package/src/parse-css.ts +21 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
Copyright 2024 Composable
|
|
2
|
+
|
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License.
|
|
5
|
+
You may obtain a copy of the License at
|
|
6
|
+
|
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
|
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
See the License for the specific language governing permissions and
|
|
13
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
# @vertesia/plugin-builder
|
|
2
|
+
|
|
3
|
+
A Vite plugin for building Vertesia UI plugins with CSS handling and Tailwind utilities extraction.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- Seamless integration with Vite build process
|
|
8
|
+
- Automatic CSS file generation for plugins
|
|
9
|
+
- Tailwind CSS utilities layer extraction
|
|
10
|
+
- Optional inline CSS as JavaScript export
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
npm install @vertesia/plugin-builder --save-dev
|
|
16
|
+
# or
|
|
17
|
+
pnpm add -D @vertesia/plugin-builder
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Usage
|
|
21
|
+
|
|
22
|
+
Add the plugin to your `vite.config.ts`:
|
|
23
|
+
|
|
24
|
+
```typescript
|
|
25
|
+
import { defineConfig } from 'vite';
|
|
26
|
+
import { vertesiaPluginBuilder } from '@vertesia/plugin-builder';
|
|
27
|
+
|
|
28
|
+
export default defineConfig({
|
|
29
|
+
plugins: [
|
|
30
|
+
vertesiaPluginBuilder()
|
|
31
|
+
]
|
|
32
|
+
});
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Configuration Options
|
|
36
|
+
|
|
37
|
+
```typescript
|
|
38
|
+
interface VertesiaPluginBuilderOptions {
|
|
39
|
+
// Inline CSS as a JavaScript export variable
|
|
40
|
+
inlineCss?: boolean;
|
|
41
|
+
|
|
42
|
+
// Name of the exported CSS variable (default: 'css')
|
|
43
|
+
cssVar?: string;
|
|
44
|
+
|
|
45
|
+
// Input CSS file path (default: 'src/index.css')
|
|
46
|
+
input?: string;
|
|
47
|
+
|
|
48
|
+
// Output CSS file name (default: 'plugin.css')
|
|
49
|
+
output?: string;
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Examples
|
|
54
|
+
|
|
55
|
+
### Basic Usage
|
|
56
|
+
|
|
57
|
+
```typescript
|
|
58
|
+
import { vertesiaPluginBuilder } from '@vertesia/plugin-builder';
|
|
59
|
+
|
|
60
|
+
export default defineConfig({
|
|
61
|
+
plugins: [
|
|
62
|
+
vertesiaPluginBuilder()
|
|
63
|
+
]
|
|
64
|
+
});
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### With Inline CSS Export
|
|
68
|
+
|
|
69
|
+
When `inlineCss` is enabled, the plugin extracts Tailwind utilities and exports them as a JavaScript variable:
|
|
70
|
+
|
|
71
|
+
```typescript
|
|
72
|
+
import { vertesiaPluginBuilder } from '@vertesia/plugin-builder';
|
|
73
|
+
|
|
74
|
+
export default defineConfig({
|
|
75
|
+
plugins: [
|
|
76
|
+
vertesiaPluginBuilder({
|
|
77
|
+
inlineCss: true,
|
|
78
|
+
cssVar: 'pluginStyles'
|
|
79
|
+
})
|
|
80
|
+
]
|
|
81
|
+
});
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
This allows you to import the CSS directly in your JavaScript:
|
|
85
|
+
|
|
86
|
+
```typescript
|
|
87
|
+
import { pluginStyles } from './plugin.js';
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### Custom Input/Output
|
|
91
|
+
|
|
92
|
+
```typescript
|
|
93
|
+
import { vertesiaPluginBuilder } from '@vertesia/plugin-builder';
|
|
94
|
+
|
|
95
|
+
export default defineConfig({
|
|
96
|
+
plugins: [
|
|
97
|
+
vertesiaPluginBuilder({
|
|
98
|
+
input: 'styles/main.css',
|
|
99
|
+
output: 'my-plugin.css'
|
|
100
|
+
})
|
|
101
|
+
]
|
|
102
|
+
});
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
## How It Works
|
|
106
|
+
|
|
107
|
+
1. The plugin creates a virtual entry module that imports your CSS file
|
|
108
|
+
2. During the build process, Vite processes the CSS through its pipeline (including Tailwind if configured)
|
|
109
|
+
3. The processed CSS is output to the specified file
|
|
110
|
+
4. If `inlineCss` is enabled, the Tailwind utilities layer is extracted and appended to the JavaScript bundle as an exported variable
|
|
111
|
+
|
|
112
|
+
## Requirements
|
|
113
|
+
|
|
114
|
+
- Vite 4.2.0 or higher
|
|
115
|
+
- Node.js 18+
|
|
116
|
+
|
|
117
|
+
## License
|
|
118
|
+
|
|
119
|
+
Apache-2.0
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
interface VertesiaPluginBuilderOptions {
|
|
2
|
+
inlineCss?: boolean;
|
|
3
|
+
cssVar?: string;
|
|
4
|
+
input?: string;
|
|
5
|
+
output?: string;
|
|
6
|
+
}
|
|
7
|
+
export declare function vertesiaPluginBuilder({ inlineCss, cssVar, input, output, }?: VertesiaPluginBuilderOptions): {
|
|
8
|
+
name: string;
|
|
9
|
+
apply: "build";
|
|
10
|
+
enforce: "post";
|
|
11
|
+
resolveId(this: import("rollup").PluginContext, id: string): "virtual:vertesia-plugin-css-entry" | null;
|
|
12
|
+
load(this: import("rollup").PluginContext, id: string): string | null;
|
|
13
|
+
buildStart(this: import("rollup").PluginContext): void;
|
|
14
|
+
generateBundle(this: import("rollup").PluginContext, _options: import("rollup").NormalizedOutputOptions, bundle: import("rollup").OutputBundle): void;
|
|
15
|
+
writeBundle(this: import("rollup").PluginContext, options: import("rollup").NormalizedOutputOptions, bundle: import("rollup").OutputBundle): void;
|
|
16
|
+
};
|
|
17
|
+
export {};
|
|
18
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,UAAU,4BAA4B;IAClC,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf,MAAM,CAAC,EAAE,MAAM,CAAC;CACnB;AACD,wBAAgB,qBAAqB,CAAC,EAClC,SAAS,EACT,MAAM,EACN,KAAK,EACL,MAAM,GACT,GAAE,4BAAiC;;WAQV,OAAO;;;;;;;EA+ChC"}
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { readFileSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { extractTailwindUtilitiesLayer } from "./parse-css.js";
|
|
4
|
+
export function vertesiaPluginBuilder({ inlineCss, cssVar, input, output, } = {}) {
|
|
5
|
+
const CSS_VAR = cssVar || 'css';
|
|
6
|
+
if (!input)
|
|
7
|
+
input = 'src/index.css';
|
|
8
|
+
if (!output)
|
|
9
|
+
output = 'plugin.css';
|
|
10
|
+
const inputRelative = input.startsWith('./') ? input : `./${input}`;
|
|
11
|
+
const jsOutput = output.replace('.css', '.js');
|
|
12
|
+
return {
|
|
13
|
+
name: 'vertesia-plugin-builder',
|
|
14
|
+
apply: 'build',
|
|
15
|
+
enforce: 'post',
|
|
16
|
+
resolveId(id) {
|
|
17
|
+
// Create a virtual CSS entry module
|
|
18
|
+
if (id === 'virtual:vertesia-plugin-css-entry') {
|
|
19
|
+
return id;
|
|
20
|
+
}
|
|
21
|
+
return null;
|
|
22
|
+
},
|
|
23
|
+
load(id) {
|
|
24
|
+
if (id === 'virtual:vertesia-plugin-css-entry') {
|
|
25
|
+
// This creates a virtual JS file that imports your actual CSS
|
|
26
|
+
return `import "${inputRelative}";`;
|
|
27
|
+
}
|
|
28
|
+
return null;
|
|
29
|
+
},
|
|
30
|
+
buildStart() {
|
|
31
|
+
// This emits the file into the build pipeline
|
|
32
|
+
this.emitFile({
|
|
33
|
+
type: 'chunk',
|
|
34
|
+
fileName: 'virtual-vertesia-plugin-css-entry.js',
|
|
35
|
+
id: 'virtual:vertesia-plugin-css-entry',
|
|
36
|
+
});
|
|
37
|
+
},
|
|
38
|
+
generateBundle(_options, bundle) {
|
|
39
|
+
delete bundle['virtual-vertesia-plugin-css-entry.js'];
|
|
40
|
+
},
|
|
41
|
+
writeBundle(options, bundle) {
|
|
42
|
+
if (!inlineCss)
|
|
43
|
+
return;
|
|
44
|
+
// Look for the generated CSS file in the output directory
|
|
45
|
+
const keys = Object.keys(bundle).filter(k => k === output);
|
|
46
|
+
if (keys.length === 1) {
|
|
47
|
+
const asset = bundle[jsOutput];
|
|
48
|
+
if (asset) {
|
|
49
|
+
const cssContent = readFileSync(join(options.dir, output), 'utf8');
|
|
50
|
+
if (cssContent) {
|
|
51
|
+
const exportedContent = extractTailwindUtilitiesLayer(cssContent);
|
|
52
|
+
if (exportedContent) {
|
|
53
|
+
const jsFile = join(options.dir, jsOutput);
|
|
54
|
+
const jsContent = readFileSync(jsFile, 'utf8');
|
|
55
|
+
writeFileSync(jsFile, `${jsContent}\nexport const ${CSS_VAR} = \`\n${exportedContent}\n\`;\n`);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACtD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,OAAO,EAAE,6BAA6B,EAAE,MAAM,gBAAgB,CAAC;AAU/D,MAAM,UAAU,qBAAqB,CAAC,EAClC,SAAS,EACT,MAAM,EACN,KAAK,EACL,MAAM,MACwB,EAAE;IAChC,MAAM,OAAO,GAAG,MAAM,IAAI,KAAK,CAAC;IAChC,IAAI,CAAC,KAAK;QAAE,KAAK,GAAG,eAAe,CAAC;IACpC,IAAI,CAAC,MAAM;QAAE,MAAM,GAAG,YAAY,CAAC;IACnC,MAAM,aAAa,GAAG,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,KAAK,EAAE,CAAC;IACpE,MAAM,QAAQ,GAAG,MAAM,CAAC,OAAO,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IAC/C,OAAO;QACH,IAAI,EAAE,yBAAyB;QAC/B,KAAK,EAAE,OAAkB;QACzB,OAAO,EAAE,MAAM;QACf,SAAS,CAAC,EAAE;YACR,oCAAoC;YACpC,IAAI,EAAE,KAAK,mCAAmC,EAAE,CAAC;gBAC7C,OAAO,EAAE,CAAC;YACd,CAAC;YACD,OAAO,IAAI,CAAC;QAChB,CAAC;QACD,IAAI,CAAC,EAAE;YACH,IAAI,EAAE,KAAK,mCAAmC,EAAE,CAAC;gBAC7C,8DAA8D;gBAC9D,OAAO,WAAW,aAAa,IAAI,CAAC;YACxC,CAAC;YACD,OAAO,IAAI,CAAC;QAChB,CAAC;QACD,UAAU;YACN,8CAA8C;YAC9C,IAAI,CAAC,QAAQ,CAAC;gBACV,IAAI,EAAE,OAAO;gBACb,QAAQ,EAAE,sCAAsC;gBAChD,EAAE,EAAE,mCAAmC;aAC1C,CAAC,CAAC;QACP,CAAC;QACD,cAAc,CAAC,QAAQ,EAAE,MAAM;YAC3B,OAAO,MAAM,CAAC,sCAAsC,CAAC,CAAC;QAC1D,CAAC;QACD,WAAW,CAAO,OAAO,EAAE,MAAM;YAC7B,IAAI,CAAC,SAAS;gBAAE,OAAO;YACvB,0DAA0D;YAC1D,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,MAAM,CAAC,CAAC;YAC3D,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;gBACpB,MAAM,KAAK,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC;gBAC/B,IAAI,KAAK,EAAE,CAAC;oBACR,MAAM,UAAU,GAAG,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC,GAAI,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,CAAA;oBACnE,IAAI,UAAU,EAAE,CAAC;wBACb,MAAM,eAAe,GAAG,6BAA6B,CAAC,UAAU,CAAC,CAAC;wBAClE,IAAI,eAAe,EAAE,CAAC;4BAClB,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,GAAI,EAAE,QAAQ,CAAC,CAAC;4BAC5C,MAAM,SAAS,GAAG,YAAY,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;4BAC/C,aAAa,CAAC,MAAM,EAAE,GAAG,SAAS,kBAAkB,OAAO,UAAU,eAAe,SAAS,CAAC,CAAC;wBACnG,CAAC;oBACL,CAAC;gBACL,CAAC;YACL,CAAC;QACL,CAAC;KACa,CAAC;AACvB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-css.d.ts","sourceRoot":"","sources":["../src/parse-css.ts"],"names":[],"mappings":"AAGA,wBAAgB,6BAA6B,CAAC,OAAO,EAAE,MAAM,UAiB5D"}
|
package/lib/parse-css.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { parse, stringify } from '@adobe/css-tools';
|
|
2
|
+
export function extractTailwindUtilitiesLayer(content) {
|
|
3
|
+
let obj = parse(content, {});
|
|
4
|
+
let result = '';
|
|
5
|
+
for (const rule of obj.stylesheet.rules) {
|
|
6
|
+
if (rule.type === 'layer' && rule.layer === 'utilities') {
|
|
7
|
+
if (rule.rules) {
|
|
8
|
+
const output = {
|
|
9
|
+
type: 'stylesheet',
|
|
10
|
+
stylesheet: {
|
|
11
|
+
rules: rule.rules
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
result = stringify(output, {});
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return result;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=parse-css.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-css.js","sourceRoot":"","sources":["../src/parse-css.ts"],"names":[],"mappings":"AACA,OAAO,EAAoB,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAEtE,MAAM,UAAU,6BAA6B,CAAC,OAAe;IACzD,IAAI,GAAG,GAAG,KAAK,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;IAC7B,IAAI,MAAM,GAAG,EAAE,CAAC;IAChB,KAAK,MAAM,IAAI,IAAI,GAAG,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC;QACtC,IAAI,IAAI,CAAC,IAAI,KAAK,OAAO,IAAI,IAAI,CAAC,KAAK,KAAK,WAAW,EAAE,CAAC;YACtD,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;gBACb,MAAM,MAAM,GAAG;oBACX,IAAI,EAAE,YAAY;oBAClB,UAAU,EAAE;wBACR,KAAK,EAAE,IAAI,CAAC,KAAK;qBACpB;iBACgB,CAAC;gBACtB,MAAM,GAAG,SAAS,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;YACnC,CAAC;QACL,CAAC;IACL,CAAC;IACD,OAAO,MAAM,CAAC;AAClB,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@vertesia/plugin-builder",
|
|
3
|
+
"version": "0.24.0-dev.202601221707",
|
|
4
|
+
"description": "A vite plugin to build vertesia UI plugins",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"types": "./lib/index.d.ts",
|
|
7
|
+
"main": "./lib/index.js",
|
|
8
|
+
"files": [
|
|
9
|
+
"lib",
|
|
10
|
+
"src"
|
|
11
|
+
],
|
|
12
|
+
"license": "Apache-2.0",
|
|
13
|
+
"homepage": "https://docs.vertesiahq.com",
|
|
14
|
+
"keywords": [
|
|
15
|
+
"vertesia",
|
|
16
|
+
"plugin",
|
|
17
|
+
"vite",
|
|
18
|
+
"vite-plugin",
|
|
19
|
+
"ui",
|
|
20
|
+
"react",
|
|
21
|
+
"css",
|
|
22
|
+
"tailwind"
|
|
23
|
+
],
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"typescript": "^5.9.3"
|
|
26
|
+
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"@adobe/css-tools": "^4.4.1",
|
|
29
|
+
"@types/node": "^22.19.2"
|
|
30
|
+
},
|
|
31
|
+
"peerDependencies": {
|
|
32
|
+
"vite": "^7.3.0"
|
|
33
|
+
},
|
|
34
|
+
"repository": {
|
|
35
|
+
"type": "git",
|
|
36
|
+
"url": "https://github.com/vertesia/composableai.git",
|
|
37
|
+
"directory": "packages/plugin-builder"
|
|
38
|
+
},
|
|
39
|
+
"scripts": {
|
|
40
|
+
"eslint": "eslint './src/**/*.{jsx,js,tsx,ts}'",
|
|
41
|
+
"build": "rm -rf ./lib ./tsconfig.tsbuildinfo && tsc",
|
|
42
|
+
"clean": "rimraf ./node_modules ./lib ./tsconfig.tsbuildinfo"
|
|
43
|
+
}
|
|
44
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { readFileSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { Plugin } from "vite";
|
|
4
|
+
import { extractTailwindUtilitiesLayer } from "./parse-css.js";
|
|
5
|
+
|
|
6
|
+
interface VertesiaPluginBuilderOptions {
|
|
7
|
+
inlineCss?: boolean,
|
|
8
|
+
cssVar?: string;
|
|
9
|
+
// the input file. defaults to src/index.css
|
|
10
|
+
input?: string;
|
|
11
|
+
// the output file name. Defaults to plugin.css
|
|
12
|
+
output?: string;
|
|
13
|
+
}
|
|
14
|
+
export function vertesiaPluginBuilder({
|
|
15
|
+
inlineCss,
|
|
16
|
+
cssVar,
|
|
17
|
+
input,
|
|
18
|
+
output,
|
|
19
|
+
}: VertesiaPluginBuilderOptions = {}) {
|
|
20
|
+
const CSS_VAR = cssVar || 'css';
|
|
21
|
+
if (!input) input = 'src/index.css';
|
|
22
|
+
if (!output) output = 'plugin.css';
|
|
23
|
+
const inputRelative = input.startsWith('./') ? input : `./${input}`;
|
|
24
|
+
const jsOutput = output.replace('.css', '.js');
|
|
25
|
+
return {
|
|
26
|
+
name: 'vertesia-plugin-builder',
|
|
27
|
+
apply: 'build' as 'build',
|
|
28
|
+
enforce: 'post',
|
|
29
|
+
resolveId(id) {
|
|
30
|
+
// Create a virtual CSS entry module
|
|
31
|
+
if (id === 'virtual:vertesia-plugin-css-entry') {
|
|
32
|
+
return id;
|
|
33
|
+
}
|
|
34
|
+
return null;
|
|
35
|
+
},
|
|
36
|
+
load(id) {
|
|
37
|
+
if (id === 'virtual:vertesia-plugin-css-entry') {
|
|
38
|
+
// This creates a virtual JS file that imports your actual CSS
|
|
39
|
+
return `import "${inputRelative}";`;
|
|
40
|
+
}
|
|
41
|
+
return null;
|
|
42
|
+
},
|
|
43
|
+
buildStart(this) {
|
|
44
|
+
// This emits the file into the build pipeline
|
|
45
|
+
this.emitFile({
|
|
46
|
+
type: 'chunk',
|
|
47
|
+
fileName: 'virtual-vertesia-plugin-css-entry.js',
|
|
48
|
+
id: 'virtual:vertesia-plugin-css-entry',
|
|
49
|
+
});
|
|
50
|
+
},
|
|
51
|
+
generateBundle(_options, bundle) {
|
|
52
|
+
delete bundle['virtual-vertesia-plugin-css-entry.js'];
|
|
53
|
+
},
|
|
54
|
+
writeBundle(this, options, bundle) {
|
|
55
|
+
if (!inlineCss) return;
|
|
56
|
+
// Look for the generated CSS file in the output directory
|
|
57
|
+
const keys = Object.keys(bundle).filter(k => k === output);
|
|
58
|
+
if (keys.length === 1) {
|
|
59
|
+
const asset = bundle[jsOutput];
|
|
60
|
+
if (asset) {
|
|
61
|
+
const cssContent = readFileSync(join(options.dir!, output), 'utf8')
|
|
62
|
+
if (cssContent) {
|
|
63
|
+
const exportedContent = extractTailwindUtilitiesLayer(cssContent);
|
|
64
|
+
if (exportedContent) {
|
|
65
|
+
const jsFile = join(options.dir!, jsOutput);
|
|
66
|
+
const jsContent = readFileSync(jsFile, 'utf8');
|
|
67
|
+
writeFileSync(jsFile, `${jsContent}\nexport const ${CSS_VAR} = \`\n${exportedContent}\n\`;\n`);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
} satisfies Plugin;
|
|
74
|
+
}
|
package/src/parse-css.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
|
|
2
|
+
import { CssStylesheetAST, parse, stringify } from '@adobe/css-tools';
|
|
3
|
+
|
|
4
|
+
export function extractTailwindUtilitiesLayer(content: string) {
|
|
5
|
+
let obj = parse(content, {});
|
|
6
|
+
let result = '';
|
|
7
|
+
for (const rule of obj.stylesheet.rules) {
|
|
8
|
+
if (rule.type === 'layer' && rule.layer === 'utilities') {
|
|
9
|
+
if (rule.rules) {
|
|
10
|
+
const output = {
|
|
11
|
+
type: 'stylesheet',
|
|
12
|
+
stylesheet: {
|
|
13
|
+
rules: rule.rules
|
|
14
|
+
}
|
|
15
|
+
} as CssStylesheetAST;
|
|
16
|
+
result = stringify(output, {});
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return result;
|
|
21
|
+
}
|