@tuya-sat/micro-dev-loader 2.2.3 → 2.2.6
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.
|
@@ -16,7 +16,7 @@ const cssFileRegex = /.css$/;
|
|
|
16
16
|
const imports = [];
|
|
17
17
|
const writers = [];
|
|
18
18
|
const output = [];
|
|
19
|
-
function buildContents(lines, filePath) {
|
|
19
|
+
function buildContents(lines, filePath, lessVarible) {
|
|
20
20
|
let currentLines = [];
|
|
21
21
|
let line;
|
|
22
22
|
let hashPath;
|
|
@@ -35,11 +35,18 @@ function buildContents(lines, filePath) {
|
|
|
35
35
|
currentLines = [];
|
|
36
36
|
}
|
|
37
37
|
imported = line.replace(stringLiteralRegex, "$1");
|
|
38
|
+
//处理变量路径(目前,处理不了文件内的变量)
|
|
39
|
+
imported = imported.replace(/\@\{([^}]+)\}/, (match, p1) => {
|
|
40
|
+
if (lessVarible[p1] !== undefined) {
|
|
41
|
+
return lessVarible[p1];
|
|
42
|
+
}
|
|
43
|
+
return p1;
|
|
44
|
+
});
|
|
38
45
|
if (!(lessFileRegex.test(imported) || cssFileRegex.test(imported))) {
|
|
39
46
|
imported += ".less";
|
|
40
47
|
}
|
|
41
48
|
if (imported.match(/^~/)) {
|
|
42
|
-
hashPath = imported.replace("~",
|
|
49
|
+
hashPath = require.resolve(imported.replace("~", ""));
|
|
43
50
|
}
|
|
44
51
|
else {
|
|
45
52
|
hashPath = path__default["default"].resolve(filePath, "..", imported);
|
|
@@ -49,7 +56,7 @@ function buildContents(lines, filePath) {
|
|
|
49
56
|
file = fs__default["default"].readFileSync(hashPath, "utf8");
|
|
50
57
|
splitLines = file.split(/\r\n|\n/);
|
|
51
58
|
splitLines[0] = splitLines[0].trim();
|
|
52
|
-
buildContents(splitLines, hashPath);
|
|
59
|
+
buildContents(splitLines, hashPath, lessVarible);
|
|
53
60
|
}
|
|
54
61
|
continue;
|
|
55
62
|
}
|
|
@@ -59,11 +66,11 @@ function buildContents(lines, filePath) {
|
|
|
59
66
|
writers.push(new Writer(currentLines));
|
|
60
67
|
return index;
|
|
61
68
|
}
|
|
62
|
-
function compress(data, path) {
|
|
69
|
+
function compress(data, path, lessVarible) {
|
|
63
70
|
return new Promise(function (resolve, reject) {
|
|
64
71
|
var splitLines = data.split(/\r\n|\n/);
|
|
65
72
|
splitLines[0] = splitLines[0].trim();
|
|
66
|
-
buildContents(splitLines, path);
|
|
73
|
+
buildContents(splitLines, path, lessVarible);
|
|
67
74
|
let previousLine = "";
|
|
68
75
|
writers.forEach((writer) => {
|
|
69
76
|
previousLine = writer.write(output, previousLine);
|
|
@@ -8,9 +8,9 @@ export default class ThemePlugin {
|
|
|
8
8
|
apply(compiler: Compiler): void;
|
|
9
9
|
getBundledLessFile(): Promise<string>;
|
|
10
10
|
runCssbundle(): Promise<string>;
|
|
11
|
-
getCustomeVarible
|
|
12
|
-
getLessVarible(contentHash: any): {
|
|
11
|
+
private getCustomeVarible;
|
|
12
|
+
getLessVarible(contentHash: any): Promise<{
|
|
13
13
|
fileName: string;
|
|
14
14
|
content: string;
|
|
15
|
-
}[]
|
|
15
|
+
}[]>;
|
|
16
16
|
}
|
|
@@ -10,6 +10,7 @@ var less = require('less');
|
|
|
10
10
|
var path = require('path');
|
|
11
11
|
var fse = require('fs-extra');
|
|
12
12
|
var bundle = require('./bundle.js');
|
|
13
|
+
var microUtils = require('@tuya-sat/micro-utils');
|
|
13
14
|
|
|
14
15
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
15
16
|
|
|
@@ -47,7 +48,7 @@ class ThemePlugin {
|
|
|
47
48
|
const { contenthash } = compilation.assetsInfo.get(pathname);
|
|
48
49
|
const darkCssFileName = `dark.${contenthash}.css`;
|
|
49
50
|
const lessFileName = `theme.${contenthash}.less`;
|
|
50
|
-
const lessVarible = this.getLessVarible(contenthash);
|
|
51
|
+
const lessVarible = yield this.getLessVarible(contenthash);
|
|
51
52
|
compilation.emitAsset(`${this.stylePath}/${darkCssFileName}`, new RawSource(content));
|
|
52
53
|
compilation.emitAsset(`${this.stylePath}/${lessFileName}`, new RawSource(lessContent));
|
|
53
54
|
lessVarible.forEach(({ fileName, content }) => {
|
|
@@ -90,7 +91,7 @@ class ThemePlugin {
|
|
|
90
91
|
const relativePath = path__default["default"].relative(cwd, file);
|
|
91
92
|
fakefile += `@import "${relativePath}";\n`;
|
|
92
93
|
});
|
|
93
|
-
const file = yield bundle["default"](fakefile, path__default["default"].resolve(cwd, "fake.less"));
|
|
94
|
+
const file = yield bundle["default"](fakefile, path__default["default"].resolve(cwd, "fake.less"), Object.assign(Object.assign({}, theme.getThemeVariables({ dark: true })), { "entry-name": "light" }));
|
|
94
95
|
return file;
|
|
95
96
|
});
|
|
96
97
|
}
|
|
@@ -101,9 +102,9 @@ class ThemePlugin {
|
|
|
101
102
|
return less__default["default"].render(bufferString, {
|
|
102
103
|
filename: file,
|
|
103
104
|
javascriptEnabled: true,
|
|
104
|
-
modifyVars: Object.assign(Object.assign({}, theme.getThemeVariables({
|
|
105
|
+
modifyVars: Object.assign(Object.assign(Object.assign({}, theme.getThemeVariables({
|
|
105
106
|
dark: true,
|
|
106
|
-
})), { "entry-name": "dark" }),
|
|
107
|
+
})), microUtils.theme.getAntdOverWriteFile().dark), { "entry-name": "dark" }),
|
|
107
108
|
plugins: [createHandleImportPlugin()],
|
|
108
109
|
});
|
|
109
110
|
});
|
|
@@ -116,44 +117,34 @@ class ThemePlugin {
|
|
|
116
117
|
});
|
|
117
118
|
}
|
|
118
119
|
getCustomeVarible() {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
function convertLessFileToVarible(filePath) {
|
|
126
|
-
if (!filePath) {
|
|
127
|
-
return {};
|
|
128
|
-
}
|
|
129
|
-
let content = fse__default["default"].readFileSync(filePath, "utf-8");
|
|
130
|
-
return content
|
|
131
|
-
.split(";")
|
|
132
|
-
.map((item) => item.split(":"))
|
|
133
|
-
.reduce((prev, [key, value]) => {
|
|
134
|
-
prev[key] = value;
|
|
135
|
-
return prev;
|
|
136
|
-
}, {});
|
|
137
|
-
}
|
|
120
|
+
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
121
|
+
return [
|
|
122
|
+
yield microUtils.theme.getCustomLightVaribleFile(),
|
|
123
|
+
yield microUtils.theme.getCustomDarkVaribleFile(),
|
|
124
|
+
];
|
|
125
|
+
});
|
|
138
126
|
}
|
|
139
127
|
getLessVarible(contentHash) {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
{
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
128
|
+
return tslib.__awaiter(this, void 0, void 0, function* () {
|
|
129
|
+
let antdLightVarible = theme.getThemeVariables();
|
|
130
|
+
let antdDarkVarible = theme.getThemeVariables({ dark: true });
|
|
131
|
+
const antdOverWriteVarible = microUtils.theme.getAntdOverWriteFile();
|
|
132
|
+
delete antdDarkVarible.hack;
|
|
133
|
+
delete antdLightVarible.hack;
|
|
134
|
+
const [customLightVarible, customDarkVarible] = yield this.getCustomeVarible();
|
|
135
|
+
let lightLessVarible = Object.assign(Object.assign(Object.assign({}, antdLightVarible), antdOverWriteVarible.light), customLightVarible);
|
|
136
|
+
let darkLessVarible = Object.assign(Object.assign(Object.assign({}, antdDarkVarible), antdOverWriteVarible.dark), customDarkVarible);
|
|
137
|
+
return [
|
|
138
|
+
{
|
|
139
|
+
fileName: `${this.jsFilePrefix}/dark.${contentHash}.less.js`,
|
|
140
|
+
content: `window.darkLessVarible = ${JSON.stringify(darkLessVarible)}`,
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
fileName: `${this.jsFilePrefix}/light.${contentHash}.less.js`,
|
|
144
|
+
content: `window.lightLessVarible = ${JSON.stringify(lightLessVarible)}`,
|
|
145
|
+
},
|
|
146
|
+
];
|
|
147
|
+
});
|
|
157
148
|
}
|
|
158
149
|
}
|
|
159
150
|
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.6",
|
|
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.
|
|
17
|
+
"@tuya-sat/micro-utils": "2.2.6",
|
|
18
18
|
"cheerio": "1.0.0-rc.10",
|
|
19
19
|
"ejs": "3.1.6",
|
|
20
20
|
"fs-extra": "10.0.1",
|