@tuya-sat/micro-dev-loader 2.2.3 → 2.2.4

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.
@@ -1 +1,3 @@
1
- export default function compress(data: string, path: string): Promise<string>;
1
+ export default function compress(data: string, path: string, lessVarible: {
2
+ [key: string]: any;
3
+ }): Promise<string>;
@@ -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("~", path__default["default"].join(__dirname, "../../"));
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);
@@ -90,7 +90,7 @@ class ThemePlugin {
90
90
  const relativePath = path__default["default"].relative(cwd, file);
91
91
  fakefile += `@import "${relativePath}";\n`;
92
92
  });
93
- const file = yield bundle["default"](fakefile, path__default["default"].resolve(cwd, "fake.less"));
93
+ const file = yield bundle["default"](fakefile, path__default["default"].resolve(cwd, "fake.less"), Object.assign(Object.assign({}, theme.getThemeVariables({ dark: true })), { "entry-name": "dark" }));
94
94
  return file;
95
95
  });
96
96
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tuya-sat/micro-dev-loader",
3
- "version": "2.2.3",
3
+ "version": "2.2.4",
4
4
  "main": "dist/index.js",
5
5
  "license": "MIT",
6
6
  "scripts": {