@deot/dev-dever 2.5.3 → 2.5.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.
package/README.md CHANGED
@@ -36,4 +36,8 @@ 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`
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.4",
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,21 @@ 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$ !== cwd && !preload) {
66
+ let preloadFullPath = path.resolve(dir$, './preload.ts');
67
+ if (fs.existsSync(preloadFullPath)) {
68
+ preload = ` import "/${path.relative(cwd, preloadFullPath)}";\n`;
69
+ } else {
70
+ dir$ = path.resolve(dir$, '..');
71
+ }
72
+ }
73
+
74
+ return preload;
75
+ };
61
76
 
62
77
  const htmlFullpath = isExist('.html');
63
78
  if (htmlFullpath) {
@@ -66,14 +81,14 @@ const getVirtualHtml = async (url: string) => {
66
81
 
67
82
  const tsFullpath = isExist('.ts');
68
83
  if (tsFullpath) {
69
- let inject = '';
84
+ let inject = getPreload(tsFullpath);
70
85
  inject += ` import "/${path.relative(cwd, tsFullpath)}";\n`;
71
86
  return generateIndexHtml(url, inject);
72
87
  }
73
88
 
74
89
  const vueFullpath = isExist('.vue');
75
90
  if (vueFullpath) {
76
- let inject = '';
91
+ let inject = getPreload(vueFullpath);
77
92
  inject += ` import { createApp } from "vue"\n`;
78
93
  inject += ` import App from "/${path.relative(cwd, vueFullpath)}";\n`;
79
94
  inject += ` const app = createApp(App);\n`;
@@ -84,7 +99,7 @@ const getVirtualHtml = async (url: string) => {
84
99
 
85
100
  const tsxFullpath = isExist('.tsx');
86
101
  if (tsxFullpath) {
87
- let inject = '';
102
+ let inject = getPreload(tsxFullpath);
88
103
  inject += ` import React, { StrictMode } from 'react';`;
89
104
  inject += ` import { createRoot } from 'react-dom/client';`;
90
105
  inject += ` import App from "/${path.relative(cwd, tsxFullpath)}";\n`;