@flairjs/parcel-transformer 0.0.1-beta.6 → 0.0.1-beta.9
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 +154 -0
- package/dist/cjs/index.js +3 -2
- package/dist/esm/index.js +3 -2
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
# @flairjs/parcel-transformer
|
|
2
|
+
|
|
3
|
+
Parcel transformer for Flair CSS-in-JSX.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @flairjs/parcel-transformer
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
Add the transformer to your `.parcelrc` file:
|
|
14
|
+
|
|
15
|
+
```json
|
|
16
|
+
{
|
|
17
|
+
"extends": "@parcel/config-default",
|
|
18
|
+
"transformers": {
|
|
19
|
+
"*.{tsx,jsx}": ["@flairjs/parcel-transformer", "..."]
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Configuration
|
|
25
|
+
|
|
26
|
+
You can configure the transformer by adding options to your `package.json`:
|
|
27
|
+
|
|
28
|
+
```json
|
|
29
|
+
{
|
|
30
|
+
"@flairjs/parcel-transformer": {
|
|
31
|
+
"include": ["src/**/*.{tsx,jsx}"],
|
|
32
|
+
"exclude": ["**/*.test.{tsx,jsx}"],
|
|
33
|
+
"classNameList": ["className", "class"]
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### Configuration Options
|
|
39
|
+
|
|
40
|
+
```typescript
|
|
41
|
+
interface FlairJsParcelTransformerOptions {
|
|
42
|
+
/**
|
|
43
|
+
* Preprocess the extracted CSS before it is passed to lightningcss
|
|
44
|
+
* @experimental
|
|
45
|
+
*/
|
|
46
|
+
cssPreprocessor?: (css: string, id: string) => string
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Files to include (default: all .tsx/.jsx files)
|
|
50
|
+
*/
|
|
51
|
+
include?: string | string[]
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Files to exclude (default: node_modules)
|
|
55
|
+
*/
|
|
56
|
+
exclude?: string | string[]
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Override the default theme file content
|
|
60
|
+
*/
|
|
61
|
+
buildThemeFile?: (theme: FlairThemeConfig) => string
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* List of class names used in the project. Supports regex.
|
|
65
|
+
*/
|
|
66
|
+
classNameList?: string[]
|
|
67
|
+
}
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## Complete Parcel Setup
|
|
71
|
+
|
|
72
|
+
### 1. Install Dependencies
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
npm install parcel @flairjs/client @flairjs/core @flairjs/parcel-transformer
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### 2. Create .parcelrc
|
|
79
|
+
|
|
80
|
+
```json
|
|
81
|
+
{
|
|
82
|
+
"extends": "@parcel/config-default",
|
|
83
|
+
"transformers": {
|
|
84
|
+
"*.{tsx,jsx}": ["@flairjs/parcel-transformer", "..."]
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### 3. Package.json Scripts
|
|
90
|
+
|
|
91
|
+
```json
|
|
92
|
+
{
|
|
93
|
+
"scripts": {
|
|
94
|
+
"dev": "parcel src/index.html",
|
|
95
|
+
"build": "parcel build src/index.html"
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### 4. Create Theme File
|
|
101
|
+
|
|
102
|
+
```typescript
|
|
103
|
+
// flair.theme.ts
|
|
104
|
+
import { defineConfig } from '@flairjs/client'
|
|
105
|
+
|
|
106
|
+
export default defineConfig({
|
|
107
|
+
tokens: {
|
|
108
|
+
colors: {
|
|
109
|
+
primary: '#3b82f6',
|
|
110
|
+
secondary: '#64748b'
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
})
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### 5. Import Theme CSS
|
|
117
|
+
|
|
118
|
+
```js
|
|
119
|
+
// src/index.js
|
|
120
|
+
import '@flairjs/client/theme.css'
|
|
121
|
+
import { App } from './App'
|
|
122
|
+
|
|
123
|
+
// Render your app
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
## React Setup
|
|
127
|
+
|
|
128
|
+
```jsx
|
|
129
|
+
// src/App.jsx
|
|
130
|
+
import { flair } from '@flairjs/client'
|
|
131
|
+
|
|
132
|
+
const App = () => {
|
|
133
|
+
return (
|
|
134
|
+
<div className="app">
|
|
135
|
+
<h1>Hello Flair!</h1>
|
|
136
|
+
</div>
|
|
137
|
+
)
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
App.flair = flair({
|
|
141
|
+
'.app': {
|
|
142
|
+
fontFamily: 'system-ui, sans-serif',
|
|
143
|
+
padding: '$space.4',
|
|
144
|
+
backgroundColor: '$colors.primary',
|
|
145
|
+
color: 'white'
|
|
146
|
+
}
|
|
147
|
+
})
|
|
148
|
+
|
|
149
|
+
export { App }
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
## License
|
|
153
|
+
|
|
154
|
+
MIT
|
package/dist/cjs/index.js
CHANGED
|
@@ -159,13 +159,14 @@ const setupGeneratedCssDir = async (options) => {
|
|
|
159
159
|
}
|
|
160
160
|
return flairGeneratedCssDir;
|
|
161
161
|
};
|
|
162
|
-
const setupUserThemeFile = async ({ buildThemeFile, onThemeFileChange }) => {
|
|
162
|
+
const setupUserThemeFile = async ({ buildThemeFile, onThemeFileChange, deleteBeforeWrite = false }) => {
|
|
163
163
|
const flairThemeFile = require$1.resolve("@flairjs/client/theme.css");
|
|
164
164
|
let userTheme = await getUserTheme();
|
|
165
165
|
const buildThemeCSS = buildThemeFile ?? buildThemeTokens;
|
|
166
166
|
if (userTheme) {
|
|
167
167
|
const themeCSS = buildThemeCSS(userTheme.theme);
|
|
168
168
|
store.setLastThemeUpdate(Date.now());
|
|
169
|
+
if (deleteBeforeWrite) await (0, node_fs_promises.rm)(flairThemeFile, { force: true });
|
|
169
170
|
await (0, node_fs_promises.writeFile)(flairThemeFile, themeCSS, "utf-8");
|
|
170
171
|
(0, node_fs.watch)(userTheme.originalPath, async () => {
|
|
171
172
|
userTheme = await getUserTheme();
|
|
@@ -233,7 +234,7 @@ const SourceMap = __parcel_source_map.default.default ?? __parcel_source_map.def
|
|
|
233
234
|
let initialized = false;
|
|
234
235
|
const transformer = new __parcel_plugin.Transformer({
|
|
235
236
|
async loadConfig({ config }) {
|
|
236
|
-
const getConfigResult = await config.getConfig(["
|
|
237
|
+
const getConfigResult = await config.getConfig(["flair.config.js"]);
|
|
237
238
|
const filePath = getConfigResult?.filePath;
|
|
238
239
|
const configContents = getConfigResult?.contents;
|
|
239
240
|
if (filePath?.endsWith(".js")) config.invalidateOnStartup();
|
package/dist/esm/index.js
CHANGED
|
@@ -124,13 +124,14 @@ const setupGeneratedCssDir = async (options) => {
|
|
|
124
124
|
}
|
|
125
125
|
return flairGeneratedCssDir;
|
|
126
126
|
};
|
|
127
|
-
const setupUserThemeFile = async ({ buildThemeFile, onThemeFileChange }) => {
|
|
127
|
+
const setupUserThemeFile = async ({ buildThemeFile, onThemeFileChange, deleteBeforeWrite = false }) => {
|
|
128
128
|
const flairThemeFile = require.resolve("@flairjs/client/theme.css");
|
|
129
129
|
let userTheme = await getUserTheme();
|
|
130
130
|
const buildThemeCSS = buildThemeFile ?? buildThemeTokens;
|
|
131
131
|
if (userTheme) {
|
|
132
132
|
const themeCSS = buildThemeCSS(userTheme.theme);
|
|
133
133
|
store.setLastThemeUpdate(Date.now());
|
|
134
|
+
if (deleteBeforeWrite) await rm(flairThemeFile, { force: true });
|
|
134
135
|
await writeFile(flairThemeFile, themeCSS, "utf-8");
|
|
135
136
|
watch(userTheme.originalPath, async () => {
|
|
136
137
|
userTheme = await getUserTheme();
|
|
@@ -198,7 +199,7 @@ const SourceMap = SourceMapImport.default ?? SourceMapImport;
|
|
|
198
199
|
let initialized = false;
|
|
199
200
|
const transformer = new Transformer({
|
|
200
201
|
async loadConfig({ config }) {
|
|
201
|
-
const getConfigResult = await config.getConfig(["
|
|
202
|
+
const getConfigResult = await config.getConfig(["flair.config.js"]);
|
|
202
203
|
const filePath = getConfigResult?.filePath;
|
|
203
204
|
const configContents = getConfigResult?.contents;
|
|
204
205
|
if (filePath?.endsWith(".js")) config.invalidateOnStartup();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flairjs/parcel-transformer",
|
|
3
|
-
"version": "0.0.1-beta.
|
|
3
|
+
"version": "0.0.1-beta.9",
|
|
4
4
|
"main": "./dist/cjs/index.js",
|
|
5
5
|
"module": "./dist/esm/index.js",
|
|
6
6
|
"types": "./dist/types/index.d.ts",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
},
|
|
14
14
|
"peerDependencies": {
|
|
15
15
|
"parcel": ">=2.0.0",
|
|
16
|
-
"@flairjs/core": "0.0.1-beta.
|
|
16
|
+
"@flairjs/core": "0.0.1-beta.8"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
19
|
"@biomejs/biome": "^2.2.4",
|
|
@@ -23,8 +23,8 @@
|
|
|
23
23
|
"rimraf": "^6.0.1",
|
|
24
24
|
"rolldown": "1.0.0-beta.37",
|
|
25
25
|
"typescript": "^5.8.2",
|
|
26
|
-
"@flairjs/bundler-shared": "0.0.1-beta.
|
|
27
|
-
"@flairjs/core": "0.0.1-beta.
|
|
26
|
+
"@flairjs/bundler-shared": "0.0.1-beta.13",
|
|
27
|
+
"@flairjs/core": "0.0.1-beta.8"
|
|
28
28
|
},
|
|
29
29
|
"engines": {
|
|
30
30
|
"parcel": ">=2.0.0"
|