@flairjs/webpack-loader 0.0.1-beta.8 → 0.0.1
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 +146 -0
- package/dist/cjs/index.js +6 -2
- package/dist/esm/index.js +6 -2
- package/package.json +5 -6
package/README.md
CHANGED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
# @flairjs/webpack-loader
|
|
2
|
+
|
|
3
|
+
Webpack loader for Flair CSS-in-JSX.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @flairjs/webpack-loader
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```js
|
|
14
|
+
// webpack.config.js
|
|
15
|
+
module.exports = {
|
|
16
|
+
module: {
|
|
17
|
+
rules: [
|
|
18
|
+
{
|
|
19
|
+
test: /\.(tsx|jsx)$/,
|
|
20
|
+
use: [
|
|
21
|
+
'@flairjs/webpack-loader'
|
|
22
|
+
],
|
|
23
|
+
exclude: /node_modules/
|
|
24
|
+
}
|
|
25
|
+
]
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Configuration
|
|
31
|
+
|
|
32
|
+
```js
|
|
33
|
+
// webpack.config.js
|
|
34
|
+
module.exports = {
|
|
35
|
+
module: {
|
|
36
|
+
rules: [
|
|
37
|
+
{
|
|
38
|
+
test: /\.(tsx|jsx)$/,
|
|
39
|
+
use: [
|
|
40
|
+
'babel-loader',
|
|
41
|
+
{
|
|
42
|
+
loader: '@flairjs/webpack-loader',
|
|
43
|
+
options: {
|
|
44
|
+
// Configuration options
|
|
45
|
+
cssPreprocessor: (css, id) => {
|
|
46
|
+
// Custom CSS preprocessing
|
|
47
|
+
return css
|
|
48
|
+
},
|
|
49
|
+
include: ['src/**/*.{tsx,jsx}'],
|
|
50
|
+
exclude: ['**/*.test.{tsx,jsx}'],
|
|
51
|
+
classNameList: ["className", "class"]
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
]
|
|
55
|
+
}
|
|
56
|
+
]
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### Configuration Options
|
|
62
|
+
|
|
63
|
+
```typescript
|
|
64
|
+
interface FlairJsWebpackLoaderOptions {
|
|
65
|
+
/**
|
|
66
|
+
* Preprocess the extracted CSS before it is passed to lightningcss
|
|
67
|
+
* @experimental
|
|
68
|
+
*/
|
|
69
|
+
cssPreprocessor?: (css: string, id: string) => string
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Files to include (default: all .tsx/.jsx files)
|
|
73
|
+
*/
|
|
74
|
+
include?: string | string[]
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Files to exclude (default: node_modules)
|
|
78
|
+
*/
|
|
79
|
+
exclude?: string | string[]
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Override the default theme file content
|
|
83
|
+
*/
|
|
84
|
+
buildThemeFile?: (theme: FlairThemeConfig) => string
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* List of class names used in the project. Supports regex.
|
|
88
|
+
*/
|
|
89
|
+
classNameList?: string[]
|
|
90
|
+
}
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## CSS Handling
|
|
94
|
+
|
|
95
|
+
Ensure your webpack configuration can handle CSS files:
|
|
96
|
+
|
|
97
|
+
```js
|
|
98
|
+
// webpack.config.js
|
|
99
|
+
module.exports = {
|
|
100
|
+
module: {
|
|
101
|
+
rules: [
|
|
102
|
+
// Flair loader
|
|
103
|
+
{
|
|
104
|
+
test: /\.(tsx|jsx)$/,
|
|
105
|
+
use: ['@flairjs/webpack-loader']
|
|
106
|
+
},
|
|
107
|
+
// CSS loader for generated styles
|
|
108
|
+
{
|
|
109
|
+
test: /\.css$/,
|
|
110
|
+
use: ['style-loader', 'css-loader']
|
|
111
|
+
}
|
|
112
|
+
]
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
## Theme Integration
|
|
119
|
+
|
|
120
|
+
Create a `flair.theme.ts` in your project root:
|
|
121
|
+
|
|
122
|
+
```typescript
|
|
123
|
+
// flair.theme.ts
|
|
124
|
+
import { defineConfig } from '@flairjs/client'
|
|
125
|
+
|
|
126
|
+
export default defineConfig({
|
|
127
|
+
tokens: {
|
|
128
|
+
colors: {
|
|
129
|
+
primary: '#3b82f6',
|
|
130
|
+
secondary: '#64748b'
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
})
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
Import the theme in your entry file:
|
|
137
|
+
|
|
138
|
+
```js
|
|
139
|
+
// src/index.js
|
|
140
|
+
import '@flairjs/client/theme.css'
|
|
141
|
+
import './App'
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
## License
|
|
145
|
+
|
|
146
|
+
MIT
|
package/dist/cjs/index.js
CHANGED
|
@@ -239,7 +239,7 @@ async function flairJsLoader(source, sourceMap) {
|
|
|
239
239
|
let cssGeneratedDir = null;
|
|
240
240
|
let userTheme = null;
|
|
241
241
|
if (!initialized) {
|
|
242
|
-
cssGeneratedDir = await setupGeneratedCssDir();
|
|
242
|
+
cssGeneratedDir = await setupGeneratedCssDir({ clearExisting: this.mode !== "production" });
|
|
243
243
|
userTheme = await setupUserThemeFile({
|
|
244
244
|
buildThemeFile: options.buildThemeFile,
|
|
245
245
|
deleteBeforeWrite: true
|
|
@@ -265,7 +265,11 @@ async function flairJsLoader(source, sourceMap) {
|
|
|
265
265
|
if (!result) return callback(null, source, sourceMap);
|
|
266
266
|
if (!result.generatedCssName) return callback(null, source, sourceMap);
|
|
267
267
|
this.addDependency(path.resolve(result.generatedCssName));
|
|
268
|
-
|
|
268
|
+
let resultSourcemap = null;
|
|
269
|
+
if (result.sourcemap) try {
|
|
270
|
+
resultSourcemap = JSON.parse(result.sourcemap);
|
|
271
|
+
} catch {}
|
|
272
|
+
callback(null, result.code, resultSourcemap ?? sourceMap);
|
|
269
273
|
} catch (error) {
|
|
270
274
|
console.error("[@flairjs/webpack-loader]", error);
|
|
271
275
|
callback(error, source, sourceMap);
|
package/dist/esm/index.js
CHANGED
|
@@ -206,7 +206,7 @@ async function flairJsLoader(source, sourceMap) {
|
|
|
206
206
|
let cssGeneratedDir = null;
|
|
207
207
|
let userTheme = null;
|
|
208
208
|
if (!initialized) {
|
|
209
|
-
cssGeneratedDir = await setupGeneratedCssDir();
|
|
209
|
+
cssGeneratedDir = await setupGeneratedCssDir({ clearExisting: this.mode !== "production" });
|
|
210
210
|
userTheme = await setupUserThemeFile({
|
|
211
211
|
buildThemeFile: options.buildThemeFile,
|
|
212
212
|
deleteBeforeWrite: true
|
|
@@ -232,7 +232,11 @@ async function flairJsLoader(source, sourceMap) {
|
|
|
232
232
|
if (!result) return callback(null, source, sourceMap);
|
|
233
233
|
if (!result.generatedCssName) return callback(null, source, sourceMap);
|
|
234
234
|
this.addDependency(path$2.resolve(result.generatedCssName));
|
|
235
|
-
|
|
235
|
+
let resultSourcemap = null;
|
|
236
|
+
if (result.sourcemap) try {
|
|
237
|
+
resultSourcemap = JSON.parse(result.sourcemap);
|
|
238
|
+
} catch {}
|
|
239
|
+
callback(null, result.code, resultSourcemap ?? sourceMap);
|
|
236
240
|
} catch (error) {
|
|
237
241
|
console.error("[@flairjs/webpack-loader]", error);
|
|
238
242
|
callback(error, source, sourceMap);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flairjs/webpack-loader",
|
|
3
|
-
"version": "0.0.1
|
|
3
|
+
"version": "0.0.1",
|
|
4
4
|
"main": "./dist/cjs/index.js",
|
|
5
5
|
"module": "./dist/esm/index.js",
|
|
6
6
|
"types": "./dist/types/index.d.ts",
|
|
@@ -12,8 +12,7 @@
|
|
|
12
12
|
"access": "public"
|
|
13
13
|
},
|
|
14
14
|
"peerDependencies": {
|
|
15
|
-
"webpack": ">=5.0.0"
|
|
16
|
-
"@flairjs/core": "0.0.1-beta.7"
|
|
15
|
+
"webpack": ">=5.0.0"
|
|
17
16
|
},
|
|
18
17
|
"devDependencies": {
|
|
19
18
|
"@biomejs/biome": "^2.2.4",
|
|
@@ -23,12 +22,12 @@
|
|
|
23
22
|
"rolldown": "1.0.0-beta.37",
|
|
24
23
|
"typescript": "^5.8.2",
|
|
25
24
|
"webpack": "^5.101.0",
|
|
26
|
-
"@flairjs/bundler-shared": "0.0.1
|
|
27
|
-
"@flairjs/core": "0.0.1-beta.7"
|
|
25
|
+
"@flairjs/bundler-shared": "0.0.1"
|
|
28
26
|
},
|
|
29
27
|
"dependencies": {
|
|
30
28
|
"esbuild": "^0.25.10",
|
|
31
|
-
"picomatch": "^4.0.3"
|
|
29
|
+
"picomatch": "^4.0.3",
|
|
30
|
+
"@flairjs/core": "0.0.1"
|
|
32
31
|
},
|
|
33
32
|
"scripts": {
|
|
34
33
|
"build": "rimraf dist && tsc && api-extractor run --local && rolldown -c && rimraf dist/types-temp",
|