mocksw 1.1.4 → 1.1.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 +9 -0
- package/dist/cli.mjs +0 -1
- package/dist/plugin.d.mts +8 -0
- package/dist/plugin.mjs +15 -0
- package/package.json +6 -1
package/README.md
CHANGED
|
@@ -33,6 +33,15 @@ npx mocksw init public
|
|
|
33
33
|
pnpm exec mocksw init public
|
|
34
34
|
```
|
|
35
35
|
|
|
36
|
+
或者使用内置插件`(推荐)`:
|
|
37
|
+
|
|
38
|
+
```ts
|
|
39
|
+
import { mockswPlugin } from 'mocksw/vite';
|
|
40
|
+
export default defineConfig({
|
|
41
|
+
plugins: [mockswPlugin()], // mockswPlugin('public') 支持显示指定目录
|
|
42
|
+
});
|
|
43
|
+
```
|
|
44
|
+
|
|
36
45
|
这将在指定的目录 `public` 下生成 `swMockWorker.js` worker环境。
|
|
37
46
|
|
|
38
47
|
### 2. 定义 Mock 接口
|
package/dist/cli.mjs
CHANGED
|
@@ -9,7 +9,6 @@ const __dirname = path.dirname(__filename);
|
|
|
9
9
|
const targetDir = process.argv[3] || "public";
|
|
10
10
|
const targetPath = path.resolve(process.cwd(), targetDir);
|
|
11
11
|
const sourcePath = path.join(__dirname, "../public/swMockWorker.js");
|
|
12
|
-
console.log(sourcePath);
|
|
13
12
|
async function init() {
|
|
14
13
|
try {
|
|
15
14
|
if (!fs.existsSync(targetPath)) fs.mkdirSync(targetPath, { recursive: true });
|
package/dist/plugin.mjs
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { execSync } from "node:child_process";
|
|
2
|
+
|
|
3
|
+
//#region src/plugin.ts
|
|
4
|
+
function mockswPlugin(path = "public") {
|
|
5
|
+
return {
|
|
6
|
+
name: "vite-plugin-mocksw",
|
|
7
|
+
enforce: "pre",
|
|
8
|
+
buildStart() {
|
|
9
|
+
execSync(`npx mocksw init ${path}`, { stdio: "inherit" });
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
//#endregion
|
|
15
|
+
export { mockswPlugin };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mocksw",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.5",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "@zstings",
|
|
@@ -22,6 +22,11 @@
|
|
|
22
22
|
".": {
|
|
23
23
|
"import": "./dist/index.js",
|
|
24
24
|
"types": "./dist/index.d.ts"
|
|
25
|
+
},
|
|
26
|
+
"./vite": {
|
|
27
|
+
"types": "./dist/plugin.d.mts",
|
|
28
|
+
"import": "./dist/plugin.mjs",
|
|
29
|
+
"default": "./dist/plugin.mjs"
|
|
25
30
|
}
|
|
26
31
|
},
|
|
27
32
|
"scripts": {
|