@heathenjs/taro-router-plugin 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 +94 -0
- package/dist/index.js +1 -0
- package/package.json +38 -0
package/README.md
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
# @heathenjs/taro-router-plugin
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@heathenjs/taro-router-plugin)
|
|
4
|
+
[](https://www.npmjs.com/package/@heathenjs/taro-router-plugin)
|
|
5
|
+
|
|
6
|
+
在Taro构建时自动生成 [@heathenjs/taro-router](https://www.npmjs.com/package/@heathenjs/taro-router) 所需的路由,并自动配置路由信息到app.config
|
|
7
|
+
|
|
8
|
+
## 特性
|
|
9
|
+
<ol>
|
|
10
|
+
<li>约定式路由生成;</li>
|
|
11
|
+
<li>自动生成路由跳转方法,可按页面的 route.config.ts 配置 进行跳转参数校验;</li>
|
|
12
|
+
<li>自动配置路由信息到 app.config,免去繁杂的页面及分包配置;</li>
|
|
13
|
+
</ol>
|
|
14
|
+
|
|
15
|
+
## 使用
|
|
16
|
+
### Step 1
|
|
17
|
+
安装
|
|
18
|
+
#### pnpm
|
|
19
|
+
```bash
|
|
20
|
+
pnpm add @heathenjs/taro-router-plugin --save-dev
|
|
21
|
+
pnpm add @heathenjs/taro-router
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
#### yarn
|
|
25
|
+
```bash
|
|
26
|
+
yarn add @heathenjs/taro-router-plugin --dev
|
|
27
|
+
yarn add @heathenjs/taro-router
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
#### npm
|
|
31
|
+
```bash
|
|
32
|
+
npm install @heathenjs/taro-router-plugin --save-dev
|
|
33
|
+
npm install @heathenjs/taro-router --save
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### Step 2
|
|
37
|
+
在项目根目录创建配置文件 router.config.json ,参考配置信息如下:
|
|
38
|
+
```json
|
|
39
|
+
{
|
|
40
|
+
"ignore": [
|
|
41
|
+
"components",
|
|
42
|
+
],
|
|
43
|
+
"defaultPage": "pages/default/index/index",
|
|
44
|
+
"packages": [
|
|
45
|
+
{
|
|
46
|
+
"name": "package1",
|
|
47
|
+
"pagePath": "./src/pages/package1"
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
"name": "package2",
|
|
51
|
+
"pagePath": "./src/pages/package2"
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
"name": "default",
|
|
55
|
+
"pagePath": "./src/pages/default",
|
|
56
|
+
"isMainPackage": true
|
|
57
|
+
}
|
|
58
|
+
]
|
|
59
|
+
}
|
|
60
|
+
```
|
|
61
|
+
详见[配置参数说明](#配置参数说明)
|
|
62
|
+
|
|
63
|
+
### Step 3
|
|
64
|
+
taro构建配置中增加插件
|
|
65
|
+
```typescript
|
|
66
|
+
export default {
|
|
67
|
+
plugins: [
|
|
68
|
+
'@heathenjs/taro-router-plugin',
|
|
69
|
+
],
|
|
70
|
+
}
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
完成!此时你不需要在 app.config 中再编写任何路由/页面相关的配置,插件会自动生成。
|
|
74
|
+
|
|
75
|
+
## 配置参数说明
|
|
76
|
+
|
|
77
|
+
### ignore
|
|
78
|
+
不参与路由构建的目录,例如在页面中临时使用的一些组件。配置语法参考[ignore](https://www.npmjs.com/package/ignore)
|
|
79
|
+
> 默认情况下,会将 pagePath 目录下所有 `index.js`/`index.jsx`/`index.jsx`/`index.tsx` 识别为页面文件
|
|
80
|
+
|
|
81
|
+
### defaultPage
|
|
82
|
+
进入小程序时的初始页面。必须是主包的页面。
|
|
83
|
+
|
|
84
|
+
### packages
|
|
85
|
+
分包配置
|
|
86
|
+
|
|
87
|
+
#### name
|
|
88
|
+
分包名
|
|
89
|
+
|
|
90
|
+
#### pagePath
|
|
91
|
+
包页面路径
|
|
92
|
+
|
|
93
|
+
#### isMainPackage
|
|
94
|
+
是否为主包。必须有且仅有一个 package 的 isMainPackage 为true
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var h=Object.create;var i=Object.defineProperty;var d=Object.getOwnPropertyDescriptor;var k=Object.getOwnPropertyNames;var A=Object.getPrototypeOf,S=Object.prototype.hasOwnProperty;var N=(e,o)=>{for(var t in o)i(e,t,{get:o[t],enumerable:!0})},c=(e,o,t,r)=>{if(o&&typeof o=="object"||typeof o=="function")for(let a of k(o))!S.call(e,a)&&a!==t&&i(e,a,{get:()=>o[a],enumerable:!(r=d(o,a))||r.enumerable});return e};var g=(e,o,t)=>(t=e!=null?h(A(e)):{},c(o||!e||!e.__esModule?i(t,"default",{value:e,enumerable:!0}):t,e)),$=e=>c(i({},"__esModule",{value:!0}),e);var y={};N(y,{default:()=>x});module.exports=$(y);var C=require("@heathenjs/taro-router-generator"),f=g(require("fs-extra")),u=g(require("path"));var p=g(require("path")),m=process.cwd(),E=p.default.resolve(m,"./src"),l=({pages:e,config:o,mainPackageName:t})=>{let r=o.packages.filter(s=>s.name!==t).map(s=>({root:p.default.resolve(m,s.pagePath).replace(E,"").slice(1),pages:[]})),a={pages:[],subPackages:r};return e.forEach(s=>{if(s.packageName===t)a.pages.push(s.path.slice(1));else{let n=a.subPackages.find(P=>s.path.startsWith(`${p.default.sep}${P.root}`));n&&n.pages.push(s.path.replace(`${p.default.sep}${n.root}${p.default.sep}`,""))}}),o.defaultPage&&a.pages.sort(s=>s===o.defaultPage?-1:0),a};var b="router.config.json",x=e=>{let o=u.default.resolve(process.cwd(),`./${b}`),t=f.default.existsSync(o),r={};if(t){let a=f.default.readFileSync(o,{encoding:"utf8"});r=JSON.parse(a)}else throw`\u627E\u4E0D\u5230 ${o}\uFF0C\u8BF7\u68C0\u67E5\u914D\u7F6E\u6587\u4EF6\u53CA\u6267\u884C\u8DEF\u5F84\u3002`;r.packages=r.packages??[],r.ignore=r.ignore??[".DS_Store"],e.onBuildStart(()=>{let a=new C.Generator(r);a.generateRouter(),e.modifyAppConfig(({appConfig:s})=>{Object.assign(s,l({config:r,pages:a.getPages(),mainPackageName:a.getMainPackageName()}))}),console.log()})};
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@heathenjs/taro-router-plugin",
|
|
3
|
+
"version": "1.1.5",
|
|
4
|
+
"description": "在Taro构建时自动生成路由方法及页面路由配置",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"files": [
|
|
7
|
+
"dist",
|
|
8
|
+
"package.json",
|
|
9
|
+
"README.md"
|
|
10
|
+
],
|
|
11
|
+
"keywords": [
|
|
12
|
+
"taro",
|
|
13
|
+
"router",
|
|
14
|
+
"plugin",
|
|
15
|
+
"miniprogram"
|
|
16
|
+
],
|
|
17
|
+
"publishConfig": {
|
|
18
|
+
"access": "public",
|
|
19
|
+
"registry": "https://registry.npmjs.org/"
|
|
20
|
+
},
|
|
21
|
+
"author": "heathen1998",
|
|
22
|
+
"license": "MIT",
|
|
23
|
+
"peerDependencies": {
|
|
24
|
+
"@tarojs/service": "^3.6.35",
|
|
25
|
+
"@tarojs/taro": "^3.6.35"
|
|
26
|
+
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"fs-extra": "^11.3.3",
|
|
29
|
+
"@heathenjs/taro-router-generator": "1.1.5"
|
|
30
|
+
},
|
|
31
|
+
"scripts": {
|
|
32
|
+
"clean": "rimraf dist",
|
|
33
|
+
"build:script": "tsx build.ts",
|
|
34
|
+
"build": "npm run clean && npm run build:script",
|
|
35
|
+
"tsc": "tsc -p ./tsconfig.json --noEmit",
|
|
36
|
+
"lint": "eslint --ext .ts --max-warnings 0 \"./src\" "
|
|
37
|
+
}
|
|
38
|
+
}
|