@plumeria/webpack-plugin 6.3.0 → 6.3.2
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.d.ts +1 -1
- package/dist/index.js +90 -44
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { LoaderContext } from 'webpack';
|
|
2
|
-
export default function loader(this: LoaderContext<unknown>, source: string): void
|
|
2
|
+
export default function loader(this: LoaderContext<unknown>, source: string): Promise<void>;
|
package/dist/index.js
CHANGED
|
@@ -5,15 +5,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.default = loader;
|
|
7
7
|
const core_1 = require("@swc/core");
|
|
8
|
-
const fs_1 =
|
|
8
|
+
const fs_1 = require("fs");
|
|
9
9
|
const path_1 = __importDefault(require("path"));
|
|
10
10
|
const zss_engine_1 = require("zss-engine");
|
|
11
11
|
const utils_1 = require("@plumeria/utils");
|
|
12
12
|
const VIRTUAL_FILE_PATH = path_1.default.resolve(__dirname, '..', 'zero-virtual.css');
|
|
13
13
|
if (process.env.NODE_ENV === 'production') {
|
|
14
|
-
fs_1.
|
|
14
|
+
(0, fs_1.writeFileSync)(VIRTUAL_FILE_PATH, '/** Placeholder file */\n', 'utf-8');
|
|
15
15
|
}
|
|
16
|
-
function loader(source) {
|
|
16
|
+
async function loader(source) {
|
|
17
17
|
const callback = this.async();
|
|
18
18
|
const isProduction = process.env.NODE_ENV === 'production';
|
|
19
19
|
if (this.resourcePath.includes('node_modules') ||
|
|
@@ -222,7 +222,7 @@ function loader(source) {
|
|
|
222
222
|
if (obj) {
|
|
223
223
|
const hashMap = {};
|
|
224
224
|
Object.entries(obj).forEach(([key, style]) => {
|
|
225
|
-
const records = (0, utils_1.getStyleRecords)(key, style
|
|
225
|
+
const records = (0, utils_1.getStyleRecords)(key, style);
|
|
226
226
|
if (!isProduction) {
|
|
227
227
|
(0, utils_1.extractOndemandStyles)(style, extractedSheets, scannedTables);
|
|
228
228
|
records.forEach((r) => {
|
|
@@ -372,6 +372,9 @@ function loader(source) {
|
|
|
372
372
|
const obj = (0, utils_1.objectExpressionToObject)(args[0].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable, mergedVariantsTable);
|
|
373
373
|
const hash = (0, zss_engine_1.genBase36Hash)(obj, 1, 8);
|
|
374
374
|
scannedTables.keyframesObjectTable[hash] = obj;
|
|
375
|
+
if (!isProduction) {
|
|
376
|
+
(0, utils_1.extractOndemandStyles)({ kf: `kf-${hash}` }, extractedSheets, scannedTables);
|
|
377
|
+
}
|
|
375
378
|
replacements.push({
|
|
376
379
|
start: node.span.start - ast.span.start,
|
|
377
380
|
end: node.span.end - ast.span.start,
|
|
@@ -419,7 +422,7 @@ function loader(source) {
|
|
|
419
422
|
scannedTables.createObjectTable[hash] = obj;
|
|
420
423
|
Object.entries(obj).forEach(([key, style]) => {
|
|
421
424
|
if (typeof style === 'object' && style !== null) {
|
|
422
|
-
const records = (0, utils_1.getStyleRecords)(key, style
|
|
425
|
+
const records = (0, utils_1.getStyleRecords)(key, style);
|
|
423
426
|
if (!isProduction) {
|
|
424
427
|
(0, utils_1.extractOndemandStyles)(style, extractedSheets, scannedTables);
|
|
425
428
|
records.forEach((r) => addSheet(r.sheet));
|
|
@@ -770,7 +773,7 @@ function loader(source) {
|
|
|
770
773
|
(0, utils_1.extractOndemandStyles)(baseStyle, extractedSheets, scannedTables);
|
|
771
774
|
}
|
|
772
775
|
const hash = (0, zss_engine_1.genBase36Hash)(baseStyle, 1, 8);
|
|
773
|
-
const records = (0, utils_1.getStyleRecords)(hash, baseStyle
|
|
776
|
+
const records = (0, utils_1.getStyleRecords)(hash, baseStyle);
|
|
774
777
|
if (!isProduction) {
|
|
775
778
|
records.forEach((r) => addSheet(r.sheet));
|
|
776
779
|
}
|
|
@@ -783,35 +786,49 @@ function loader(source) {
|
|
|
783
786
|
}
|
|
784
787
|
else {
|
|
785
788
|
const table = {};
|
|
786
|
-
const
|
|
787
|
-
|
|
789
|
+
const groups = {};
|
|
790
|
+
let strayIdCounter = groupIdCounter + 1;
|
|
791
|
+
conditionals.forEach((c) => {
|
|
792
|
+
const gid = c.groupId !== undefined ? c.groupId : strayIdCounter++;
|
|
793
|
+
if (!groups[gid]) {
|
|
794
|
+
groups[gid] = [];
|
|
795
|
+
}
|
|
796
|
+
groups[gid].push(c);
|
|
797
|
+
});
|
|
798
|
+
const sortedGroupIds = Object.keys(groups)
|
|
799
|
+
.map(Number)
|
|
800
|
+
.sort((a, b) => a - b);
|
|
801
|
+
let totalCombinations = 1;
|
|
802
|
+
const groupMeta = sortedGroupIds.map((gid) => {
|
|
803
|
+
const options = groups[gid];
|
|
804
|
+
const isVariantGroup = options[0].groupId !== undefined;
|
|
805
|
+
const size = isVariantGroup ? options.length : 2;
|
|
806
|
+
const stride = totalCombinations;
|
|
807
|
+
totalCombinations *= size;
|
|
808
|
+
return { gid, options, size, stride, isVariantGroup };
|
|
809
|
+
});
|
|
810
|
+
for (let i = 0; i < totalCombinations; i++) {
|
|
788
811
|
let currentStyle = { ...baseStyle };
|
|
789
|
-
const
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
if (conditionals[j].groupId !== undefined) {
|
|
794
|
-
if (seenGroups.has(conditionals[j].groupId)) {
|
|
795
|
-
impossible = true;
|
|
796
|
-
break;
|
|
797
|
-
}
|
|
798
|
-
seenGroups.add(conditionals[j].groupId);
|
|
799
|
-
}
|
|
800
|
-
currentStyle = (0, utils_1.deepMerge)(currentStyle, conditionals[j].truthy);
|
|
812
|
+
for (const meta of groupMeta) {
|
|
813
|
+
const localIndex = Math.floor(i / meta.stride) % meta.size;
|
|
814
|
+
if (meta.isVariantGroup) {
|
|
815
|
+
currentStyle = (0, utils_1.deepMerge)(currentStyle, meta.options[localIndex].truthy);
|
|
801
816
|
}
|
|
802
817
|
else {
|
|
803
|
-
|
|
818
|
+
const cond = meta.options[0];
|
|
819
|
+
if (localIndex === 1) {
|
|
820
|
+
currentStyle = (0, utils_1.deepMerge)(currentStyle, cond.truthy);
|
|
821
|
+
}
|
|
822
|
+
else {
|
|
823
|
+
currentStyle = (0, utils_1.deepMerge)(currentStyle, cond.falsy);
|
|
824
|
+
}
|
|
804
825
|
}
|
|
805
826
|
}
|
|
806
|
-
if (impossible) {
|
|
807
|
-
table[i] = '';
|
|
808
|
-
continue;
|
|
809
|
-
}
|
|
810
827
|
if (process.env.NODE_ENV !== 'production') {
|
|
811
828
|
(0, utils_1.extractOndemandStyles)(currentStyle, extractedSheets, scannedTables);
|
|
812
829
|
}
|
|
813
830
|
const hash = (0, zss_engine_1.genBase36Hash)(currentStyle, 1, 8);
|
|
814
|
-
const records = (0, utils_1.getStyleRecords)(hash, currentStyle
|
|
831
|
+
const records = (0, utils_1.getStyleRecords)(hash, currentStyle);
|
|
815
832
|
if (process.env.NODE_ENV !== 'production') {
|
|
816
833
|
records.forEach((r) => extractedSheets.push(r.sheet));
|
|
817
834
|
}
|
|
@@ -820,22 +837,50 @@ function loader(source) {
|
|
|
820
837
|
.join(' ');
|
|
821
838
|
table[i] = className;
|
|
822
839
|
}
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
840
|
+
const indexParts = [];
|
|
841
|
+
for (const meta of groupMeta) {
|
|
842
|
+
if (meta.isVariantGroup) {
|
|
843
|
+
const exprs = meta.options
|
|
844
|
+
.map((opt, idx) => {
|
|
845
|
+
if (idx === 0)
|
|
846
|
+
return null;
|
|
847
|
+
let testStr = opt.testString;
|
|
848
|
+
if (!testStr && opt.test) {
|
|
849
|
+
const start = opt.test.span.start - ast.span.start;
|
|
850
|
+
const end = opt.test.span.end - ast.span.start;
|
|
851
|
+
testStr = source.substring(start, end);
|
|
852
|
+
}
|
|
853
|
+
return `(!!(${testStr}) * ${idx})`;
|
|
854
|
+
})
|
|
855
|
+
.filter(Boolean);
|
|
856
|
+
if (exprs.length > 0) {
|
|
857
|
+
const groupSum = `(${exprs.join(' + ')})`;
|
|
858
|
+
if (meta.stride > 1) {
|
|
859
|
+
indexParts.push(`(${groupSum} * ${meta.stride})`);
|
|
860
|
+
}
|
|
861
|
+
else {
|
|
862
|
+
indexParts.push(groupSum);
|
|
863
|
+
}
|
|
831
864
|
}
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
const
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
865
|
+
}
|
|
866
|
+
else {
|
|
867
|
+
const cond = meta.options[0];
|
|
868
|
+
let testStr = cond.testString;
|
|
869
|
+
if (!testStr && cond.test) {
|
|
870
|
+
const start = cond.test.span.start - ast.span.start;
|
|
871
|
+
const end = cond.test.span.end - ast.span.start;
|
|
872
|
+
testStr = source.substring(start, end);
|
|
873
|
+
}
|
|
874
|
+
const expr = `(!!(${testStr}))`;
|
|
875
|
+
if (meta.stride > 1) {
|
|
876
|
+
indexParts.push(`(${expr} * ${meta.stride})`);
|
|
877
|
+
}
|
|
878
|
+
else {
|
|
879
|
+
indexParts.push(`(${expr} * 1)`);
|
|
880
|
+
}
|
|
881
|
+
}
|
|
838
882
|
}
|
|
883
|
+
const indexExpr = indexParts.join(' + ') || '0';
|
|
839
884
|
const tableStr = JSON.stringify(table);
|
|
840
885
|
const replacement = `${tableStr}[${indexExpr}]`;
|
|
841
886
|
replacements.push({
|
|
@@ -849,7 +894,7 @@ function loader(source) {
|
|
|
849
894
|
},
|
|
850
895
|
});
|
|
851
896
|
Object.values(localCreateStyles).forEach((info) => {
|
|
852
|
-
if (info.type === 'constant'
|
|
897
|
+
if (info.type === 'constant') {
|
|
853
898
|
return;
|
|
854
899
|
}
|
|
855
900
|
if (info.isExported) {
|
|
@@ -867,6 +912,7 @@ function loader(source) {
|
|
|
867
912
|
});
|
|
868
913
|
}
|
|
869
914
|
});
|
|
915
|
+
const optInCSS = await (0, utils_1.optimizer)(extractedSheets.join(''));
|
|
870
916
|
const buffer = Buffer.from(source);
|
|
871
917
|
let offset = 0;
|
|
872
918
|
const parts = [];
|
|
@@ -892,7 +938,7 @@ function loader(source) {
|
|
|
892
938
|
}
|
|
893
939
|
const virtualCssRequest = stringifyRequest(this, `${VIRTUAL_CSS_PATH}`);
|
|
894
940
|
const postfix = `\nimport ${virtualCssRequest};`;
|
|
895
|
-
const css = fs_1.
|
|
941
|
+
const css = (0, fs_1.readFileSync)(VIRTUAL_FILE_PATH, 'utf-8');
|
|
896
942
|
function generateOrderedCSS(styles) {
|
|
897
943
|
const sections = [];
|
|
898
944
|
if (styles.keyframeStyles?.trim()) {
|
|
@@ -912,7 +958,7 @@ function loader(source) {
|
|
|
912
958
|
}
|
|
913
959
|
return sections.join('\n');
|
|
914
960
|
}
|
|
915
|
-
const orderedCSS = generateOrderedCSS(fileStyles);
|
|
961
|
+
const orderedCSS = await (0, utils_1.optimizer)(generateOrderedCSS(fileStyles));
|
|
916
962
|
const relativeId = path_1.default.relative(process.cwd(), this.resourcePath);
|
|
917
963
|
const hmrCode = `
|
|
918
964
|
if (module.hot) {
|
|
@@ -946,7 +992,7 @@ function loader(source) {
|
|
|
946
992
|
}
|
|
947
993
|
`;
|
|
948
994
|
if (extractedSheets.length > 0 && process.env.NODE_ENV === 'development') {
|
|
949
|
-
fs_1.
|
|
995
|
+
(0, fs_1.appendFileSync)(VIRTUAL_FILE_PATH, optInCSS, 'utf-8');
|
|
950
996
|
}
|
|
951
997
|
const useClientDirective = /^\s*['"]use client['"]/;
|
|
952
998
|
if (process.env.NODE_ENV === 'production')
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plumeria/webpack-plugin",
|
|
3
|
-
"version": "6.3.
|
|
3
|
+
"version": "6.3.2",
|
|
4
4
|
"description": "Plumeria Webpack plugin",
|
|
5
5
|
"author": "Refirst 11",
|
|
6
6
|
"license": "MIT",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"zero-virtual.css"
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@plumeria/utils": "^6.3.
|
|
25
|
+
"@plumeria/utils": "^6.3.2"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@swc/core": "1.15.8",
|