@plumeria/webpack-plugin 0.26.0 → 0.28.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/dist/create.js +31 -14
- package/dist/index.d.ts +1 -9
- package/dist/index.js +3 -37
- package/package.json +2 -2
package/dist/create.js
CHANGED
|
@@ -17,23 +17,38 @@ function compileToSingleCSS(object) {
|
|
|
17
17
|
const hashes = new Set();
|
|
18
18
|
const sheets = new Set();
|
|
19
19
|
(0, zss_engine_1.processAtomicProps)({ [prop]: value }, hashes, sheets);
|
|
20
|
-
const
|
|
21
|
-
const
|
|
22
|
-
|
|
20
|
+
const hashArray = [...hashes];
|
|
21
|
+
const sheetArray = [...sheets];
|
|
22
|
+
const baseSheetParts = [];
|
|
23
|
+
const baseHashParts = [];
|
|
24
|
+
const querySheetParts = [];
|
|
25
|
+
const queryHashParts = [];
|
|
26
|
+
for (let i = 0; i < sheetArray.length; i++) {
|
|
27
|
+
const sheet = sheetArray[i];
|
|
28
|
+
const hash = hashArray[i];
|
|
23
29
|
if (sheet.includes('@media') || sheet.includes('@container')) {
|
|
24
|
-
|
|
30
|
+
querySheetParts.push(sheet);
|
|
31
|
+
queryHashParts.push(hash);
|
|
25
32
|
}
|
|
26
33
|
else {
|
|
27
|
-
|
|
34
|
+
baseSheetParts.push(sheet);
|
|
35
|
+
baseHashParts.push(hash);
|
|
28
36
|
}
|
|
29
37
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
38
|
+
if (baseSheetParts.length > 0) {
|
|
39
|
+
records.push({
|
|
40
|
+
key: prop,
|
|
41
|
+
hash: baseHashParts.join(' '),
|
|
42
|
+
sheet: baseSheetParts.join(''),
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
if (querySheetParts.length > 0) {
|
|
46
|
+
records.push({
|
|
47
|
+
key: prop + '__queries__',
|
|
48
|
+
hash: queryHashParts.join(' '),
|
|
49
|
+
sheet: querySheetParts.join(''),
|
|
50
|
+
});
|
|
51
|
+
}
|
|
37
52
|
});
|
|
38
53
|
if (Object.keys(nonFlat).length > 0) {
|
|
39
54
|
const modNonFlat = (0, zss_engine_1.transformNestedSelectors)(nonFlat);
|
|
@@ -41,7 +56,7 @@ function compileToSingleCSS(object) {
|
|
|
41
56
|
const nonFlatHash = (0, zss_engine_1.genBase36Hash)(nonFlatObj, 1, 7);
|
|
42
57
|
const { styleSheet } = (0, zss_engine_1.transpile)(nonFlatObj, nonFlatHash);
|
|
43
58
|
Object.entries(nonFlat).forEach(([atRule, nestedObj]) => {
|
|
44
|
-
Object.
|
|
59
|
+
Object.keys(nestedObj).forEach((prop) => {
|
|
45
60
|
records.push({
|
|
46
61
|
key: atRule + prop,
|
|
47
62
|
hash: nonFlatHash,
|
|
@@ -62,7 +77,9 @@ function compileToSingleCSS(object) {
|
|
|
62
77
|
}
|
|
63
78
|
});
|
|
64
79
|
});
|
|
65
|
-
|
|
80
|
+
const baseLayer = baseSheets.length > 0 ? `@layer base {\n${baseSheets.join('')}}` : '';
|
|
81
|
+
const queryLayer = querySheets.length > 0 ? `@layer queries {\n${querySheets.join('')}}` : '';
|
|
82
|
+
return [baseLayer, queryLayer].filter(Boolean).join('\n');
|
|
66
83
|
}
|
|
67
84
|
function createCSS(object) {
|
|
68
85
|
const compiledCSS = compileToSingleCSS(object);
|
package/dist/index.d.ts
CHANGED
|
@@ -1,19 +1,11 @@
|
|
|
1
1
|
import type { Compiler } from 'webpack';
|
|
2
2
|
import { CSSObject } from './types';
|
|
3
|
-
interface PlumeriaPluginOptions {
|
|
4
|
-
entryPaths: string;
|
|
5
|
-
}
|
|
6
3
|
export declare class PlumeriaPlugin {
|
|
7
4
|
private stylesByFile;
|
|
8
|
-
private currentPageFiles;
|
|
9
5
|
private outFile;
|
|
10
|
-
|
|
11
|
-
constructor(options: PlumeriaPluginOptions);
|
|
6
|
+
constructor();
|
|
12
7
|
apply(compiler: Compiler): void;
|
|
13
|
-
private updateCurrentPageFiles;
|
|
14
8
|
registerFileStyles(filePath: string, styles: CSSObject): void;
|
|
15
|
-
private isCurrentPageFile;
|
|
16
9
|
private generateOrderedCSS;
|
|
17
10
|
private writeCSS;
|
|
18
11
|
}
|
|
19
|
-
export {};
|
package/dist/index.js
CHANGED
|
@@ -9,24 +9,16 @@ const fs_1 = __importDefault(require("fs"));
|
|
|
9
9
|
const PLUGIN_NAME = 'PlumeriaPlugin';
|
|
10
10
|
class PlumeriaPlugin {
|
|
11
11
|
stylesByFile = new Map();
|
|
12
|
-
currentPageFiles = new Set();
|
|
13
12
|
outFile;
|
|
14
|
-
|
|
15
|
-
constructor(options) {
|
|
16
|
-
this.options = options;
|
|
17
|
-
}
|
|
13
|
+
constructor() { }
|
|
18
14
|
apply(compiler) {
|
|
19
15
|
this.outFile = path_1.default.resolve(__dirname, '..', 'zero-virtual.css');
|
|
20
16
|
compiler.hooks.invalid.tap(PLUGIN_NAME, (filename) => {
|
|
21
17
|
if (filename) {
|
|
22
18
|
const absPath = path_1.default.resolve(filename);
|
|
23
19
|
this.stylesByFile.delete(absPath);
|
|
24
|
-
this.currentPageFiles.delete(absPath);
|
|
25
20
|
}
|
|
26
21
|
});
|
|
27
|
-
compiler.hooks.watchRun.tap(PLUGIN_NAME, (compiler) => {
|
|
28
|
-
this.updateCurrentPageFiles(compiler);
|
|
29
|
-
});
|
|
30
22
|
compiler.hooks.normalModuleFactory.tap(PLUGIN_NAME, (nmf) => {
|
|
31
23
|
nmf.hooks.createModule.tap(PLUGIN_NAME, (createData) => {
|
|
32
24
|
const modPath = createData.matchResource ?? createData.resourceResolveData?.path;
|
|
@@ -37,26 +29,6 @@ class PlumeriaPlugin {
|
|
|
37
29
|
});
|
|
38
30
|
});
|
|
39
31
|
}
|
|
40
|
-
updateCurrentPageFiles(compiler) {
|
|
41
|
-
this.stylesByFile.clear();
|
|
42
|
-
const entries = compiler.options.entry;
|
|
43
|
-
if (entries && typeof entries === 'object') {
|
|
44
|
-
this.currentPageFiles.clear();
|
|
45
|
-
Object.keys(entries).forEach((entryName) => {
|
|
46
|
-
if (entryName.startsWith(this.options.entryPaths)) {
|
|
47
|
-
const entry = entries[entryName];
|
|
48
|
-
if (Array.isArray(entry)) {
|
|
49
|
-
entry.forEach((file) => {
|
|
50
|
-
this.currentPageFiles.add(path_1.default.resolve(file));
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
else if (typeof entry === 'string') {
|
|
54
|
-
this.currentPageFiles.add(path_1.default.resolve(entry));
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
32
|
registerFileStyles(filePath, styles) {
|
|
61
33
|
const absPath = path_1.default.resolve(filePath);
|
|
62
34
|
const prev = this.stylesByFile.get(absPath) || {
|
|
@@ -66,20 +38,13 @@ class PlumeriaPlugin {
|
|
|
66
38
|
tokenStyles: '',
|
|
67
39
|
baseStyles: '',
|
|
68
40
|
};
|
|
69
|
-
const isCurrentPage = this.isCurrentPageFile(absPath);
|
|
70
41
|
const updatedStyles = {
|
|
71
42
|
...prev,
|
|
72
43
|
...styles,
|
|
73
|
-
isCurrentPage,
|
|
74
|
-
lastAccessed: Date.now(),
|
|
75
44
|
};
|
|
76
45
|
this.stylesByFile.set(absPath, updatedStyles);
|
|
77
46
|
this.writeCSS();
|
|
78
47
|
}
|
|
79
|
-
isCurrentPageFile(filePath) {
|
|
80
|
-
return (this.currentPageFiles.has(filePath) ||
|
|
81
|
-
Array.from(this.currentPageFiles).some((pageFile) => filePath.includes(path_1.default.dirname(pageFile))));
|
|
82
|
-
}
|
|
83
48
|
generateOrderedCSS() {
|
|
84
49
|
const allStyles = Array.from(this.stylesByFile.values());
|
|
85
50
|
if (allStyles.length === 0) {
|
|
@@ -110,7 +75,8 @@ class PlumeriaPlugin {
|
|
|
110
75
|
.join('\n');
|
|
111
76
|
}
|
|
112
77
|
writeCSS() {
|
|
113
|
-
|
|
78
|
+
let css = this.generateOrderedCSS();
|
|
79
|
+
css = '@layer base, queries;\n\n' + css;
|
|
114
80
|
fs_1.default.writeFileSync(this.outFile, css, 'utf-8');
|
|
115
81
|
}
|
|
116
82
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plumeria/webpack-plugin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.28.0",
|
|
4
4
|
"description": "Plumeria Webpack plugin",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"devDependencies": {
|
|
24
24
|
"@types/babel__core": "^7.20.5",
|
|
25
25
|
"webpack": "^5.101.0",
|
|
26
|
-
"zss-engine": "^0.2.
|
|
26
|
+
"zss-engine": "^0.2.99"
|
|
27
27
|
},
|
|
28
28
|
"publishConfig": {
|
|
29
29
|
"access": "public"
|