@tuya-sat/micro-dev-loader 2.2.13 → 2.2.14
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.
|
@@ -2,22 +2,27 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
rule.
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
decl.
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
|
|
5
|
+
const getFilterPlugin = (storeHtmlVarible = []) => {
|
|
6
|
+
function plugin() {
|
|
7
|
+
return {
|
|
8
|
+
postcssPlugin: "filter",
|
|
9
|
+
Rule(rule) {
|
|
10
|
+
if (!rule.nodes.length) {
|
|
11
|
+
rule.remove();
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
Declaration(decl) {
|
|
15
|
+
//@ts-ignore
|
|
16
|
+
if (decl.variable && decl.parent.selector === "html") {
|
|
17
|
+
const declStr = decl.toString();
|
|
18
|
+
!storeHtmlVarible.includes(declStr) && storeHtmlVarible.push(declStr);
|
|
19
|
+
decl.remove();
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
plugin.postcss = true;
|
|
25
|
+
return plugin;
|
|
26
|
+
};
|
|
22
27
|
|
|
23
|
-
exports.
|
|
28
|
+
exports.getFilterPlugin = getFilterPlugin;
|
|
@@ -5,6 +5,6 @@ export default class ThemePlugin {
|
|
|
5
5
|
private lessFiles;
|
|
6
6
|
constructor(stylePath?: string);
|
|
7
7
|
apply(compiler: Compiler): void;
|
|
8
|
-
runCssbundle(): Promise<string>;
|
|
9
|
-
filterCssVarible(css: string): string;
|
|
8
|
+
runCssbundle(): Promise<[string, string[]]>;
|
|
9
|
+
filterCssVarible(css: string): [string, string[]];
|
|
10
10
|
}
|
|
@@ -47,15 +47,19 @@ class ThemePlugin {
|
|
|
47
47
|
this.lessFiles.push(item.nameForCondition());
|
|
48
48
|
});
|
|
49
49
|
compilation.updateAsset(pathname, (source) => {
|
|
50
|
-
return new RawSource(this.filterCssVarible(source.source().toString()));
|
|
50
|
+
return new RawSource(this.filterCssVarible(source.source().toString())[0]);
|
|
51
51
|
});
|
|
52
|
-
const content = yield this.runCssbundle();
|
|
52
|
+
const [content, storeHtmlVariable] = yield this.runCssbundle();
|
|
53
53
|
const { contenthash } = compilation.assetsInfo.get(pathname);
|
|
54
54
|
const darkCssFileName = `dark.${contenthash}.css`;
|
|
55
55
|
compilation.emitAsset(`${this.stylePath}/${darkCssFileName}`, new RawSource(content));
|
|
56
56
|
HtmlWebpackPlugin__default["default"].getHooks(compilation).beforeAssetTagGeneration.tapAsync(this.pluginName, (data, cb) => {
|
|
57
57
|
HtmlWebpackPlugin__default["default"].getHooks(compilation).beforeEmit.tapAsync(this.pluginName, (data, cb) => {
|
|
58
58
|
const $ = cheerio__default["default"].load(data.html);
|
|
59
|
+
const cssVariableStyleSheet = storeHtmlVariable.reduce((prev, curr) => {
|
|
60
|
+
return prev + curr + ";\n";
|
|
61
|
+
}, "");
|
|
62
|
+
$(`<style id="micro-css-variable">html{${cssVariableStyleSheet}}</style>`).insertBefore($("head").children().first());
|
|
59
63
|
$("link").map(function () {
|
|
60
64
|
const reg = /(?<=\/)light.([\s\S]+?).css$/;
|
|
61
65
|
const href = $(this).attr("href");
|
|
@@ -96,8 +100,9 @@ class ThemePlugin {
|
|
|
96
100
|
});
|
|
97
101
|
}
|
|
98
102
|
filterCssVarible(css) {
|
|
103
|
+
const store = [];
|
|
99
104
|
//@ts-ignore
|
|
100
|
-
return postcss__default["default"]([filterPlugin.
|
|
105
|
+
return [postcss__default["default"]([filterPlugin.getFilterPlugin(store)]).process(css).css, store];
|
|
101
106
|
}
|
|
102
107
|
}
|
|
103
108
|
function createHandleImportPlugin() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tuya-sat/micro-dev-loader",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.14",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"scripts": {
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"@babel/generator": "7.17.7",
|
|
15
15
|
"@babel/plugin-syntax-typescript": "7.16.7",
|
|
16
16
|
"@babel/template": "7.16.7",
|
|
17
|
-
"@tuya-sat/micro-utils": "2.2.
|
|
17
|
+
"@tuya-sat/micro-utils": "2.2.14",
|
|
18
18
|
"cheerio": "1.0.0-rc.10",
|
|
19
19
|
"ejs": "3.1.6",
|
|
20
20
|
"fs-extra": "10.0.1",
|