lvyjs 0.2.5 → 0.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.
- package/lib/config.js +4 -0
- package/lib/esbuild/config.js +3 -3
- package/lib/esbuild/plugins/Asstes.js +1 -1
- package/lib/esbuild/plugins/alias.js +24 -56
- package/lib/esbuild/plugins/css.js +1 -1
- package/lib/rullup/plugins/config.js +3 -3
- package/lib/rullup/plugins/loader-css.js +1 -1
- package/lib/rullup/plugins/loader-files.js +1 -1
- package/package.json +1 -1
package/lib/config.js
ADDED
package/lib/esbuild/config.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const assetsReg = /\.(png|jpg|jpeg|gif|svg|webp|ico)
|
|
2
|
-
const cssReg = /\.(css|scss|less|sass|less)
|
|
1
|
+
const assetsReg = /\.(png|jpg|jpeg|gif|svg|webp|ico)$/
|
|
2
|
+
const cssReg = /\.(css|scss|less|sass|less)$/
|
|
3
3
|
|
|
4
|
-
export { assetsReg, cssReg }
|
|
4
|
+
export { assetsReg, cssReg }
|
|
@@ -1,76 +1,44 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { assetsReg, cssReg } from '../../config.js';
|
|
2
|
+
import { resolve } from 'path';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
6
|
-
* @param alias
|
|
7
|
-
* @returns
|
|
5
|
+
* esbuild alias 插件
|
|
6
|
+
* @param alias 配置对象
|
|
7
|
+
* @returns 插件
|
|
8
8
|
*/
|
|
9
9
|
const esBuildAlias = (alias) => {
|
|
10
10
|
const entries = alias?.entries;
|
|
11
|
+
let assets = null;
|
|
12
|
+
if (typeof global.lvyConfig?.assets != 'boolean') {
|
|
13
|
+
assets = global.lvyConfig?.assets?.filter ?? assetsReg;
|
|
14
|
+
}
|
|
15
|
+
let styles = null;
|
|
16
|
+
if (typeof global.lvyConfig?.styles != 'boolean') {
|
|
17
|
+
styles = global.lvyConfig?.styles?.filter ?? cssReg;
|
|
18
|
+
}
|
|
11
19
|
return {
|
|
12
20
|
name: 'alias',
|
|
13
21
|
setup(build) {
|
|
14
|
-
// 解析路径时使用 entries
|
|
15
22
|
if (entries) {
|
|
16
23
|
build.onResolve({ filter: /.*/ }, args => {
|
|
17
24
|
const url = args.path;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
return;
|
|
25
|
-
|
|
26
|
-
path: value
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
else if (find instanceof RegExp && find.test(url)) {
|
|
30
|
-
// 正则匹配
|
|
31
|
-
const resolvedPath = url.replace(find, replacement);
|
|
32
|
-
const absolutePath = resolve(resolvedPath);
|
|
33
|
-
const value = checkFileExtensions(absolutePath);
|
|
34
|
-
if (!value)
|
|
35
|
-
return;
|
|
36
|
-
return {
|
|
37
|
-
path: value
|
|
38
|
-
};
|
|
25
|
+
const resolveDir = args.resolveDir;
|
|
26
|
+
if (assets?.test(url) || styles?.test(url)) {
|
|
27
|
+
for (const { find, replacement } of entries) {
|
|
28
|
+
if ((find instanceof RegExp && find.test(url)) ||
|
|
29
|
+
(typeof find === 'string' && url.startsWith(find))) {
|
|
30
|
+
let resolvedPath = url.replace(find, replacement);
|
|
31
|
+
return { path: resolvedPath };
|
|
32
|
+
}
|
|
39
33
|
}
|
|
34
|
+
return {
|
|
35
|
+
path: resolve(resolveDir, url)
|
|
36
|
+
};
|
|
40
37
|
}
|
|
41
|
-
return null;
|
|
42
38
|
});
|
|
43
39
|
}
|
|
44
40
|
}
|
|
45
41
|
};
|
|
46
42
|
};
|
|
47
|
-
/**
|
|
48
|
-
*
|
|
49
|
-
* @param basePath
|
|
50
|
-
* @returns
|
|
51
|
-
*/
|
|
52
|
-
const checkFileExtensions = (basePath) => {
|
|
53
|
-
const extensions = ['.js', '.jsx', '.ts', '.tsx'];
|
|
54
|
-
if (existsSync(basePath)) {
|
|
55
|
-
// const name = basename(basePath)
|
|
56
|
-
// const rest = name.split('.')
|
|
57
|
-
// // 该路径是文件命名法。
|
|
58
|
-
// if (rest.length > 1) {
|
|
59
|
-
// const fileName = rest[rest.length - 1]
|
|
60
|
-
// if (fileName) return basePath
|
|
61
|
-
// }
|
|
62
|
-
// // 不是文件命名,路径存在,推测是路径引用
|
|
63
|
-
// basePath = `${basePath}/index`
|
|
64
|
-
return basePath;
|
|
65
|
-
}
|
|
66
|
-
for (const ext of extensions) {
|
|
67
|
-
const filePath = `${basePath}${ext}`;
|
|
68
|
-
if (existsSync(filePath)) {
|
|
69
|
-
return filePath;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
// 如果没有找到文件,返回 null
|
|
73
|
-
return null;
|
|
74
|
-
};
|
|
75
43
|
|
|
76
44
|
export { esBuildAlias };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const assetsReg = /\.(png|jpg|jpeg|gif|svg|webp|ico)
|
|
2
|
-
const cssReg = /\.(css|scss|less|sass|less)
|
|
1
|
+
const assetsReg = /\.(png|jpg|jpeg|gif|svg|webp|ico)$/
|
|
2
|
+
const cssReg = /\.(css|scss|less|sass|less)$/
|
|
3
3
|
|
|
4
|
-
export { assetsReg, cssReg }
|
|
4
|
+
export { assetsReg, cssReg }
|