@plumeria/compiler 0.6.0 → 0.6.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/package.json +1 -2
- package/src/index.ts +21 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plumeria/compiler",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.1",
|
|
4
4
|
"description": "Compiler for Plumeria that build and optimizes",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -9,7 +9,6 @@
|
|
|
9
9
|
"plumeria",
|
|
10
10
|
"styling"
|
|
11
11
|
],
|
|
12
|
-
"author": "Refirst",
|
|
13
12
|
"repository": "github:zss-in-js/plumeria",
|
|
14
13
|
"license": "MIT",
|
|
15
14
|
"files": [
|
package/src/index.ts
CHANGED
|
@@ -10,13 +10,20 @@ import combineSelectors from 'postcss-combine-duplicated-selectors';
|
|
|
10
10
|
|
|
11
11
|
function isCSS(filePath: string): boolean {
|
|
12
12
|
const content = fs.readFileSync(filePath, 'utf8');
|
|
13
|
-
const sourceFile = ts.createSourceFile(
|
|
13
|
+
const sourceFile = ts.createSourceFile(
|
|
14
|
+
filePath,
|
|
15
|
+
content,
|
|
16
|
+
ts.ScriptTarget.Latest,
|
|
17
|
+
true,
|
|
18
|
+
);
|
|
14
19
|
|
|
15
20
|
const checker = (node: ts.Node): boolean => {
|
|
16
21
|
if (ts.isPropertyAccessExpression(node) && ts.isIdentifier(node.name)) {
|
|
17
22
|
const expressionText = node.expression.getText(sourceFile);
|
|
18
23
|
const methodName = node.name.getText(sourceFile);
|
|
19
|
-
return
|
|
24
|
+
return (
|
|
25
|
+
expressionText === 'css' && ['create', 'global'].includes(methodName)
|
|
26
|
+
);
|
|
20
27
|
}
|
|
21
28
|
return ts.forEachChild(node, checker) || false;
|
|
22
29
|
};
|
|
@@ -35,7 +42,9 @@ async function optimizeCSS() {
|
|
|
35
42
|
const corePath = path.dirname(require.resolve('@plumeria/core/package.json'));
|
|
36
43
|
const cssPath = path.join(corePath, 'dist/styles/global.css');
|
|
37
44
|
const cssContent = fs.readFileSync(cssPath, 'utf8');
|
|
38
|
-
const result = postcss([
|
|
45
|
+
const result = postcss([
|
|
46
|
+
combineSelectors({ removeDuplicatedProperties: true }),
|
|
47
|
+
]).process(cssContent, {
|
|
39
48
|
from: cssPath,
|
|
40
49
|
to: cssPath,
|
|
41
50
|
});
|
|
@@ -46,10 +55,17 @@ async function optimizeCSS() {
|
|
|
46
55
|
await cleanUp();
|
|
47
56
|
const appRoot = await getAppRoot();
|
|
48
57
|
const files = await fg([path.join(appRoot, '**/*.{js,jsx,ts,tsx}')], {
|
|
49
|
-
ignore: [
|
|
58
|
+
ignore: [
|
|
59
|
+
'**/main.{js,ts}/**',
|
|
60
|
+
'**/dist/**',
|
|
61
|
+
'**/.next/**',
|
|
62
|
+
'**/node_modules/**',
|
|
63
|
+
],
|
|
50
64
|
});
|
|
51
65
|
const styleFiles = files.filter(isCSS);
|
|
52
|
-
const importPromises = styleFiles.map(
|
|
66
|
+
const importPromises = styleFiles.map(
|
|
67
|
+
(styleFile) => import(path.resolve(styleFile)),
|
|
68
|
+
);
|
|
53
69
|
await Promise.all(importPromises);
|
|
54
70
|
|
|
55
71
|
for (let i = 0; i < styleFiles.length; i++) {
|