@plumeria/vite-plugin 6.3.0 → 6.3.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/dist/index.js +11 -9
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -2,7 +2,7 @@ import { createFilter } from 'vite';
|
|
|
2
2
|
import { parseSync } from '@swc/core';
|
|
3
3
|
import path from 'path';
|
|
4
4
|
import { genBase36Hash } from 'zss-engine';
|
|
5
|
-
import { traverse, getStyleRecords, collectLocalConsts, objectExpressionToObject, t, extractOndemandStyles, deepMerge, scanAll, resolveImportPath, } from '@plumeria/utils';
|
|
5
|
+
import { traverse, getStyleRecords, collectLocalConsts, objectExpressionToObject, t, extractOndemandStyles, deepMerge, scanAll, resolveImportPath, optimizer, } from '@plumeria/utils';
|
|
6
6
|
const TARGET_EXTENSIONS = ['ts', 'tsx', 'js', 'jsx'];
|
|
7
7
|
const EXTENSION_PATTERN = /\.(ts|tsx|js|jsx)$/;
|
|
8
8
|
export function plumeria(options = {}) {
|
|
@@ -20,6 +20,7 @@ export function plumeria(options = {}) {
|
|
|
20
20
|
configResolved(resolvedConfig) {
|
|
21
21
|
isDev = resolvedConfig.command === 'serve';
|
|
22
22
|
config = resolvedConfig;
|
|
23
|
+
config.build.cssCodeSplit = false;
|
|
23
24
|
},
|
|
24
25
|
configureServer(_server) {
|
|
25
26
|
if (!isDev)
|
|
@@ -49,7 +50,7 @@ export function plumeria(options = {}) {
|
|
|
49
50
|
.filter((m) => !!m)
|
|
50
51
|
.concat(ctx.modules);
|
|
51
52
|
},
|
|
52
|
-
transform(source, id) {
|
|
53
|
+
async transform(source, id) {
|
|
53
54
|
if (id.includes('node_modules'))
|
|
54
55
|
return null;
|
|
55
56
|
if (id.includes('?'))
|
|
@@ -268,7 +269,7 @@ export function plumeria(options = {}) {
|
|
|
268
269
|
if (obj) {
|
|
269
270
|
const hashMap = {};
|
|
270
271
|
Object.entries(obj).forEach(([key, style]) => {
|
|
271
|
-
const records = getStyleRecords(key, style
|
|
272
|
+
const records = getStyleRecords(key, style);
|
|
272
273
|
extractOndemandStyles(style, extractedSheets, scannedTables);
|
|
273
274
|
records.forEach((r) => {
|
|
274
275
|
addSheet(r.sheet);
|
|
@@ -416,6 +417,7 @@ export function plumeria(options = {}) {
|
|
|
416
417
|
const obj = objectExpressionToObject(args[0].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable, mergedVariantsTable);
|
|
417
418
|
const hash = genBase36Hash(obj, 1, 8);
|
|
418
419
|
scannedTables.keyframesObjectTable[hash] = obj;
|
|
420
|
+
extractOndemandStyles({ kf: `kf-${hash}` }, extractedSheets, scannedTables);
|
|
419
421
|
replacements.push({
|
|
420
422
|
start: node.span.start - ast.span.start,
|
|
421
423
|
end: node.span.end - ast.span.start,
|
|
@@ -461,7 +463,7 @@ export function plumeria(options = {}) {
|
|
|
461
463
|
scannedTables.createObjectTable[hash] = obj;
|
|
462
464
|
Object.entries(obj).forEach(([key, style]) => {
|
|
463
465
|
if (typeof style === 'object' && style !== null) {
|
|
464
|
-
const records = getStyleRecords(key, style
|
|
466
|
+
const records = getStyleRecords(key, style);
|
|
465
467
|
extractOndemandStyles(style, extractedSheets, scannedTables);
|
|
466
468
|
records.forEach((r) => addSheet(r.sheet));
|
|
467
469
|
}
|
|
@@ -808,7 +810,7 @@ export function plumeria(options = {}) {
|
|
|
808
810
|
if (conditionals.length === 0) {
|
|
809
811
|
extractOndemandStyles(baseStyle, extractedSheets, scannedTables);
|
|
810
812
|
const hash = genBase36Hash(baseStyle, 1, 8);
|
|
811
|
-
const records = getStyleRecords(hash, baseStyle
|
|
813
|
+
const records = getStyleRecords(hash, baseStyle);
|
|
812
814
|
records.forEach((r) => addSheet(r.sheet));
|
|
813
815
|
const className = records
|
|
814
816
|
.map((r) => r.hash)
|
|
@@ -847,7 +849,7 @@ export function plumeria(options = {}) {
|
|
|
847
849
|
}
|
|
848
850
|
extractOndemandStyles(currentStyle, extractedSheets, scannedTables);
|
|
849
851
|
const hash = genBase36Hash(currentStyle, 1, 8);
|
|
850
|
-
const records = getStyleRecords(hash, currentStyle
|
|
852
|
+
const records = getStyleRecords(hash, currentStyle);
|
|
851
853
|
records.forEach((r) => extractedSheets.push(r.sheet));
|
|
852
854
|
const className = records
|
|
853
855
|
.map((r) => r.hash)
|
|
@@ -883,7 +885,7 @@ export function plumeria(options = {}) {
|
|
|
883
885
|
},
|
|
884
886
|
});
|
|
885
887
|
Object.values(localCreateStyles).forEach((info) => {
|
|
886
|
-
if (info.type === 'constant'
|
|
888
|
+
if (info.type === 'constant') {
|
|
887
889
|
return;
|
|
888
890
|
}
|
|
889
891
|
if (info.isExported) {
|
|
@@ -901,6 +903,7 @@ export function plumeria(options = {}) {
|
|
|
901
903
|
});
|
|
902
904
|
}
|
|
903
905
|
});
|
|
906
|
+
const optInCSS = await optimizer(extractedSheets.join(''));
|
|
904
907
|
const buffer = Buffer.from(source);
|
|
905
908
|
let offset = 0;
|
|
906
909
|
const parts = [];
|
|
@@ -916,14 +919,13 @@ export function plumeria(options = {}) {
|
|
|
916
919
|
parts.push(buffer.subarray(offset));
|
|
917
920
|
const transformedSource = Buffer.concat(parts).toString();
|
|
918
921
|
if (extractedSheets.length > 0) {
|
|
919
|
-
const generatedCSS = extractedSheets.join('');
|
|
920
922
|
const baseId = id.replace(EXTENSION_PATTERN, '');
|
|
921
923
|
const cssFilename = `${baseId}.zero.css`;
|
|
922
924
|
const cssRelativePath = path
|
|
923
925
|
.relative(config.root, cssFilename)
|
|
924
926
|
.replace(/\\/g, '/');
|
|
925
927
|
const cssId = `/${cssRelativePath}`;
|
|
926
|
-
cssLookup.set(cssFilename,
|
|
928
|
+
cssLookup.set(cssFilename, optInCSS);
|
|
927
929
|
cssFileLookup.set(cssId, cssFilename);
|
|
928
930
|
const targetIndex = targets.findIndex((t) => t.id === id);
|
|
929
931
|
if (targetIndex !== -1) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plumeria/vite-plugin",
|
|
3
|
-
"version": "6.3.
|
|
3
|
+
"version": "6.3.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Plumeria Vite plugin",
|
|
6
6
|
"author": "Refirst 11",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"dist/"
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@plumeria/utils": "^6.3.
|
|
25
|
+
"@plumeria/utils": "^6.3.1"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@swc/core": "1.15.8",
|