@deot/dev-dever 2.5.3 → 2.5.5

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/README.md CHANGED
@@ -36,4 +36,15 @@ export default mergeConfig(
36
36
  );
37
37
  ```
38
38
 
39
- 取`dev.config.ts`, 是为了方便从`vite`转其他开发工具时,可以不改变文件名
39
+ 取`dev.config.ts`, 是为了方便从`vite`转其他开发工具时,可以不改变文件名
40
+
41
+ ## 预加载配置`preload.ts`
42
+
43
+ 会查找当前文件夹路径下往前查找`preload.ts`文件,直至`process.cwd()`,如果存件,就近添加`preload.ts`
44
+
45
+ 文件查找优先级
46
+
47
+ - `z.dev.preload.ts`
48
+ - `dev.preload.ts`
49
+ - `z.preload.ts`
50
+ - `preload.ts`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deot/dev-dever",
3
- "version": "2.5.3",
3
+ "version": "2.5.5",
4
4
  "type": "module",
5
5
  "main": "dist/index.es.js",
6
6
  "types": "dist/index.d.ts",
@@ -25,7 +25,7 @@
25
25
  "@deot/dev-shared": "^2.5.0",
26
26
  "@deot/dev-vue": "^2.5.1",
27
27
  "ejs": "^3.1.9",
28
- "vite": "^4.4.9"
28
+ "vite": "^4.4.11"
29
29
  },
30
30
  "devDependencies": {
31
31
  "@deot/dev-test": "^2.5.0",
package/shared.config.ts CHANGED
@@ -58,6 +58,28 @@ const getVirtualHtml = async (url: string) => {
58
58
  const fullpath = path.join(dir, `${entry.replace(/(.*)(\..*)$/, '$1') + ext}`);
59
59
  return fs.existsSync(fullpath) ? fullpath : false;
60
60
  };
61
+
62
+ const getPreload = (fullpath: string) => {
63
+ let dir$ = path.dirname(fullpath);
64
+ let preload = '';
65
+ while (dir$.includes(cwd) && !preload) {
66
+
67
+ let preloadFullPath = [
68
+ path.resolve(dir$, './z.dev.preload.ts'),
69
+ path.resolve(dir$, './dev.preload.ts'),
70
+ path.resolve(dir$, './z.preload.ts'),
71
+ path.resolve(dir$, './preload.ts')
72
+ ].find(i => fs.existsSync(i));
73
+
74
+ if (preloadFullPath) {
75
+ preload = ` import "/${path.relative(cwd, preloadFullPath)}";\n`;
76
+ } else {
77
+ dir$ = path.resolve(dir$, '..');
78
+ }
79
+ }
80
+
81
+ return preload;
82
+ };
61
83
 
62
84
  const htmlFullpath = isExist('.html');
63
85
  if (htmlFullpath) {
@@ -66,14 +88,14 @@ const getVirtualHtml = async (url: string) => {
66
88
 
67
89
  const tsFullpath = isExist('.ts');
68
90
  if (tsFullpath) {
69
- let inject = '';
91
+ let inject = getPreload(tsFullpath);
70
92
  inject += ` import "/${path.relative(cwd, tsFullpath)}";\n`;
71
93
  return generateIndexHtml(url, inject);
72
94
  }
73
95
 
74
96
  const vueFullpath = isExist('.vue');
75
97
  if (vueFullpath) {
76
- let inject = '';
98
+ let inject = getPreload(vueFullpath);
77
99
  inject += ` import { createApp } from "vue"\n`;
78
100
  inject += ` import App from "/${path.relative(cwd, vueFullpath)}";\n`;
79
101
  inject += ` const app = createApp(App);\n`;
@@ -84,7 +106,7 @@ const getVirtualHtml = async (url: string) => {
84
106
 
85
107
  const tsxFullpath = isExist('.tsx');
86
108
  if (tsxFullpath) {
87
- let inject = '';
109
+ let inject = getPreload(tsxFullpath);
88
110
  inject += ` import React, { StrictMode } from 'react';`;
89
111
  inject += ` import { createRoot } from 'react-dom/client';`;
90
112
  inject += ` import App from "/${path.relative(cwd, tsxFullpath)}";\n`;