# 6、设置页面只在开发模式下被HBX打包
# 你可能会有这样的需求
在开发时,有一些测试页面,而这些测试页面不想在正式上线时被用户访问到。
以 设置 pages_template
目录内的所有页面仅在开发模式下生效为例。
# 步骤
# 1、在项目根目录新建文件 pages-dev.json
{
"subPackages": [{
"root": "pages_template",
"pages": [{
"path": "db-test/db-test",
"style": {
"navigationBarTitleText": "数据库调用示例"
}
},
{
"path": "db-test/list/list",
"style": {
"navigationBarTitleText": "列表渲染 - 分页加载"
}
},
{
"path": "uni-id/index/index",
"style": {
"navigationBarTitleText": "云函数调用示例-uni-id"
}
},
{
"path": "uni-id/password/password",
"style": {}
},
{
"path": "uni-id/mobile/mobile",
"style": {}
},
{
"path": "uni-id/univerify/univerify",
"style": {}
},
{
"path": "uni-id/weixin/weixin",
"style": {}
},
{
"path": "uni-id/alipay/alipay",
"style": {}
},
{
"path": "uni-id/util/util",
"style": {}
},
{
"path": "uni-id/email/email",
"style": {}
},
{
"path": "uni-id/login/index/index",
"style": {
"navigationBarTitleText": "登录"
}
},
{
"path": "uni-id/login/register/register",
"style": {
"navigationBarTitleText": "注册"
}
},
{
"path": "uni-id/login/forget/forget",
"style": {
"navigationBarTitleText": "找回密码"
}
},
{
"path": "vk-vuex/vk-vuex",
"style": {
"navigationBarTitleText": "vuex演示示例"
}
},
{
"path": "openapi/weixin/weixin",
"style": {}
},
{
"path": "openapi/weixin/msgSecCheck/msgSecCheck",
"style": {}
},
{
"path": "openapi/weixin/imgSecCheck/imgSecCheck",
"style": {}
},
{
"path": "openapi/weixin/sendMessage/sendMessage",
"style": {}
},
{
"path": "openapi/baidu/baidu",
"style": {}
}]
}]
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# 2、删除 package.json
内原有的 pages_template
分包
若删除后需要保留 "subPackages": [], 若删除后需要保留 "subPackages": [], 若删除后需要保留 "subPackages": [],
# 3、项目根目录新建文件 pages.js
const debug = process.env.NODE_ENV !== 'production';
var devPages;
try {
devPages = require('./pages-dev.json');
} catch(err) {}
module.exports = function(pagesJson) {
try {
let newDevPages = JSON.parse(JSON.stringify(devPages));
if (debug && newDevPages) {
for (let keyName in newDevPages ) {
let item = newDevPages [keyName]
if (Object.prototype.toString.call(item) === "[object Array]") {
pagesJson[keyName].push(...item);
} else if (Object.prototype.toString.call(item) === '[object Object]') {
pagesJson[keyName] = Object.assign(pagesJson[keyName], item);
}
}
}
} catch(err) {
console.log(err);
}
return pagesJson;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23