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 ADDED
@@ -0,0 +1,4 @@
1
+ const assetsReg = /\.(png|jpg|jpeg|gif|svg|webp|ico)$/;
2
+ const cssReg = /\.(css|scss|less|sass|less)$/;
3
+
4
+ export { assetsReg, cssReg };
@@ -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,4 +1,4 @@
1
- import { assetsReg } from '../config.js';
1
+ import { assetsReg } from '../../config.js';
2
2
  import { generateModuleContent } from '../utils/content.js';
3
3
 
4
4
  /**
@@ -1,76 +1,44 @@
1
- import { join, resolve } from 'path';
2
- import { existsSync } from 'fs';
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
- for (const { find, replacement } of entries) {
19
- if (typeof find === 'string' && url.startsWith(find)) {
20
- const resolvedPath = join(replacement, url.slice(find.length));
21
- const absolutePath = resolve(resolvedPath);
22
- const value = checkFileExtensions(absolutePath);
23
- if (!value)
24
- return;
25
- return {
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,5 +1,5 @@
1
1
  import { generateCSSModuleContent } from '../utils/content.js';
2
- import { cssReg } from '../config.js';
2
+ import { cssReg } from '../../config.js';
3
3
 
4
4
  /**
5
5
  * css资源处理插件
@@ -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,6 +1,6 @@
1
1
  import { createFilter } from '@rollup/pluginutils';
2
2
  import { resolve, dirname, basename } from 'node:path';
3
- import { cssReg } from './config.js';
3
+ import { cssReg } from '../../config.js';
4
4
 
5
5
  /**
6
6
  *
@@ -1,6 +1,6 @@
1
1
  import { resolve, dirname, basename } from 'path';
2
2
  import { readFileSync } from 'fs';
3
- import { assetsReg } from './config.js';
3
+ import { assetsReg } from '../../config.js';
4
4
 
5
5
  /**
6
6
  * @param {Object} options
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lvyjs",
3
- "version": "0.2.5",
3
+ "version": "0.2.6",
4
4
  "description": "tsx compile script",
5
5
  "author": "lemonade",
6
6
  "license": "MIT",