@plumeria/webpack-plugin 0.9.0 → 0.11.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/dist/index.d.ts +3 -2
- package/dist/index.js +36 -6
- package/dist/{types-table.d.ts → types.d.ts} +2 -1
- package/dist/virtual-css-loader.js +129 -107
- package/package.json +6 -6
- /package/dist/{create-css.d.ts → create.d.ts} +0 -0
- /package/dist/{create-css.js → create.js} +0 -0
- /package/dist/{types-table.js → types.js} +0 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) zss-in-js contributer
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { Compiler } from 'webpack';
|
|
2
2
|
export declare class PlumeriaPlugin {
|
|
3
|
-
private
|
|
3
|
+
private stylesByFile;
|
|
4
4
|
private virtualModules?;
|
|
5
5
|
apply(compiler: Compiler): void;
|
|
6
|
-
registerStyle(virtualFileName: string,
|
|
6
|
+
registerStyle(virtualFileName: string, styles: any): void;
|
|
7
|
+
private generateOrderedCSS;
|
|
7
8
|
}
|
package/dist/index.js
CHANGED
|
@@ -8,27 +8,57 @@ const webpack_1 = require("webpack");
|
|
|
8
8
|
const webpack_virtual_modules_1 = __importDefault(require("webpack-virtual-modules"));
|
|
9
9
|
const PLUGIN_NAME = 'PlumeriaPlugin';
|
|
10
10
|
class PlumeriaPlugin {
|
|
11
|
-
|
|
11
|
+
stylesByFile = new Map();
|
|
12
12
|
virtualModules;
|
|
13
13
|
apply(compiler) {
|
|
14
14
|
this.virtualModules = new webpack_virtual_modules_1.default();
|
|
15
15
|
this.virtualModules.apply(compiler);
|
|
16
16
|
compiler.hooks.compile.tap(PLUGIN_NAME, () => {
|
|
17
|
-
this.
|
|
17
|
+
this.stylesByFile.clear();
|
|
18
18
|
});
|
|
19
19
|
compiler.hooks.thisCompilation.tap(PLUGIN_NAME, (compilation) => {
|
|
20
20
|
compilation.hooks.processAssets.tapPromise({
|
|
21
21
|
name: PLUGIN_NAME,
|
|
22
22
|
stage: webpack_1.Compilation.PROCESS_ASSETS_STAGE_ADDITIONS,
|
|
23
23
|
}, async () => {
|
|
24
|
-
const
|
|
25
|
-
compilation.emitAsset('plumeria.css', new webpack_1.sources.RawSource(
|
|
24
|
+
const css = this.generateOrderedCSS(this.stylesByFile);
|
|
25
|
+
compilation.emitAsset('plumeria.css', new webpack_1.sources.RawSource(css));
|
|
26
26
|
});
|
|
27
27
|
});
|
|
28
28
|
}
|
|
29
|
-
registerStyle(virtualFileName,
|
|
30
|
-
this.
|
|
29
|
+
registerStyle(virtualFileName, styles) {
|
|
30
|
+
this.stylesByFile.set(virtualFileName, styles);
|
|
31
|
+
const css = this.generateOrderedCSS(this.stylesByFile);
|
|
31
32
|
this.virtualModules?.writeModule(virtualFileName, css);
|
|
32
33
|
}
|
|
34
|
+
generateOrderedCSS(styles) {
|
|
35
|
+
const allStyles = Array.from(styles.values());
|
|
36
|
+
const globalStyles = [];
|
|
37
|
+
const keyframeStylesSet = new Set();
|
|
38
|
+
const varStylesSet = new Set();
|
|
39
|
+
const themeStylesSet = new Set();
|
|
40
|
+
const baseStyles = [];
|
|
41
|
+
for (const s of allStyles) {
|
|
42
|
+
if (s.globalStyles)
|
|
43
|
+
globalStyles.push(s.globalStyles);
|
|
44
|
+
if (s.keyframeStyles)
|
|
45
|
+
keyframeStylesSet.add(s.keyframeStyles);
|
|
46
|
+
if (s.varStyles)
|
|
47
|
+
varStylesSet.add(s.varStyles);
|
|
48
|
+
if (s.themeStyles)
|
|
49
|
+
themeStylesSet.add(s.themeStyles);
|
|
50
|
+
if (s.baseStyles)
|
|
51
|
+
baseStyles.push(s.baseStyles);
|
|
52
|
+
}
|
|
53
|
+
return [
|
|
54
|
+
...globalStyles,
|
|
55
|
+
...Array.from(keyframeStylesSet),
|
|
56
|
+
...Array.from(varStylesSet),
|
|
57
|
+
...Array.from(themeStylesSet),
|
|
58
|
+
...baseStyles,
|
|
59
|
+
]
|
|
60
|
+
.filter(Boolean)
|
|
61
|
+
.join('\n');
|
|
62
|
+
}
|
|
33
63
|
}
|
|
34
64
|
exports.PlumeriaPlugin = PlumeriaPlugin;
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
type CSSPrimitive = string | number | boolean | null;
|
|
2
2
|
type ParseErrorString = `[unresolved]` | `[unresolved identifier]` | `[unsupported value type]` | `[unresolved: ${string}]` | `[unresolved member expression]`;
|
|
3
|
-
type CSSValue = CSSPrimitive | CSSObject | ParseErrorString;
|
|
3
|
+
export type CSSValue = CSSPrimitive | CSSObject | ParseErrorString;
|
|
4
4
|
export type CSSObject = {
|
|
5
5
|
[key: string]: CSSValue;
|
|
6
6
|
};
|
|
7
7
|
export type ConstTable = Record<string, CSSObject | string>;
|
|
8
8
|
export type VariableTable = Record<string, CSSObject>;
|
|
9
|
+
export type ThemeTable = Record<string, CSSObject>;
|
|
9
10
|
export type KeyframesHashTable = Record<string, string>;
|
|
10
11
|
export type KeyframesObjectTable = Record<string, CSSObject>;
|
|
11
12
|
export type DefineVarsObjectTable = Record<string, CSSObject>;
|
|
@@ -39,12 +39,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
39
39
|
exports.default = loader;
|
|
40
40
|
const core_1 = require("@babel/core");
|
|
41
41
|
const t = __importStar(require("@babel/types"));
|
|
42
|
-
const loader_utils_1 = __importDefault(require("loader-utils"));
|
|
43
42
|
const path_1 = __importDefault(require("path"));
|
|
44
43
|
const fs_1 = __importDefault(require("fs"));
|
|
45
|
-
const
|
|
44
|
+
const create_1 = require("./create");
|
|
46
45
|
const glob_1 = require("@rust-gear/glob");
|
|
47
46
|
const zss_engine_1 = require("zss-engine");
|
|
47
|
+
const loader_utils_1 = __importDefault(require("loader-utils"));
|
|
48
48
|
const PROJECT_ROOT = process.cwd().split('node_modules')[0];
|
|
49
49
|
const PATTERN_PATH = path_1.default.join(PROJECT_ROOT, '**/*.{js,jsx,ts,tsx}');
|
|
50
50
|
const GLOB_OPTIONS = {
|
|
@@ -53,11 +53,12 @@ const GLOB_OPTIONS = {
|
|
|
53
53
|
};
|
|
54
54
|
let constTable = {};
|
|
55
55
|
let variableTable = {};
|
|
56
|
+
let themeTable = {};
|
|
56
57
|
let keyframesHashTable = {};
|
|
57
58
|
let keyframesObjectTable = {};
|
|
58
59
|
let defineVarsObjectTable = {};
|
|
59
60
|
let defineThemeObjectTable = {};
|
|
60
|
-
function objectExpressionToObject(node, constTable, keyframesHashTable, variableTable) {
|
|
61
|
+
function objectExpressionToObject(node, constTable, keyframesHashTable, variableTable, themeTable) {
|
|
61
62
|
const obj = {};
|
|
62
63
|
node.properties.forEach((prop) => {
|
|
63
64
|
if (!t.isObjectProperty(prop))
|
|
@@ -77,6 +78,11 @@ function objectExpressionToObject(node, constTable, keyframesHashTable, variable
|
|
|
77
78
|
obj[key] = resolvedVariable;
|
|
78
79
|
return;
|
|
79
80
|
}
|
|
81
|
+
const resolvedTheme = resolveThemeTableMemberExpressionByNode(val, themeTable);
|
|
82
|
+
if (resolvedTheme !== undefined) {
|
|
83
|
+
obj[key] = resolvedTheme;
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
80
86
|
}
|
|
81
87
|
if (t.isStringLiteral(val) ||
|
|
82
88
|
t.isNumericLiteral(val) ||
|
|
@@ -87,7 +93,7 @@ function objectExpressionToObject(node, constTable, keyframesHashTable, variable
|
|
|
87
93
|
obj[key] = evaluateUnaryExpression(val);
|
|
88
94
|
}
|
|
89
95
|
else if (t.isObjectExpression(val)) {
|
|
90
|
-
obj[key] = objectExpressionToObject(val, constTable, keyframesHashTable, variableTable);
|
|
96
|
+
obj[key] = objectExpressionToObject(val, constTable, keyframesHashTable, variableTable, themeTable);
|
|
91
97
|
}
|
|
92
98
|
else if (t.isMemberExpression(val)) {
|
|
93
99
|
const resolved = resolveConstTableMemberExpression(val, constTable);
|
|
@@ -195,6 +201,10 @@ function evaluateExpression(node, constTable, variableTable) {
|
|
|
195
201
|
if (resolvedVar !== undefined) {
|
|
196
202
|
return resolvedVar;
|
|
197
203
|
}
|
|
204
|
+
const resolvedTheme = resolveThemeTableMemberExpressionByNode(node, themeTable);
|
|
205
|
+
if (resolvedTheme !== undefined) {
|
|
206
|
+
return resolvedTheme;
|
|
207
|
+
}
|
|
198
208
|
return `[unresolved member expression]`;
|
|
199
209
|
}
|
|
200
210
|
if (t.isBinaryExpression(node)) {
|
|
@@ -249,32 +259,65 @@ function resolveConstTableMemberExpression(node, constTable) {
|
|
|
249
259
|
}
|
|
250
260
|
return undefined;
|
|
251
261
|
}
|
|
252
|
-
function resolveVariableTableMemberExpressionByNode(node, variableTable) {
|
|
262
|
+
function resolveVariableTableMemberExpressionByNode(node, variableTable, asObject = false) {
|
|
253
263
|
if (t.isIdentifier(node)) {
|
|
254
|
-
|
|
264
|
+
if (asObject && typeof variableTable[node.name] === 'object') {
|
|
265
|
+
return { ...variableTable[node.name] };
|
|
266
|
+
}
|
|
267
|
+
const cssVarName = (0, zss_engine_1.camelToKebabCase)(node.name);
|
|
268
|
+
return `var(--${cssVarName})`;
|
|
255
269
|
}
|
|
256
|
-
if (t.isMemberExpression(node)) {
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
270
|
+
if (t.isMemberExpression(node) && t.isIdentifier(node.object)) {
|
|
271
|
+
const varName = node.object.name;
|
|
272
|
+
let key;
|
|
273
|
+
if (t.isIdentifier(node.property)) {
|
|
274
|
+
key = node.property.name;
|
|
275
|
+
}
|
|
276
|
+
else if (t.isStringLiteral(node.property)) {
|
|
277
|
+
key = node.property.value;
|
|
278
|
+
}
|
|
279
|
+
if (key &&
|
|
280
|
+
variableTable[varName] &&
|
|
281
|
+
variableTable[varName][key] !== undefined) {
|
|
282
|
+
if (asObject) {
|
|
283
|
+
return { [key]: variableTable[varName][key] };
|
|
265
284
|
}
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
285
|
+
const cssVarName = (0, zss_engine_1.camelToKebabCase)(key);
|
|
286
|
+
return `var(--${cssVarName})`;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
return undefined;
|
|
290
|
+
}
|
|
291
|
+
function resolveThemeTableMemberExpressionByNode(node, themeTable, asObject = false) {
|
|
292
|
+
if (t.isIdentifier(node)) {
|
|
293
|
+
if (asObject && typeof themeTable[node.name] === 'object') {
|
|
294
|
+
return { ...themeTable[node.name] };
|
|
295
|
+
}
|
|
296
|
+
const cssVarName = (0, zss_engine_1.camelToKebabCase)(node.name);
|
|
297
|
+
return `var(--${cssVarName})`;
|
|
298
|
+
}
|
|
299
|
+
if (t.isMemberExpression(node) && t.isIdentifier(node.object)) {
|
|
300
|
+
const varName = node.object.name;
|
|
301
|
+
let key;
|
|
302
|
+
if (t.isIdentifier(node.property)) {
|
|
303
|
+
key = node.property.name;
|
|
304
|
+
}
|
|
305
|
+
else if (t.isStringLiteral(node.property)) {
|
|
306
|
+
key = node.property.value;
|
|
307
|
+
}
|
|
308
|
+
if (key && themeTable[varName] && themeTable[varName][key] !== undefined) {
|
|
309
|
+
if (asObject) {
|
|
310
|
+
return { [key]: themeTable[varName][key] };
|
|
270
311
|
}
|
|
312
|
+
const cssVarName = (0, zss_engine_1.camelToKebabCase)(key);
|
|
313
|
+
return `var(--${cssVarName})`;
|
|
271
314
|
}
|
|
272
315
|
}
|
|
273
316
|
return undefined;
|
|
274
317
|
}
|
|
275
318
|
function scanForDefineConsts() {
|
|
276
|
-
const files = (0, glob_1.globSync)(PATTERN_PATH, GLOB_OPTIONS);
|
|
277
319
|
const constTableLocal = {};
|
|
320
|
+
const files = (0, glob_1.globSync)(PATTERN_PATH, GLOB_OPTIONS);
|
|
278
321
|
for (const filePath of files) {
|
|
279
322
|
if (!isCSSDefineFile(filePath, 'defineConsts'))
|
|
280
323
|
continue;
|
|
@@ -309,7 +352,7 @@ function scanForDefineConsts() {
|
|
|
309
352
|
decl.init.arguments.length === 1 &&
|
|
310
353
|
t.isObjectExpression(decl.init.arguments[0])) {
|
|
311
354
|
const varName = decl.id.name;
|
|
312
|
-
const obj = objectExpressionToObject(decl.init.arguments[0], constTableLocal, keyframesHashTable, variableTable);
|
|
355
|
+
const obj = objectExpressionToObject(decl.init.arguments[0], constTableLocal, keyframesHashTable, variableTable, themeTable);
|
|
313
356
|
constTableLocal[varName] = obj;
|
|
314
357
|
}
|
|
315
358
|
}
|
|
@@ -318,9 +361,9 @@ function scanForDefineConsts() {
|
|
|
318
361
|
return constTableLocal;
|
|
319
362
|
}
|
|
320
363
|
function scanForKeyframes() {
|
|
321
|
-
const files = (0, glob_1.globSync)(PATTERN_PATH, GLOB_OPTIONS);
|
|
322
364
|
const keyframesHashTableLocal = {};
|
|
323
365
|
const keyframesObjectTableLocal = {};
|
|
366
|
+
const files = (0, glob_1.globSync)(PATTERN_PATH, GLOB_OPTIONS);
|
|
324
367
|
for (const filePath of files) {
|
|
325
368
|
if (!isCSSDefineFile(filePath, 'keyframes'))
|
|
326
369
|
continue;
|
|
@@ -355,7 +398,7 @@ function scanForKeyframes() {
|
|
|
355
398
|
decl.init.arguments.length === 1 &&
|
|
356
399
|
t.isObjectExpression(decl.init.arguments[0])) {
|
|
357
400
|
const varName = decl.id.name;
|
|
358
|
-
const obj = objectExpressionToObject(decl.init.arguments[0], constTable, keyframesHashTableLocal, variableTable);
|
|
401
|
+
const obj = objectExpressionToObject(decl.init.arguments[0], constTable, keyframesHashTableLocal, variableTable, themeTable);
|
|
359
402
|
const hash = (0, zss_engine_1.genBase36Hash)(obj, 1, 8);
|
|
360
403
|
keyframesHashTableLocal[varName] = hash;
|
|
361
404
|
keyframesObjectTableLocal[hash] = obj;
|
|
@@ -369,9 +412,9 @@ function scanForKeyframes() {
|
|
|
369
412
|
};
|
|
370
413
|
}
|
|
371
414
|
function scanForDefineVars() {
|
|
372
|
-
const files = (0, glob_1.globSync)(PATTERN_PATH, GLOB_OPTIONS);
|
|
373
415
|
const variableTableLocal = {};
|
|
374
416
|
const defineVarsObjectTableLocal = {};
|
|
417
|
+
const files = (0, glob_1.globSync)(PATTERN_PATH, GLOB_OPTIONS);
|
|
375
418
|
for (const filePath of files) {
|
|
376
419
|
if (!isCSSDefineFile(filePath, 'defineVars'))
|
|
377
420
|
continue;
|
|
@@ -406,7 +449,7 @@ function scanForDefineVars() {
|
|
|
406
449
|
decl.init.arguments.length === 1 &&
|
|
407
450
|
t.isObjectExpression(decl.init.arguments[0])) {
|
|
408
451
|
const varName = decl.id.name;
|
|
409
|
-
const obj = objectExpressionToObject(decl.init.arguments[0], constTable, keyframesHashTable, variableTableLocal);
|
|
452
|
+
const obj = objectExpressionToObject(decl.init.arguments[0], constTable, keyframesHashTable, variableTableLocal, themeTable);
|
|
410
453
|
variableTableLocal[varName] = obj;
|
|
411
454
|
defineVarsObjectTableLocal[varName] = obj;
|
|
412
455
|
}
|
|
@@ -416,9 +459,9 @@ function scanForDefineVars() {
|
|
|
416
459
|
return { variableTableLocal, defineVarsObjectTableLocal };
|
|
417
460
|
}
|
|
418
461
|
function scanForDefineTheme() {
|
|
419
|
-
const
|
|
420
|
-
const variableTableLocal = {};
|
|
462
|
+
const themeTableLocal = {};
|
|
421
463
|
const defineThemeObjectTableLocal = {};
|
|
464
|
+
const files = (0, glob_1.globSync)(PATTERN_PATH, GLOB_OPTIONS);
|
|
422
465
|
for (const filePath of files) {
|
|
423
466
|
if (!isCSSDefineFile(filePath, 'defineTheme'))
|
|
424
467
|
continue;
|
|
@@ -453,14 +496,14 @@ function scanForDefineTheme() {
|
|
|
453
496
|
decl.init.arguments.length === 1 &&
|
|
454
497
|
t.isObjectExpression(decl.init.arguments[0])) {
|
|
455
498
|
const varName = decl.id.name;
|
|
456
|
-
const obj = objectExpressionToObject(decl.init.arguments[0], constTable, keyframesHashTable,
|
|
457
|
-
|
|
499
|
+
const obj = objectExpressionToObject(decl.init.arguments[0], constTable, keyframesHashTable, variableTable, themeTableLocal);
|
|
500
|
+
themeTableLocal[varName] = obj;
|
|
458
501
|
defineThemeObjectTableLocal[varName] = obj;
|
|
459
502
|
}
|
|
460
503
|
}
|
|
461
504
|
}
|
|
462
505
|
}
|
|
463
|
-
return {
|
|
506
|
+
return { themeTableLocal, defineThemeObjectTableLocal };
|
|
464
507
|
}
|
|
465
508
|
function isCSSDefineFile(filePath, target) {
|
|
466
509
|
if (fs_1.default.statSync(filePath).isDirectory())
|
|
@@ -500,17 +543,16 @@ function isCSSDefineFile(filePath, target) {
|
|
|
500
543
|
}
|
|
501
544
|
function loader(source) {
|
|
502
545
|
const callback = this.async();
|
|
546
|
+
this.clearDependencies();
|
|
503
547
|
this.addDependency(this.resourcePath);
|
|
504
548
|
constTable = scanForDefineConsts.call(this);
|
|
505
549
|
const { keyframesHashTableLocal, keyframesObjectTableLocal } = scanForKeyframes.call(this);
|
|
506
550
|
keyframesHashTable = keyframesHashTableLocal;
|
|
507
551
|
keyframesObjectTable = keyframesObjectTableLocal;
|
|
508
|
-
const { variableTableLocal
|
|
509
|
-
const {
|
|
510
|
-
variableTable =
|
|
511
|
-
|
|
512
|
-
variableTable[k] = themeTable[k];
|
|
513
|
-
}
|
|
552
|
+
const { variableTableLocal, defineVarsObjectTableLocal } = scanForDefineVars.call(this);
|
|
553
|
+
const { themeTableLocal, defineThemeObjectTableLocal } = scanForDefineTheme.call(this);
|
|
554
|
+
variableTable = variableTableLocal;
|
|
555
|
+
themeTable = themeTableLocal;
|
|
514
556
|
defineVarsObjectTable = defineVarsObjectTableLocal;
|
|
515
557
|
defineThemeObjectTable = defineThemeObjectTableLocal;
|
|
516
558
|
let extractedObject = null;
|
|
@@ -525,53 +567,31 @@ function loader(source) {
|
|
|
525
567
|
],
|
|
526
568
|
});
|
|
527
569
|
}
|
|
528
|
-
catch (
|
|
529
|
-
console.
|
|
530
|
-
|
|
531
|
-
return callback(null, source);
|
|
532
|
-
return source;
|
|
533
|
-
}
|
|
534
|
-
if (!ast) {
|
|
535
|
-
console.warn('[virtual-css-loader] parseSync returned null');
|
|
536
|
-
if (callback)
|
|
537
|
-
return callback(null, source);
|
|
538
|
-
return source;
|
|
570
|
+
catch (err) {
|
|
571
|
+
console.log(err);
|
|
572
|
+
return callback(null, source);
|
|
539
573
|
}
|
|
574
|
+
if (!ast)
|
|
575
|
+
return callback(null, source);
|
|
540
576
|
const localConsts = collectLocalConsts(ast);
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
constTable[k] = localConsts[k];
|
|
544
|
-
}
|
|
545
|
-
}
|
|
546
|
-
const plugin = {
|
|
577
|
+
Object.assign(constTable, localConsts);
|
|
578
|
+
const pluginAst = {
|
|
547
579
|
visitor: {
|
|
548
580
|
CallExpression(path) {
|
|
549
581
|
const callee = path.node.callee;
|
|
550
582
|
if (t.isMemberExpression(callee) &&
|
|
551
|
-
t.isIdentifier(callee.object) &&
|
|
552
|
-
callee.object.name === 'css' &&
|
|
583
|
+
t.isIdentifier(callee.object, { name: 'css' }) &&
|
|
553
584
|
t.isIdentifier(callee.property)) {
|
|
554
585
|
const args = path.node.arguments;
|
|
555
586
|
if (callee.property.name === 'create' &&
|
|
556
587
|
args.length === 1 &&
|
|
557
588
|
t.isObjectExpression(args[0])) {
|
|
558
|
-
|
|
559
|
-
extractedObject = objectExpressionToObject(args[0], constTable, keyframesHashTable, variableTable);
|
|
560
|
-
}
|
|
561
|
-
catch (e) {
|
|
562
|
-
console.warn('[virtual-css-loader] Failed to build object from AST:', e);
|
|
563
|
-
}
|
|
589
|
+
extractedObject = objectExpressionToObject(args[0], constTable, keyframesHashTable, variableTable, themeTable);
|
|
564
590
|
}
|
|
565
591
|
if (callee.property.name === 'global' &&
|
|
566
592
|
args.length === 1 &&
|
|
567
593
|
t.isObjectExpression(args[0])) {
|
|
568
|
-
|
|
569
|
-
const globalObj = objectExpressionToObject(args[0], constTable, keyframesHashTable, variableTable);
|
|
570
|
-
extractedGlobalObjects.push(globalObj);
|
|
571
|
-
}
|
|
572
|
-
catch (e) {
|
|
573
|
-
console.warn('[virtual-css-loader] Failed to build global object from AST:', e);
|
|
574
|
-
}
|
|
594
|
+
extractedGlobalObjects.push(objectExpressionToObject(args[0], constTable, keyframesHashTable, variableTable, themeTable));
|
|
575
595
|
}
|
|
576
596
|
}
|
|
577
597
|
},
|
|
@@ -579,52 +599,54 @@ function loader(source) {
|
|
|
579
599
|
};
|
|
580
600
|
(0, core_1.transformFromAstSync)(ast, source, {
|
|
581
601
|
code: false,
|
|
582
|
-
plugins: [
|
|
602
|
+
plugins: [pluginAst],
|
|
583
603
|
configFile: false,
|
|
584
604
|
});
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
}
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
}
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
keyframeCss +
|
|
615
|
-
'\n' +
|
|
616
|
-
varCss +
|
|
617
|
-
'\n' +
|
|
618
|
-
themeCss +
|
|
619
|
-
'\n' +
|
|
620
|
-
css;
|
|
605
|
+
const fileStyles = {};
|
|
606
|
+
if (extractedObject) {
|
|
607
|
+
const base = (0, create_1.createCSS)(extractedObject);
|
|
608
|
+
if (base)
|
|
609
|
+
fileStyles.baseStyles = base;
|
|
610
|
+
}
|
|
611
|
+
if (extractedGlobalObjects.length > 0) {
|
|
612
|
+
fileStyles.globalStyles = extractedGlobalObjects
|
|
613
|
+
.map((obj) => (0, zss_engine_1.transpile)(obj, undefined, '--global').styleSheet)
|
|
614
|
+
.join('\n');
|
|
615
|
+
}
|
|
616
|
+
if (Object.keys(keyframesObjectTable).length > 0) {
|
|
617
|
+
fileStyles.keyframeStyles = Object.entries(keyframesObjectTable)
|
|
618
|
+
.map(([hash, obj]) => (0, zss_engine_1.transpile)({ [`@keyframes ${hash}`]: obj }, undefined, '--global')
|
|
619
|
+
.styleSheet)
|
|
620
|
+
.join('\n');
|
|
621
|
+
}
|
|
622
|
+
if (Object.keys(defineVarsObjectTable).length > 0) {
|
|
623
|
+
fileStyles.varStyles = Object.values(defineVarsObjectTable)
|
|
624
|
+
.map((obj) => (0, zss_engine_1.transpile)((0, create_1.createVars)(obj), undefined, '--global')
|
|
625
|
+
.styleSheet)
|
|
626
|
+
.join('\n');
|
|
627
|
+
}
|
|
628
|
+
if (Object.keys(defineThemeObjectTable).length > 0) {
|
|
629
|
+
fileStyles.themeStyles = Object.values(defineThemeObjectTable)
|
|
630
|
+
.map((obj) => (0, zss_engine_1.transpile)((0, create_1.createTheme)(obj), undefined, '--global')
|
|
631
|
+
.styleSheet)
|
|
632
|
+
.join('\n');
|
|
633
|
+
}
|
|
621
634
|
const virtualCssFileName = loader_utils_1.default.interpolateName(this, '[path][name].[hash:base64:8].virtual.css', {
|
|
622
|
-
content:
|
|
635
|
+
content: JSON.stringify(fileStyles),
|
|
623
636
|
context: this.rootContext,
|
|
624
637
|
});
|
|
625
638
|
const absVirtualCssFileName = path_1.default.resolve(this.rootContext, virtualCssFileName);
|
|
626
639
|
const pluginInstance = this._compiler?.options?.plugins.find((p) => p?.constructor?.name === 'PlumeriaPlugin');
|
|
627
|
-
pluginInstance
|
|
640
|
+
if (pluginInstance) {
|
|
641
|
+
if (!pluginInstance.__plumeriaRegistered) {
|
|
642
|
+
pluginInstance.__plumeriaRegistered = new Set();
|
|
643
|
+
}
|
|
644
|
+
const cache = pluginInstance.__plumeriaRegistered;
|
|
645
|
+
if (!cache.has(absVirtualCssFileName)) {
|
|
646
|
+
cache.add(absVirtualCssFileName);
|
|
647
|
+
pluginInstance.registerStyle(absVirtualCssFileName, fileStyles);
|
|
648
|
+
}
|
|
649
|
+
}
|
|
628
650
|
let importPath = path_1.default.posix.relative(path_1.default.dirname(this.resourcePath), absVirtualCssFileName);
|
|
629
651
|
if (!importPath.startsWith('.')) {
|
|
630
652
|
importPath = './' + importPath;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plumeria/webpack-plugin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0",
|
|
4
4
|
"description": "Plumeria Webpack plugin",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -14,10 +14,6 @@
|
|
|
14
14
|
"files": [
|
|
15
15
|
"dist/"
|
|
16
16
|
],
|
|
17
|
-
"scripts": {
|
|
18
|
-
"build": "rimraf dist && pnpm cjs",
|
|
19
|
-
"cjs": "tsc --project tsconfig.cjs.json"
|
|
20
|
-
},
|
|
21
17
|
"dependencies": {
|
|
22
18
|
"@babel/core": "^7.28.0",
|
|
23
19
|
"@babel/preset-react": "^7.27.1",
|
|
@@ -35,5 +31,9 @@
|
|
|
35
31
|
},
|
|
36
32
|
"publishConfig": {
|
|
37
33
|
"access": "public"
|
|
34
|
+
},
|
|
35
|
+
"scripts": {
|
|
36
|
+
"build": "rimraf dist && pnpm cjs",
|
|
37
|
+
"cjs": "tsc --project tsconfig.cjs.json"
|
|
38
38
|
}
|
|
39
|
-
}
|
|
39
|
+
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|