@flairjs/webpack-loader 0.0.1-beta.5 → 0.0.1-beta.7
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/dist/cjs/index.js +107 -45
- package/dist/esm/index.js +107 -45
- package/dist/types/index.d.ts +33 -6
- package/package.json +12 -18
- package/dist/types/index.js +0 -4142
package/dist/cjs/index.js
CHANGED
|
@@ -71,8 +71,33 @@ function tokensToCSSVars(tokens, prefix = []) {
|
|
|
71
71
|
}
|
|
72
72
|
return css$1;
|
|
73
73
|
}
|
|
74
|
+
var Store = class {
|
|
75
|
+
fileNameToGeneratedCssNameMap = /* @__PURE__ */ new Map();
|
|
76
|
+
lastThemeUpdate = Date.now();
|
|
77
|
+
userTheme = /* @__PURE__ */ new Map();
|
|
78
|
+
getUserTheme() {
|
|
79
|
+
return this.userTheme.get(this.lastThemeUpdate) ?? null;
|
|
80
|
+
}
|
|
81
|
+
setUserTheme(theme) {
|
|
82
|
+
this.userTheme.set(this.lastThemeUpdate, theme);
|
|
83
|
+
}
|
|
84
|
+
getLastThemeUpdate() {
|
|
85
|
+
return this.lastThemeUpdate;
|
|
86
|
+
}
|
|
87
|
+
setLastThemeUpdate(timestamp) {
|
|
88
|
+
this.lastThemeUpdate = timestamp;
|
|
89
|
+
}
|
|
90
|
+
setFileNameToGeneratedCssNameMap(fileName, generatedCssName) {
|
|
91
|
+
this.fileNameToGeneratedCssNameMap.set(fileName, generatedCssName);
|
|
92
|
+
}
|
|
93
|
+
getGeneratedCssName(fileName) {
|
|
94
|
+
return this.fileNameToGeneratedCssNameMap.get(fileName);
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
const store = new Store();
|
|
74
98
|
const __dirname$1 = (0, node_path.dirname)((0, node_url.fileURLToPath)(require("url").pathToFileURL(__filename).href));
|
|
75
|
-
const getUserTheme = async () => {
|
|
99
|
+
const getUserTheme = async (options) => {
|
|
100
|
+
if (store.getUserTheme() && !options?.ignoreCache) return store.getUserTheme();
|
|
76
101
|
try {
|
|
77
102
|
let userThemeFilePath = path.default.resolve(process.cwd(), "flair.theme.ts");
|
|
78
103
|
if (!(0, fs.existsSync)(userThemeFilePath)) userThemeFilePath = path.default.resolve(process.cwd(), "flair.theme.js");
|
|
@@ -88,10 +113,17 @@ const getUserTheme = async () => {
|
|
|
88
113
|
});
|
|
89
114
|
const cacheBuster = Date.now();
|
|
90
115
|
const userTheme = await import(`${(0, url.pathToFileURL)(outFile).href}?update=${cacheBuster}`);
|
|
91
|
-
if (userTheme.default)
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
116
|
+
if (userTheme.default) {
|
|
117
|
+
store.setUserTheme({
|
|
118
|
+
theme: userTheme.default,
|
|
119
|
+
originalPath: userThemeFilePath
|
|
120
|
+
});
|
|
121
|
+
return {
|
|
122
|
+
theme: userTheme.default,
|
|
123
|
+
originalPath: userThemeFilePath
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
store.setUserTheme(null);
|
|
95
127
|
return null;
|
|
96
128
|
} catch (error) {
|
|
97
129
|
console.error("Error loading user theme:", error);
|
|
@@ -99,57 +131,73 @@ const getUserTheme = async () => {
|
|
|
99
131
|
}
|
|
100
132
|
};
|
|
101
133
|
const require$1 = node_module.default.createRequire(require("url").pathToFileURL(__filename).href);
|
|
102
|
-
|
|
103
|
-
* Initialize the shared plugin context
|
|
104
|
-
*/
|
|
105
|
-
async function initializeSharedContext(options = {}) {
|
|
106
|
-
const { buildThemeFile } = options;
|
|
107
|
-
const fileNameToGeneratedCssNameMap = /* @__PURE__ */ new Map();
|
|
134
|
+
const getGeneratedCssDir = () => {
|
|
108
135
|
const flairThemeFile = require$1.resolve("@flairjs/client/theme.css");
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
136
|
+
return node_path.default.resolve(flairThemeFile, "../generated-css");
|
|
137
|
+
};
|
|
138
|
+
const setupGeneratedCssDir = async (options) => {
|
|
139
|
+
const flairGeneratedCssDir = getGeneratedCssDir();
|
|
140
|
+
const { clearExisting = true } = options ?? {};
|
|
141
|
+
try {
|
|
142
|
+
if (!(0, node_fs.existsSync)(flairGeneratedCssDir)) await (0, node_fs_promises.mkdir)(flairGeneratedCssDir);
|
|
143
|
+
else if (clearExisting) {
|
|
144
|
+
await (0, node_fs_promises.rm)(flairGeneratedCssDir, {
|
|
145
|
+
recursive: true,
|
|
146
|
+
force: true
|
|
147
|
+
});
|
|
148
|
+
await (0, node_fs_promises.mkdir)(flairGeneratedCssDir);
|
|
149
|
+
}
|
|
150
|
+
} catch (err) {
|
|
151
|
+
if (err?.code === "EEXIST") return flairGeneratedCssDir;
|
|
152
|
+
else if ((0, node_fs.existsSync)(flairGeneratedCssDir)) return flairGeneratedCssDir;
|
|
153
|
+
console.error(`[flairjs] Could not create generated CSS directory: ${flairGeneratedCssDir}`, err);
|
|
154
|
+
return null;
|
|
117
155
|
}
|
|
156
|
+
return flairGeneratedCssDir;
|
|
157
|
+
};
|
|
158
|
+
const setupUserThemeFile = async ({ buildThemeFile, onThemeFileChange }) => {
|
|
159
|
+
const flairThemeFile = require$1.resolve("@flairjs/client/theme.css");
|
|
118
160
|
let userTheme = await getUserTheme();
|
|
119
161
|
const buildThemeCSS = buildThemeFile ?? buildThemeTokens;
|
|
120
162
|
if (userTheme) {
|
|
121
163
|
const themeCSS = buildThemeCSS(userTheme.theme);
|
|
164
|
+
store.setLastThemeUpdate(Date.now());
|
|
122
165
|
await (0, node_fs_promises.writeFile)(flairThemeFile, themeCSS, "utf-8");
|
|
123
166
|
(0, node_fs.watch)(userTheme.originalPath, async () => {
|
|
124
167
|
userTheme = await getUserTheme();
|
|
168
|
+
store.setLastThemeUpdate(Date.now());
|
|
125
169
|
if (!userTheme) return;
|
|
126
170
|
const themeCSS$1 = buildThemeCSS(userTheme.theme);
|
|
171
|
+
onThemeFileChange?.();
|
|
127
172
|
await (0, node_fs_promises.writeFile)(flairThemeFile, themeCSS$1, "utf-8");
|
|
128
173
|
});
|
|
129
174
|
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
175
|
+
return userTheme;
|
|
176
|
+
};
|
|
177
|
+
const removeOutdatedCssFiles = async (sourceFilePath, cssFilePath, { flairGeneratedCssDir, clearInstantly = false }) => {
|
|
178
|
+
const previousGeneratedCssName = store.getGeneratedCssName(sourceFilePath);
|
|
179
|
+
if (previousGeneratedCssName && previousGeneratedCssName !== cssFilePath) {
|
|
180
|
+
if (clearInstantly) {
|
|
181
|
+
await (0, node_fs_promises.rm)(node_path.default.join(flairGeneratedCssDir, previousGeneratedCssName), { force: true });
|
|
182
|
+
store.setFileNameToGeneratedCssNameMap(sourceFilePath, cssFilePath);
|
|
183
|
+
return;
|
|
136
184
|
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
refreshCssFile
|
|
144
|
-
};
|
|
145
|
-
}
|
|
185
|
+
setTimeout(() => {
|
|
186
|
+
(0, node_fs_promises.rm)(node_path.default.join(flairGeneratedCssDir, previousGeneratedCssName), { force: true });
|
|
187
|
+
}, 2e3);
|
|
188
|
+
}
|
|
189
|
+
store.setFileNameToGeneratedCssNameMap(sourceFilePath, cssFilePath);
|
|
190
|
+
};
|
|
146
191
|
function shouldProcessFile(id, include, exclude) {
|
|
147
|
-
const isIncluded = (0, picomatch.default)(include
|
|
148
|
-
const isExcluded = (0, picomatch.default)(exclude
|
|
149
|
-
if (!isIncluded(id)) return false;
|
|
150
|
-
if (isExcluded(id)) return false;
|
|
192
|
+
const isIncluded = (0, picomatch.default)(include ?? ["**/*.{js,ts,jsx,tsx}"]);
|
|
193
|
+
const isExcluded = (0, picomatch.default)(exclude ?? ["**/node_modules/**"]);
|
|
194
|
+
if (!isIncluded(normalizeFilePath(id))) return false;
|
|
195
|
+
if (isExcluded(normalizeFilePath(id))) return false;
|
|
151
196
|
return true;
|
|
152
197
|
}
|
|
198
|
+
function normalizeFilePath(filePath) {
|
|
199
|
+
return filePath.replace(/\\/g, "/");
|
|
200
|
+
}
|
|
153
201
|
const colors = {
|
|
154
202
|
reset: "\x1B[0m",
|
|
155
203
|
fg: {
|
|
@@ -191,28 +239,42 @@ const transformCode = (code, filePath, options) => {
|
|
|
191
239
|
|
|
192
240
|
//#endregion
|
|
193
241
|
//#region src/index.ts
|
|
242
|
+
let initialized = false;
|
|
194
243
|
async function flairJsLoader(source, sourceMap) {
|
|
195
244
|
const callback = this.async();
|
|
245
|
+
const options = this.getOptions() || {};
|
|
196
246
|
if (!callback) {
|
|
197
247
|
console.error("@flairjs/webpack-loader requires async support");
|
|
198
248
|
return;
|
|
199
249
|
}
|
|
200
|
-
const options = this.getOptions() || {};
|
|
201
|
-
const context = await initializeSharedContext(options);
|
|
202
250
|
const fileName = this.resourcePath;
|
|
203
251
|
if (!shouldProcessFile(fileName, options?.include, options?.exclude)) return callback(null, source, sourceMap);
|
|
252
|
+
let cssGeneratedDir = null;
|
|
253
|
+
let userTheme = null;
|
|
254
|
+
if (!initialized) {
|
|
255
|
+
cssGeneratedDir = await setupGeneratedCssDir();
|
|
256
|
+
userTheme = await setupUserThemeFile({ buildThemeFile: options.buildThemeFile });
|
|
257
|
+
initialized = true;
|
|
258
|
+
} else {
|
|
259
|
+
cssGeneratedDir = getGeneratedCssDir();
|
|
260
|
+
userTheme = await getUserTheme();
|
|
261
|
+
}
|
|
262
|
+
if (!cssGeneratedDir) {
|
|
263
|
+
console.error("[flairjs] Could not find generated CSS directory. Skipping processing.");
|
|
264
|
+
return callback(null, source, sourceMap);
|
|
265
|
+
}
|
|
204
266
|
try {
|
|
205
267
|
const result = transformCode(source, fileName, {
|
|
206
268
|
appendTimestampToCssFile: true,
|
|
207
269
|
classNameList: options?.classNameList,
|
|
208
270
|
cssPreprocessor: options?.cssPreprocessor ? (css) => options.cssPreprocessor(css, fileName) : void 0,
|
|
209
|
-
theme:
|
|
210
|
-
useTheme: !!
|
|
211
|
-
cssOutDir:
|
|
271
|
+
theme: userTheme?.theme,
|
|
272
|
+
useTheme: !!userTheme,
|
|
273
|
+
cssOutDir: cssGeneratedDir
|
|
212
274
|
});
|
|
213
275
|
if (!result) return callback(null, source, sourceMap);
|
|
214
|
-
if (result.generatedCssName)
|
|
215
|
-
callback(null, result.code, result.
|
|
276
|
+
if (result.generatedCssName) removeOutdatedCssFiles(fileName, result.generatedCssName, { flairGeneratedCssDir: cssGeneratedDir });
|
|
277
|
+
callback(null, result.code, result.sourcemap ? JSON.parse(result.sourcemap ?? "{}") : sourceMap);
|
|
216
278
|
} catch (error) {
|
|
217
279
|
console.error("[@flairjs/webpack-loader]", error);
|
|
218
280
|
callback(error, source, sourceMap);
|
package/dist/esm/index.js
CHANGED
|
@@ -37,8 +37,33 @@ function tokensToCSSVars(tokens, prefix = []) {
|
|
|
37
37
|
}
|
|
38
38
|
return css$1;
|
|
39
39
|
}
|
|
40
|
+
var Store = class {
|
|
41
|
+
fileNameToGeneratedCssNameMap = /* @__PURE__ */ new Map();
|
|
42
|
+
lastThemeUpdate = Date.now();
|
|
43
|
+
userTheme = /* @__PURE__ */ new Map();
|
|
44
|
+
getUserTheme() {
|
|
45
|
+
return this.userTheme.get(this.lastThemeUpdate) ?? null;
|
|
46
|
+
}
|
|
47
|
+
setUserTheme(theme) {
|
|
48
|
+
this.userTheme.set(this.lastThemeUpdate, theme);
|
|
49
|
+
}
|
|
50
|
+
getLastThemeUpdate() {
|
|
51
|
+
return this.lastThemeUpdate;
|
|
52
|
+
}
|
|
53
|
+
setLastThemeUpdate(timestamp) {
|
|
54
|
+
this.lastThemeUpdate = timestamp;
|
|
55
|
+
}
|
|
56
|
+
setFileNameToGeneratedCssNameMap(fileName, generatedCssName) {
|
|
57
|
+
this.fileNameToGeneratedCssNameMap.set(fileName, generatedCssName);
|
|
58
|
+
}
|
|
59
|
+
getGeneratedCssName(fileName) {
|
|
60
|
+
return this.fileNameToGeneratedCssNameMap.get(fileName);
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
const store = new Store();
|
|
40
64
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
41
|
-
const getUserTheme = async () => {
|
|
65
|
+
const getUserTheme = async (options) => {
|
|
66
|
+
if (store.getUserTheme() && !options?.ignoreCache) return store.getUserTheme();
|
|
42
67
|
try {
|
|
43
68
|
let userThemeFilePath = path$1.resolve(process.cwd(), "flair.theme.ts");
|
|
44
69
|
if (!existsSync$1(userThemeFilePath)) userThemeFilePath = path$1.resolve(process.cwd(), "flair.theme.js");
|
|
@@ -54,10 +79,17 @@ const getUserTheme = async () => {
|
|
|
54
79
|
});
|
|
55
80
|
const cacheBuster = Date.now();
|
|
56
81
|
const userTheme = await import(`${pathToFileURL(outFile).href}?update=${cacheBuster}`);
|
|
57
|
-
if (userTheme.default)
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
82
|
+
if (userTheme.default) {
|
|
83
|
+
store.setUserTheme({
|
|
84
|
+
theme: userTheme.default,
|
|
85
|
+
originalPath: userThemeFilePath
|
|
86
|
+
});
|
|
87
|
+
return {
|
|
88
|
+
theme: userTheme.default,
|
|
89
|
+
originalPath: userThemeFilePath
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
store.setUserTheme(null);
|
|
61
93
|
return null;
|
|
62
94
|
} catch (error) {
|
|
63
95
|
console.error("Error loading user theme:", error);
|
|
@@ -65,57 +97,73 @@ const getUserTheme = async () => {
|
|
|
65
97
|
}
|
|
66
98
|
};
|
|
67
99
|
const require = module.createRequire(import.meta.url);
|
|
68
|
-
|
|
69
|
-
* Initialize the shared plugin context
|
|
70
|
-
*/
|
|
71
|
-
async function initializeSharedContext(options = {}) {
|
|
72
|
-
const { buildThemeFile } = options;
|
|
73
|
-
const fileNameToGeneratedCssNameMap = /* @__PURE__ */ new Map();
|
|
100
|
+
const getGeneratedCssDir = () => {
|
|
74
101
|
const flairThemeFile = require.resolve("@flairjs/client/theme.css");
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
102
|
+
return path.resolve(flairThemeFile, "../generated-css");
|
|
103
|
+
};
|
|
104
|
+
const setupGeneratedCssDir = async (options) => {
|
|
105
|
+
const flairGeneratedCssDir = getGeneratedCssDir();
|
|
106
|
+
const { clearExisting = true } = options ?? {};
|
|
107
|
+
try {
|
|
108
|
+
if (!existsSync(flairGeneratedCssDir)) await mkdir(flairGeneratedCssDir);
|
|
109
|
+
else if (clearExisting) {
|
|
110
|
+
await rm(flairGeneratedCssDir, {
|
|
111
|
+
recursive: true,
|
|
112
|
+
force: true
|
|
113
|
+
});
|
|
114
|
+
await mkdir(flairGeneratedCssDir);
|
|
115
|
+
}
|
|
116
|
+
} catch (err) {
|
|
117
|
+
if (err?.code === "EEXIST") return flairGeneratedCssDir;
|
|
118
|
+
else if (existsSync(flairGeneratedCssDir)) return flairGeneratedCssDir;
|
|
119
|
+
console.error(`[flairjs] Could not create generated CSS directory: ${flairGeneratedCssDir}`, err);
|
|
120
|
+
return null;
|
|
83
121
|
}
|
|
122
|
+
return flairGeneratedCssDir;
|
|
123
|
+
};
|
|
124
|
+
const setupUserThemeFile = async ({ buildThemeFile, onThemeFileChange }) => {
|
|
125
|
+
const flairThemeFile = require.resolve("@flairjs/client/theme.css");
|
|
84
126
|
let userTheme = await getUserTheme();
|
|
85
127
|
const buildThemeCSS = buildThemeFile ?? buildThemeTokens;
|
|
86
128
|
if (userTheme) {
|
|
87
129
|
const themeCSS = buildThemeCSS(userTheme.theme);
|
|
130
|
+
store.setLastThemeUpdate(Date.now());
|
|
88
131
|
await writeFile(flairThemeFile, themeCSS, "utf-8");
|
|
89
132
|
watch(userTheme.originalPath, async () => {
|
|
90
133
|
userTheme = await getUserTheme();
|
|
134
|
+
store.setLastThemeUpdate(Date.now());
|
|
91
135
|
if (!userTheme) return;
|
|
92
136
|
const themeCSS$1 = buildThemeCSS(userTheme.theme);
|
|
137
|
+
onThemeFileChange?.();
|
|
93
138
|
await writeFile(flairThemeFile, themeCSS$1, "utf-8");
|
|
94
139
|
});
|
|
95
140
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
141
|
+
return userTheme;
|
|
142
|
+
};
|
|
143
|
+
const removeOutdatedCssFiles = async (sourceFilePath, cssFilePath, { flairGeneratedCssDir, clearInstantly = false }) => {
|
|
144
|
+
const previousGeneratedCssName = store.getGeneratedCssName(sourceFilePath);
|
|
145
|
+
if (previousGeneratedCssName && previousGeneratedCssName !== cssFilePath) {
|
|
146
|
+
if (clearInstantly) {
|
|
147
|
+
await rm(path.join(flairGeneratedCssDir, previousGeneratedCssName), { force: true });
|
|
148
|
+
store.setFileNameToGeneratedCssNameMap(sourceFilePath, cssFilePath);
|
|
149
|
+
return;
|
|
102
150
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
refreshCssFile
|
|
110
|
-
};
|
|
111
|
-
}
|
|
151
|
+
setTimeout(() => {
|
|
152
|
+
rm(path.join(flairGeneratedCssDir, previousGeneratedCssName), { force: true });
|
|
153
|
+
}, 2e3);
|
|
154
|
+
}
|
|
155
|
+
store.setFileNameToGeneratedCssNameMap(sourceFilePath, cssFilePath);
|
|
156
|
+
};
|
|
112
157
|
function shouldProcessFile(id, include, exclude) {
|
|
113
|
-
const isIncluded = picomatch(include
|
|
114
|
-
const isExcluded = picomatch(exclude
|
|
115
|
-
if (!isIncluded(id)) return false;
|
|
116
|
-
if (isExcluded(id)) return false;
|
|
158
|
+
const isIncluded = picomatch(include ?? ["**/*.{js,ts,jsx,tsx}"]);
|
|
159
|
+
const isExcluded = picomatch(exclude ?? ["**/node_modules/**"]);
|
|
160
|
+
if (!isIncluded(normalizeFilePath(id))) return false;
|
|
161
|
+
if (isExcluded(normalizeFilePath(id))) return false;
|
|
117
162
|
return true;
|
|
118
163
|
}
|
|
164
|
+
function normalizeFilePath(filePath) {
|
|
165
|
+
return filePath.replace(/\\/g, "/");
|
|
166
|
+
}
|
|
119
167
|
const colors = {
|
|
120
168
|
reset: "\x1B[0m",
|
|
121
169
|
fg: {
|
|
@@ -157,28 +205,42 @@ const transformCode$1 = (code, filePath, options) => {
|
|
|
157
205
|
|
|
158
206
|
//#endregion
|
|
159
207
|
//#region src/index.ts
|
|
208
|
+
let initialized = false;
|
|
160
209
|
async function flairJsLoader(source, sourceMap) {
|
|
161
210
|
const callback = this.async();
|
|
211
|
+
const options = this.getOptions() || {};
|
|
162
212
|
if (!callback) {
|
|
163
213
|
console.error("@flairjs/webpack-loader requires async support");
|
|
164
214
|
return;
|
|
165
215
|
}
|
|
166
|
-
const options = this.getOptions() || {};
|
|
167
|
-
const context = await initializeSharedContext(options);
|
|
168
216
|
const fileName = this.resourcePath;
|
|
169
217
|
if (!shouldProcessFile(fileName, options?.include, options?.exclude)) return callback(null, source, sourceMap);
|
|
218
|
+
let cssGeneratedDir = null;
|
|
219
|
+
let userTheme = null;
|
|
220
|
+
if (!initialized) {
|
|
221
|
+
cssGeneratedDir = await setupGeneratedCssDir();
|
|
222
|
+
userTheme = await setupUserThemeFile({ buildThemeFile: options.buildThemeFile });
|
|
223
|
+
initialized = true;
|
|
224
|
+
} else {
|
|
225
|
+
cssGeneratedDir = getGeneratedCssDir();
|
|
226
|
+
userTheme = await getUserTheme();
|
|
227
|
+
}
|
|
228
|
+
if (!cssGeneratedDir) {
|
|
229
|
+
console.error("[flairjs] Could not find generated CSS directory. Skipping processing.");
|
|
230
|
+
return callback(null, source, sourceMap);
|
|
231
|
+
}
|
|
170
232
|
try {
|
|
171
233
|
const result = transformCode$1(source, fileName, {
|
|
172
234
|
appendTimestampToCssFile: true,
|
|
173
235
|
classNameList: options?.classNameList,
|
|
174
236
|
cssPreprocessor: options?.cssPreprocessor ? (css) => options.cssPreprocessor(css, fileName) : void 0,
|
|
175
|
-
theme:
|
|
176
|
-
useTheme: !!
|
|
177
|
-
cssOutDir:
|
|
237
|
+
theme: userTheme?.theme,
|
|
238
|
+
useTheme: !!userTheme,
|
|
239
|
+
cssOutDir: cssGeneratedDir
|
|
178
240
|
});
|
|
179
241
|
if (!result) return callback(null, source, sourceMap);
|
|
180
|
-
if (result.generatedCssName)
|
|
181
|
-
callback(null, result.code, result.
|
|
242
|
+
if (result.generatedCssName) removeOutdatedCssFiles(fileName, result.generatedCssName, { flairGeneratedCssDir: cssGeneratedDir });
|
|
243
|
+
callback(null, result.code, result.sourcemap ? JSON.parse(result.sourcemap ?? "{}") : sourceMap);
|
|
182
244
|
} catch (error) {
|
|
183
245
|
console.error("[@flairjs/webpack-loader]", error);
|
|
184
246
|
callback(error, source, sourceMap);
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,6 +1,33 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { LoaderContext } from
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export default
|
|
6
|
-
|
|
1
|
+
import { FlairThemeConfig } from '@flairjs/client';
|
|
2
|
+
import { LoaderContext } from 'webpack';
|
|
3
|
+
|
|
4
|
+
declare function flairJsLoader(this: LoaderContext<FlairJsWebpackLoaderOptions>, source: string, sourceMap: string): Promise<void>;
|
|
5
|
+
export default flairJsLoader;
|
|
6
|
+
|
|
7
|
+
declare interface FlairJsWebpackLoaderOptions extends SharedPluginOptions {
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
declare interface SharedPluginOptions {
|
|
11
|
+
/**
|
|
12
|
+
* Preprocess the extracted CSS before it is passed to lightningcss
|
|
13
|
+
* @experimental
|
|
14
|
+
* @param css the extracted css
|
|
15
|
+
* @param id the id of the file being processed
|
|
16
|
+
* @returns the processed css
|
|
17
|
+
*/
|
|
18
|
+
cssPreprocessor?: (css: string, id: string) => string;
|
|
19
|
+
include?: string | string[];
|
|
20
|
+
exclude?: string | string[];
|
|
21
|
+
/**
|
|
22
|
+
* Override the default theme file content based on the user theme
|
|
23
|
+
* @param theme the user theme
|
|
24
|
+
* @returns the theme file content
|
|
25
|
+
*/
|
|
26
|
+
buildThemeFile?: (theme: FlairThemeConfig) => string;
|
|
27
|
+
/**
|
|
28
|
+
* List of class names used in the project. Supports regex.
|
|
29
|
+
*/
|
|
30
|
+
classNameList?: string[];
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export { }
|
package/package.json
CHANGED
|
@@ -1,17 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flairjs/webpack-loader",
|
|
3
|
-
"version": "0.0.1-beta.
|
|
4
|
-
"type": "module",
|
|
5
|
-
"exports": {
|
|
6
|
-
".": {
|
|
7
|
-
"types": "./dist/types/index.d.ts",
|
|
8
|
-
"import": "./dist/esm/index.js",
|
|
9
|
-
"require": "./dist/cjs/index.js"
|
|
10
|
-
},
|
|
11
|
-
"./cached-css/*": {
|
|
12
|
-
"import": "./dist/.cache/*"
|
|
13
|
-
}
|
|
14
|
-
},
|
|
3
|
+
"version": "0.0.1-beta.7",
|
|
15
4
|
"main": "./dist/cjs/index.js",
|
|
16
5
|
"module": "./dist/esm/index.js",
|
|
17
6
|
"types": "./dist/types/index.d.ts",
|
|
@@ -24,20 +13,25 @@
|
|
|
24
13
|
},
|
|
25
14
|
"peerDependencies": {
|
|
26
15
|
"webpack": ">=5.0.0",
|
|
27
|
-
"@flairjs/core": "0.0.1-beta.
|
|
16
|
+
"@flairjs/core": "0.0.1-beta.6"
|
|
28
17
|
},
|
|
29
18
|
"devDependencies": {
|
|
30
|
-
"@biomejs/biome": "^
|
|
31
|
-
"@
|
|
19
|
+
"@biomejs/biome": "^2.2.4",
|
|
20
|
+
"@microsoft/api-extractor": "^7.52.13",
|
|
32
21
|
"@types/node": "^22.8.1",
|
|
22
|
+
"rimraf": "^6.0.1",
|
|
33
23
|
"rolldown": "1.0.0-beta.37",
|
|
34
24
|
"typescript": "^5.8.2",
|
|
35
25
|
"webpack": "^5.101.0",
|
|
36
|
-
"@flairjs/bundler-shared": "0.0.1-beta.
|
|
37
|
-
"@flairjs/core": "0.0.1-beta.
|
|
26
|
+
"@flairjs/bundler-shared": "0.0.1-beta.10",
|
|
27
|
+
"@flairjs/core": "0.0.1-beta.6"
|
|
28
|
+
},
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"esbuild": "^0.25.10",
|
|
31
|
+
"picomatch": "^4.0.3"
|
|
38
32
|
},
|
|
39
33
|
"scripts": {
|
|
40
|
-
"build": "rolldown -c",
|
|
34
|
+
"build": "rimraf dist && tsc && api-extractor run --local && rolldown -c && rimraf dist/types-temp",
|
|
41
35
|
"check": "biome check --write",
|
|
42
36
|
"dev": "rolldown -w -c",
|
|
43
37
|
"format": "biome format --write"
|