Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
陈庄旺
uni-app
提交
2326c09e
U
uni-app
项目概览
陈庄旺
/
uni-app
与 Fork 源项目一致
Fork自
DCloud / uni-app
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
2326c09e
编写于
10月 11, 2021
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
wip(mp): project.config.json
上级
ef697f1d
变更
15
展开全部
隐藏空白更改
内联
并排
Showing
15 changed file
with
2468 addition
and
2023 deletion
+2468
-2023
packages/uni-app-plus/dist/uni-app-service.es.js
packages/uni-app-plus/dist/uni-app-service.es.js
+73
-73
packages/uni-cli-shared/src/json/index.ts
packages/uni-cli-shared/src/json/index.ts
+1
-0
packages/uni-cli-shared/src/json/mp/index.ts
packages/uni-cli-shared/src/json/mp/index.ts
+3
-0
packages/uni-cli-shared/src/json/mp/jsonFile.ts
packages/uni-cli-shared/src/json/mp/jsonFile.ts
+17
-0
packages/uni-cli-shared/src/json/mp/pages.ts
packages/uni-cli-shared/src/json/mp/pages.ts
+120
-0
packages/uni-cli-shared/src/json/mp/project.ts
packages/uni-cli-shared/src/json/mp/project.ts
+46
-0
packages/uni-cli-shared/src/json/mp/types.ts
packages/uni-cli-shared/src/json/mp/types.ts
+127
-0
packages/uni-cli-shared/src/json/mp/utils.ts
packages/uni-cli-shared/src/json/mp/utils.ts
+85
-0
packages/uni-cli-shared/src/json/pages.ts
packages/uni-cli-shared/src/json/pages.ts
+28
-9
packages/uni-mp-vite/src/plugin/index.ts
packages/uni-mp-vite/src/plugin/index.ts
+1
-1
packages/uni-mp-vite/src/plugins/manifestJson.ts
packages/uni-mp-vite/src/plugins/manifestJson.ts
+34
-25
packages/uni-mp-vite/src/plugins/pagesJson.ts
packages/uni-mp-vite/src/plugins/pagesJson.ts
+43
-27
packages/uni-mp-vite/src/plugins/virtual.ts
packages/uni-mp-vite/src/plugins/virtual.ts
+2
-0
packages/uni-stat/dist/uni-stat.cjs.js
packages/uni-stat/dist/uni-stat.cjs.js
+944
-944
packages/uni-stat/dist/uni-stat.es.js
packages/uni-stat/dist/uni-stat.es.js
+944
-944
未找到文件。
packages/uni-app-plus/dist/uni-app-service.es.js
浏览文件 @
2326c09e
...
...
@@ -10,79 +10,79 @@ const __uniRoutes = instanceContext.__uniRoutes;
var serviceContext = (function (vue) {
'use strict';
/*
* base64-arraybuffer
* https://github.com/niklasvh/base64-arraybuffer
*
* Copyright (c) 2012 Niklas von Hertzen
* Licensed under the MIT license.
*/
var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
// Use a lookup table to find the index.
var lookup = /*#__PURE__*/ (function () {
const lookup = new Uint8Array(256);
for (var i = 0; i < chars.length; i++) {
lookup[chars.charCodeAt(i)] = i;
}
return lookup
})();
function encode$3(arraybuffer) {
var bytes = new Uint8Array(arraybuffer),
i,
len = bytes.length,
base64 = '';
for (i = 0; i < len; i += 3) {
base64 += chars[bytes[i] >> 2];
base64 += chars[((bytes[i] & 3) << 4) | (bytes[i + 1] >> 4)];
base64 += chars[((bytes[i + 1] & 15) << 2) | (bytes[i + 2] >> 6)];
base64 += chars[bytes[i + 2] & 63];
}
if (len % 3 === 2) {
base64 = base64.substring(0, base64.length - 1) + '=';
} else if (len % 3 === 1) {
base64 = base64.substring(0, base64.length - 2) + '==';
}
return base64
}
function decode$1(base64) {
var bufferLength = base64.length * 0.75,
len = base64.length,
i,
p = 0,
encoded1,
encoded2,
encoded3,
encoded4;
if (base64[base64.length - 1] === '=') {
bufferLength--;
if (base64[base64.length - 2] === '=') {
bufferLength--;
}
}
var arraybuffer = new ArrayBuffer(bufferLength),
bytes = new Uint8Array(arraybuffer);
for (i = 0; i < len; i += 4) {
encoded1 = lookup[base64.charCodeAt(i)];
encoded2 = lookup[base64.charCodeAt(i + 1)];
encoded3 = lookup[base64.charCodeAt(i + 2)];
encoded4 = lookup[base64.charCodeAt(i + 3)];
bytes[p++] = (encoded1 << 2) | (encoded2 >> 4);
bytes[p++] = ((encoded2 & 15) << 4) | (encoded3 >> 2);
bytes[p++] = ((encoded3 & 3) << 6) | (encoded4 & 63);
}
return arraybuffer
/*
* base64-arraybuffer
* https://github.com/niklasvh/base64-arraybuffer
*
* Copyright (c) 2012 Niklas von Hertzen
* Licensed under the MIT license.
*/
var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
// Use a lookup table to find the index.
var lookup = /*#__PURE__*/ (function () {
const lookup = new Uint8Array(256);
for (var i = 0; i < chars.length; i++) {
lookup[chars.charCodeAt(i)] = i;
}
return lookup
})();
function encode$3(arraybuffer) {
var bytes = new Uint8Array(arraybuffer),
i,
len = bytes.length,
base64 = '';
for (i = 0; i < len; i += 3) {
base64 += chars[bytes[i] >> 2];
base64 += chars[((bytes[i] & 3) << 4) | (bytes[i + 1] >> 4)];
base64 += chars[((bytes[i + 1] & 15) << 2) | (bytes[i + 2] >> 6)];
base64 += chars[bytes[i + 2] & 63];
}
if (len % 3 === 2) {
base64 = base64.substring(0, base64.length - 1) + '=';
} else if (len % 3 === 1) {
base64 = base64.substring(0, base64.length - 2) + '==';
}
return base64
}
function decode$1(base64) {
var bufferLength = base64.length * 0.75,
len = base64.length,
i,
p = 0,
encoded1,
encoded2,
encoded3,
encoded4;
if (base64[base64.length - 1] === '=') {
bufferLength--;
if (base64[base64.length - 2] === '=') {
bufferLength--;
}
}
var arraybuffer = new ArrayBuffer(bufferLength),
bytes = new Uint8Array(arraybuffer);
for (i = 0; i < len; i += 4) {
encoded1 = lookup[base64.charCodeAt(i)];
encoded2 = lookup[base64.charCodeAt(i + 1)];
encoded3 = lookup[base64.charCodeAt(i + 2)];
encoded4 = lookup[base64.charCodeAt(i + 3)];
bytes[p++] = (encoded1 << 2) | (encoded2 >> 4);
bytes[p++] = ((encoded2 & 15) << 4) | (encoded3 >> 2);
bytes[p++] = ((encoded3 & 3) << 6) | (encoded4 & 63);
}
return arraybuffer
}
/**
...
...
packages/uni-cli-shared/src/json/index.ts
浏览文件 @
2326c09e
export
*
from
'
./mp
'
export
*
from
'
./app
'
export
*
from
'
./json
'
export
*
from
'
./pages
'
...
...
packages/uni-cli-shared/src/json/mp/index.ts
0 → 100644
浏览文件 @
2326c09e
export
{
AppJson
}
from
'
./types
'
export
{
parseMiniProgramPagesJson
}
from
'
./pages
'
export
{
parseMiniProgramProjectJson
}
from
'
./project
'
packages/uni-cli-shared/src/json/mp/jsonFile.ts
0 → 100644
浏览文件 @
2326c09e
import
{
ComponentJson
,
PageWindowOptions
,
UsingComponents
}
from
'
./types
'
export
const
jsonPagesCache
=
new
Map
<
string
,
PageWindowOptions
>
()
export
const
jsonComponentsCache
=
new
Map
<
string
,
ComponentJson
>
()
export
const
jsonUsingComponentsCache
=
new
Map
<
string
,
UsingComponents
>
()
export
function
addPageJson
(
filename
:
string
,
json
:
PageWindowOptions
)
{
jsonPagesCache
.
set
(
filename
,
json
)
}
export
function
addComponentJson
(
filename
:
string
,
json
:
ComponentJson
)
{
jsonComponentsCache
.
set
(
filename
,
json
)
}
export
function
addUsingComponents
(
filename
:
string
,
json
:
UsingComponents
)
{
jsonUsingComponentsCache
.
set
(
filename
,
json
)
}
packages/uni-cli-shared/src/json/mp/pages.ts
0 → 100644
浏览文件 @
2326c09e
import
path
from
'
path
'
import
{
hasOwn
}
from
'
@vue/shared
'
import
{
parseJson
}
from
'
../json
'
import
{
validatePages
}
from
'
../pages
'
import
{
AppJson
,
NetworkTimeout
,
PageWindowOptions
}
from
'
./types
'
import
{
parseTabBar
,
parseWindowOptions
}
from
'
./utils
'
import
{
normalizePath
}
from
'
../../utils
'
interface
ParsePagesJsonOptions
{
debug
?:
boolean
darkmode
?:
boolean
subpackages
:
boolean
windowOptionsMap
?:
Record
<
string
,
string
>
tabBarOptionsMap
?:
Record
<
string
,
string
>
tabBarItemOptionsMap
?:
Record
<
string
,
string
>
networkTimeout
?:
NetworkTimeout
}
export
function
parseMiniProgramPagesJson
(
jsonStr
:
string
,
platform
:
UniApp
.
PLATFORM
,
options
:
ParsePagesJsonOptions
=
{
subpackages
:
false
}
)
{
return
parsePagesJson
(
jsonStr
,
platform
,
options
)
}
function
parsePagesJson
(
jsonStr
:
string
,
platform
:
UniApp
.
PLATFORM
,
{
debug
,
darkmode
,
networkTimeout
,
subpackages
,
windowOptionsMap
,
}:
ParsePagesJsonOptions
=
{
subpackages
:
false
,
}
)
{
const
appJson
:
AppJson
=
{
pages
:
[],
}
const
pageJsons
:
Record
<
string
,
PageWindowOptions
>
=
{}
// preprocess
const
pagesJson
=
parseJson
(
jsonStr
,
true
)
as
UniApp
.
PagesJson
if
(
!
pagesJson
)
{
throw
new
Error
(
`[vite] Error: pages.json parse failed.\n`
)
}
function
addPageJson
(
pagePath
:
string
,
style
:
UniApp
.
PagesJsonPageStyle
)
{
pageJsons
[
pagePath
]
=
parseWindowOptions
(
style
,
platform
,
windowOptionsMap
)
}
// pages
validatePages
(
pagesJson
,
jsonStr
)
pagesJson
.
pages
.
forEach
((
page
)
=>
{
appJson
.
pages
.
push
(
page
.
path
)
addPageJson
(
page
.
path
,
page
.
style
)
})
// subpackages
pagesJson
.
subPackages
=
pagesJson
.
subPackages
||
pagesJson
.
subpackages
if
(
pagesJson
.
subPackages
)
{
if
(
subpackages
)
{
appJson
.
subPackages
=
pagesJson
.
subPackages
.
map
(({
root
,
pages
})
=>
{
return
{
root
,
pages
:
pages
.
map
((
page
)
=>
{
addPageJson
(
normalizePath
(
path
.
join
(
root
,
page
.
path
)),
page
.
style
)
return
page
.
path
}),
}
})
}
else
{
pagesJson
.
subPackages
.
forEach
(({
root
,
pages
})
=>
{
pages
.
forEach
((
page
)
=>
{
const
pagePath
=
normalizePath
(
path
.
join
(
root
,
page
.
path
))
appJson
.
pages
.
push
(
pagePath
)
addPageJson
(
pagePath
,
page
.
style
)
})
})
}
}
// window
if
(
pagesJson
.
globalStyle
)
{
appJson
.
window
=
parseWindowOptions
(
pagesJson
.
globalStyle
,
platform
,
windowOptionsMap
)
}
// tabBar
if
(
pagesJson
.
tabBar
)
{
const
tabBar
=
parseTabBar
(
pagesJson
.
tabBar
!
,
platform
)
if
(
tabBar
)
{
appJson
.
tabBar
=
tabBar
}
}
;[
'
preloadRule
'
,
'
workers
'
,
'
usingComponents
'
].
forEach
((
name
)
=>
{
if
(
hasOwn
(
pagesJson
,
name
))
{
appJson
[
name
]
=
pagesJson
[
name
]
}
})
if
(
debug
)
{
appJson
.
debug
=
debug
}
if
(
networkTimeout
)
{
appJson
.
networkTimeout
=
networkTimeout
}
if
(
darkmode
)
{
appJson
.
darkmode
=
true
appJson
.
themeLocation
=
'
theme.json
'
}
return
{
appJson
,
pageJsons
,
}
}
packages/uni-cli-shared/src/json/mp/project.ts
0 → 100644
浏览文件 @
2326c09e
import
{
hasOwn
}
from
'
@vue/shared
'
import
{
parseJson
}
from
'
../json
'
interface
ParseMiniProgramProjectJsonOptions
{
template
:
Record
<
string
,
any
>
}
interface
ProjectConfig
{
projectname
:
string
}
const
projectKeys
=
[
'
appid
'
,
'
setting
'
,
'
miniprogramRoot
'
,
'
cloudfunctionRoot
'
,
'
qcloudRoot
'
,
'
pluginRoot
'
,
'
compileType
'
,
'
libVersion
'
,
'
projectname
'
,
'
packOptions
'
,
'
debugOptions
'
,
'
scripts
'
,
'
cloudbaseRoot
'
,
]
export
function
parseMiniProgramProjectJson
(
jsonStr
:
string
,
platform
:
UniApp
.
PLATFORM
,
{
template
}:
ParseMiniProgramProjectJsonOptions
)
{
const
project
=
JSON
.
parse
(
JSON
.
stringify
(
template
))
as
ProjectConfig
const
manifestJson
=
parseJson
(
jsonStr
)
if
(
manifestJson
)
{
project
.
projectname
=
manifestJson
.
name
const
platformConfig
=
manifestJson
[
platform
]
if
(
platformConfig
)
{
projectKeys
.
forEach
((
name
)
=>
{
if
(
hasOwn
(
platformConfig
,
name
))
{
;(
project
as
Record
<
string
,
any
>
)[
name
]
=
platformConfig
[
name
]
}
})
}
}
return
project
}
packages/uni-cli-shared/src/json/mp/types.ts
0 → 100644
浏览文件 @
2326c09e
export
interface
ComponentJson
{
component
:
true
usingComponents
?:
UsingComponents
}
interface
ShareWindowOptions
{
navigationBarBackgroundColor
?:
string
// #000000
navigationBarTextStyle
?:
'
white
'
|
'
black
'
// white
navigationBarTitleText
?:
string
navigationStyle
?:
'
default
'
|
'
custom
'
// default
backgroundColor
?:
string
// #ffffff
backgroundTextStyle
?:
'
dark
'
|
'
light
'
// dark
backgroundColorTop
?:
string
// #ffffff
backgroundColorBottom
?:
string
// #ffffff
enablePullDownRefresh
?:
boolean
// false
onReachBottomDistance
?:
number
// 50
pageOrientation
?:
'
portrait
'
|
'
landscape
'
|
'
auto
'
// portrait
}
type
Style
=
'
v2
'
|
string
type
RestartStrategy
=
'
homePage
'
|
'
homePageAndLatestPage
'
|
string
export
interface
PageWindowOptions
extends
ShareWindowOptions
{
disableScroll
?:
boolean
// false
usingComponents
?:
UsingComponents
initialRenderingCache
?:
'
static
'
|
string
style
?:
Style
singlePage
?:
SinglePage
restartStrategy
?:
RestartStrategy
}
export
interface
AppWindowOptions
extends
ShareWindowOptions
{
visualEffectInBackground
?:
'
none
'
|
'
hidden
'
// none
}
interface
SubPackage
{
name
?:
string
root
:
string
pages
:
string
[]
independent
?:
boolean
}
interface
TabBarItem
{
pagePath
:
string
text
:
string
iconPath
?:
string
selectedIconPath
?:
string
}
export
interface
TabBar
{
color
:
string
selectedColor
:
string
backgroundColor
:
string
borderStyle
?:
'
black
'
|
'
white
'
// black
list
:
TabBarItem
[]
position
?:
'
bottom
'
|
'
top
'
// bottom
custom
?:
boolean
}
export
interface
NetworkTimeout
{
request
?:
number
// 60000
requeconnectSocketst
?:
number
// 60000
uploadFile
?:
number
// 60000
downloadFile
?:
number
// 60000
}
interface
Plugins
{
[
name
:
string
]:
{
version
:
string
provider
:
string
}
}
interface
PreloadRule
{
[
name
:
string
]:
{
network
:
'
wifi
'
|
'
all
'
// wifi
packages
:
string
[]
}
}
export
interface
UsingComponents
{
[
name
:
string
]:
string
}
interface
Permission
{
[
name
:
string
]:
{
desc
:
string
}
}
interface
UseExtendedLib
{
kbone
:
boolean
weui
:
boolean
}
interface
EntranceDeclare
{
locationMessage
:
{
path
:
string
query
:
string
}
}
interface
SinglePage
{
navigationBarFit
?:
'
squeezed
'
|
'
float
'
}
export
interface
AppJson
{
entryPagePath
?:
string
// mp-weixin
pages
:
string
[]
window
?:
AppWindowOptions
tabBar
?:
TabBar
networkTimeout
?:
NetworkTimeout
debug
?:
boolean
functionalPages
?:
boolean
subPackages
?:
SubPackage
[]
workers
?:
string
requiredBackgroundModes
?:
string
[]
// audio,location
plugins
?:
Plugins
preloadRule
?:
PreloadRule
resizable
?:
boolean
usingComponents
?:
UsingComponents
permission
?:
Permission
sitemapLocation
?:
string
style
?:
Style
useExtendedLib
?:
UseExtendedLib
entranceDeclare
?:
EntranceDeclare
darkmode
?:
boolean
themeLocation
?:
string
lazyCodeLoading
?:
'
requiredComponents
'
|
string
singlePage
?:
SinglePage
restartStrategy
?:
RestartStrategy
}
packages/uni-cli-shared/src/json/mp/utils.ts
0 → 100644
浏览文件 @
2326c09e
import
{
extend
,
hasOwn
}
from
'
@vue/shared
'
import
{
removePlatformStyle
}
from
'
../pages
'
import
{
AppWindowOptions
,
PageWindowOptions
,
TabBar
}
from
'
./types
'
function
trimJson
(
json
:
Record
<
string
,
any
>
)
{
delete
json
.
maxWidth
delete
json
.
topWindow
delete
json
.
leftWindow
delete
json
.
rightWindow
if
(
json
.
tabBar
)
{
delete
json
.
tabBar
.
matchMedia
}
return
json
}
function
convert
(
to
:
Record
<
string
,
any
>
,
from
:
Record
<
string
,
any
>
,
map
:
Record
<
string
,
string
>
)
{
Object
.
keys
(
map
).
forEach
((
key
)
=>
{
if
(
hasOwn
(
from
,
map
[
key
]))
{
to
[
key
]
=
from
[
map
[
key
]]
}
})
return
to
}
export
function
parseWindowOptions
(
style
:
UniApp
.
PagesJsonPageStyle
,
platform
:
UniApp
.
PLATFORM
,
windowOptionsMap
?:
Record
<
string
,
string
>
):
PageWindowOptions
|
AppWindowOptions
{
if
(
!
style
)
{
return
{}
}
const
platformStyle
=
style
[
platform
]
||
{}
removePlatformStyle
(
trimJson
(
style
)
as
any
)
const
res
:
PageWindowOptions
|
AppWindowOptions
=
{}
if
(
windowOptionsMap
)
{
return
extend
(
convert
(
res
,
style
,
windowOptionsMap
),
platformStyle
)
}
return
extend
(
res
,
style
,
platformStyle
)
}
function
trimTabBarJson
(
tabBar
:
UniApp
.
TabBarOptions
)
{
;(
[
'
fontSize
'
,
'
height
'
,
'
iconWidth
'
,
'
midButton
'
,
'
selectedIndex
'
,
'
spacing
'
,
]
as
const
).
forEach
((
name
)
=>
{
delete
tabBar
[
name
]
})
return
tabBar
}
export
function
parseTabBar
(
tabBar
:
UniApp
.
TabBarOptions
,
platform
:
UniApp
.
PLATFORM
,
tabBarOptionsMap
?:
Record
<
string
,
string
>
,
tabBarItemOptionsMap
?:
Record
<
string
,
string
>
):
TabBar
{
const
platformStyle
=
(
tabBar
as
any
)[
platform
]
||
{}
removePlatformStyle
(
trimTabBarJson
(
tabBar
)
as
any
)
const
res
=
{}
as
TabBar
if
(
tabBarOptionsMap
)
{
if
(
tabBarItemOptionsMap
&&
tabBar
.
list
)
{
tabBar
.
list
=
tabBar
.
list
.
map
((
item
)
=>
{
return
convert
(
{},
item
,
tabBarItemOptionsMap
)
as
UniApp
.
TabBarItemOptions
})
}
convert
(
res
,
tabBar
,
tabBarOptionsMap
)
return
extend
(
res
,
platformStyle
)
}
return
extend
(
res
,
tabBar
,
platformStyle
)
}
packages/uni-cli-shared/src/json/pages.ts
浏览文件 @
2326c09e
...
...
@@ -20,7 +20,15 @@ export const parsePagesJson = (
export
const
parsePagesJsonOnce
=
once
(
parsePagesJson
)
export
function
normalizePagesJson
(
jsonStr
:
string
,
platform
:
UniApp
.
PLATFORM
)
{
export
function
normalizePagesJson
(
jsonStr
:
string
,
platform
:
UniApp
.
PLATFORM
,
{
subpackages
,
}:
{
subpackages
:
boolean
}
=
{
subpackages
:
false
}
)
{
let
pagesJson
:
UniApp
.
PagesJson
=
{
pages
:
[],
globalStyle
:
{
...
...
@@ -35,10 +43,21 @@ export function normalizePagesJson(jsonStr: string, platform: UniApp.PLATFORM) {
}
// pages
validatePages
(
pagesJson
,
jsonStr
)
pagesJson
.
subPackages
=
pagesJson
.
subPackages
||
pagesJson
.
subpackages
delete
pagesJson
.
subpackages
// subpackages
pagesJson
.
pages
.
push
(
...
normalizeSubpackages
(
pagesJson
.
subPackages
||
pagesJson
.
subpackages
)
)
if
(
pagesJson
.
subPackages
)
{
if
(
subpackages
)
{
pagesJson
.
subPackages
.
forEach
(({
pages
})
=>
{
pages
&&
normalizePages
(
pages
,
platform
)
})
}
else
{
pagesJson
.
pages
.
push
(...
normalizeSubpackages
(
pagesJson
.
subPackages
))
delete
pagesJson
.
subPackages
}
}
else
{
delete
pagesJson
.
subPackages
}
// pageStyle
normalizePages
(
pagesJson
.
pages
,
platform
)
...
...
@@ -64,7 +83,7 @@ export function normalizePagesJson(jsonStr: string, platform: UniApp.PLATFORM) {
return
pagesJson
}
function
validatePages
(
pagesJson
:
Record
<
string
,
any
>
,
jsonStr
:
string
)
{
export
function
validatePages
(
pagesJson
:
Record
<
string
,
any
>
,
jsonStr
:
string
)
{
if
(
!
Array
.
isArray
(
pagesJson
.
pages
))
{
pagesJson
.
pages
=
[]
throw
new
Error
(
`[uni-app] Error: pages.json->pages parse failed.`
)
...
...
@@ -79,9 +98,8 @@ function normalizePages(
pages
:
UniApp
.
PagesJsonPageOptions
[],
platform
:
UniApp
.
PLATFORM
)
{
return
pages
.
f
ilter
((
page
)
=>
{
return
pages
.
f
orEach
((
page
)
=>
{
page
.
style
=
normalizePageStyle
(
page
.
path
,
page
.
style
!
,
platform
)
return
true
})
}
...
...
@@ -151,7 +169,8 @@ function normalizePageStyle(
}
}
pageStyle
.
isNVue
=
isNVue
return
removePlatformStyle
(
pageStyle
)
removePlatformStyle
(
pageStyle
)
return
pageStyle
}
return
{
navigationBar
:
{},
isNVue
}
}
...
...
@@ -347,7 +366,7 @@ function normalizeFilepath(filepath: string) {
const
platforms
=
[
'
h5
'
,
'
app
'
,
'
mp-
'
,
'
quickapp
'
]
function
removePlatformStyle
(
pageStyle
:
UniApp
.
PagesJsonPageStyle
)
{
export
function
removePlatformStyle
(
pageStyle
:
Record
<
string
,
any
>
)
{
Object
.
keys
(
pageStyle
).
forEach
((
name
)
=>
{
if
(
platforms
.
find
((
prefix
)
=>
name
.
startsWith
(
prefix
)))
{
delete
pageStyle
[
name
as
UniApp
.
PLATFORM
]
...
...
packages/uni-mp-vite/src/plugin/index.ts
浏览文件 @
2326c09e
...
...
@@ -28,7 +28,7 @@ export interface UniMiniProgramPluginOptions {
}
project
?:
{
filename
:
string
source
:
Record
<
string
,
unknown
>
source
:
Record
<
string
,
any
>
}
template
:
{
extname
:
string
...
...
packages/uni-mp-vite/src/plugins/manifestJson.ts
浏览文件 @
2326c09e
...
...
@@ -4,52 +4,61 @@ import { Plugin } from 'vite'
import
{
defineUniManifestJsonPlugin
,
getLocaleFiles
,
parseMiniProgramProjectJson
,
}
from
'
@dcloudio/uni-cli-shared
'
import
{
UniMiniProgramPluginOptions
}
from
'
../plugin
'
export
function
uniManifestJsonPlugin
(
options
:
UniMiniProgramPluginOptions
):
Plugin
{
let
projectJson
:
Record
<
string
,
any
>
return
defineUniManifestJsonPlugin
((
opts
)
=>
{
return
{
name
:
'
vite:uni-mp-manifest-json
'
,
enforce
:
'
pre
'
,
transform
(
_
code
,
id
)
{
transform
(
code
,
id
)
{
if
(
!
opts
.
filter
(
id
))
{
return
}
this
.
addWatchFile
(
path
.
resolve
(
process
.
env
.
UNI_INPUT_DIR
,
'
manifest.json
'
)
)
getLocaleFiles
(
path
.
resolve
(
process
.
env
.
UNI_INPUT_DIR
,
'
locale
'
)
).
forEach
((
filepath
)
=>
{
const
inputDir
=
process
.
env
.
UNI_INPUT_DIR
this
.
addWatchFile
(
path
.
resolve
(
inputDir
,
'
manifest.json
'
))
getLocaleFiles
(
path
.
resolve
(
inputDir
,
'
locale
'
)).
forEach
((
filepath
)
=>
{
this
.
addWatchFile
(
filepath
)
})
// manifestJson = normalizeAppManifestJson(
// parseJson(code),
// parsePagesJsonOnce(
// process.env.UNI_INPUT_DIR,
// process.env.UNI_PLATFORM
// )
// )
if
(
options
.
project
)
{
const
template
=
options
.
project
.
source
let
projectname
=
path
.
basename
(
inputDir
)
if
(
projectname
===
'
src
'
)
{
projectname
=
path
.
basename
(
path
.
dirname
(
inputDir
))
}
template
.
projectname
=
projectname
// TODO condition
if
(
process
.
env
.
UNI_AUTOMATOR_WS_ENDPOINT
)
{
if
(
!
template
.
setting
)
{
template
.
setting
=
{}
}
template
.
setting
.
urlCheck
=
false
}
projectJson
=
parseMiniProgramProjectJson
(
code
,
process
.
env
.
UNI_PLATFORM
,
{
template
}
)
}
return
{
code
:
''
,
map
:
this
.
getCombinedSourcemap
(),
}
},
generateBundle
()
{
// 生成一个空的app-config.js,兼容基座已有规范
// this.emitFile({
// fileName: `app-config.js`,
// type: 'asset',
// source: '(function(){})();',
// })
// this.emitFile({
// fileName: `manifest.json`,
// type: 'asset',
// source: JSON.stringify(manifestJson, null, 2),
// })
if
(
projectJson
&&
options
.
project
)
{
this
.
emitFile
({
fileName
:
options
.
project
.
filename
,
type
:
'
asset
'
,
source
:
JSON
.
stringify
(
projectJson
,
null
,
2
),
})
}
},
}
})
...
...
packages/uni-mp-vite/src/plugins/pagesJson.ts
浏览文件 @
2326c09e
import
fs
from
'
fs
'
import
path
from
'
path
'
import
{
Plugin
}
from
'
vite
'
import
{
AppJson
,
defineUniPagesJsonPlugin
,
normalizePagesJson
,
getLocaleFiles
,
normalizePagePath
,
normalizeNodeModules
,
parseManifestJsonOnce
,
parseMiniProgramPagesJson
,
}
from
'
@dcloudio/uni-cli-shared
'
import
{
virtualPagePath
}
from
'
./virtual
'
import
{
UniMiniProgramPluginOptions
}
from
'
../plugin
'
...
...
@@ -13,7 +17,7 @@ import { UniMiniProgramPluginOptions } from '../plugin'
export
function
uniPagesJsonPlugin
(
options
:
UniMiniProgramPluginOptions
):
Plugin
{
let
pagesJson
:
UniApp
.
Pages
Json
let
appJson
:
App
Json
return
defineUniPagesJsonPlugin
((
opts
)
=>
{
return
{
name
:
'
vite:uni-mp-pages-json
'
,
...
...
@@ -22,49 +26,61 @@ export function uniPagesJsonPlugin(
if
(
!
opts
.
filter
(
id
))
{
return
}
this
.
addWatchFile
(
path
.
resolve
(
process
.
env
.
UNI_INPUT_DIR
,
'
pages.json
'
))
getLocaleFiles
(
path
.
resolve
(
process
.
env
.
UNI_INPUT_DIR
,
'
locale
'
)
).
forEach
((
filepath
)
=>
{
const
inputDir
=
process
.
env
.
UNI_INPUT_DIR
this
.
addWatchFile
(
path
.
resolve
(
inputDir
,
'
pages.json
'
))
getLocaleFiles
(
path
.
resolve
(
inputDir
,
'
locale
'
)).
forEach
((
filepath
)
=>
{
this
.
addWatchFile
(
filepath
)
})
pagesJson
=
normalizePagesJson
(
code
,
process
.
env
.
UNI_PLATFORM
)
// TODO subpackages
pagesJson
.
pages
.
forEach
((
page
)
=>
{
this
.
addWatchFile
(
path
.
resolve
(
process
.
env
.
UNI_INPUT_DIR
,
page
.
path
+
'
.vue
'
)
)
const
manifestJson
=
parseManifestJsonOnce
(
inputDir
)
const
res
=
parseMiniProgramPagesJson
(
code
,
process
.
env
.
UNI_PLATFORM
,
{
debug
:
!!
manifestJson
.
debug
,
darkmode
:
options
.
app
.
darkmode
&&
fs
.
existsSync
(
path
.
resolve
(
inputDir
,
'
theme.json
'
)),
networkTimeout
:
manifestJson
.
networkTimeout
,
subpackages
:
options
.
app
.
subpackages
,
})
appJson
=
res
.
appJson
Object
.
keys
(
res
.
pageJsons
).
forEach
((
name
)
=>
{
this
.
emitFile
({
fileName
:
normalizeNodeModules
(
name
)
+
'
.json
'
,
type
:
'
asset
'
,
source
:
JSON
.
stringify
(
res
.
pageJsons
[
name
],
null
,
2
),
})
})
return
{
code
:
`import './manifest.json.js'\n`
+
normalizeMiniProgramPagesJson
(
pagesJson
),
code
:
`import './manifest.json.js'\n`
+
importPagesCode
(
appJson
),
map
:
this
.
getCombinedSourcemap
(),
}
},
generateBundle
()
{
// this.emitFile({
// fileName: `app-config-service.js`,
// type: 'asset',
// source: normalizeAppConfigService(
// pagesJson,
// parseManifestJsonOnce(process.env.UNI_INPUT_DIR)
// ),
// })
if
(
appJson
)
{
this
.
emitFile
({
fileName
:
`app.json`
,
type
:
'
asset
'
,
source
:
JSON
.
stringify
(
appJson
,
null
,
2
),
})
}
},
}
})
}
function
normalizeMiniProgramPagesJson
(
pagesJson
:
Record
<
string
,
any
>
)
{
function
importPagesCode
(
pagesJson
:
AppJson
)
{
const
importPagesCode
:
string
[]
=
[]
pagesJson
.
pages
.
forEach
((
page
:
UniApp
.
PagesJsonPageOptions
)
=>
{
const
pagePath
=
page
.
path
function
importPageCode
(
pagePath
:
string
)
{
const
pagePathWithExtname
=
normalizePagePath
(
pagePath
,
'
app
'
)
if
(
pagePathWithExtname
)
{
importPagesCode
.
push
(
`import('
${
virtualPagePath
(
pagePathWithExtname
)}
')`
)
}
})
}
pagesJson
.
pages
.
forEach
((
pagePath
)
=>
importPageCode
(
pagePath
))
if
(
pagesJson
.
subPackages
)
{
pagesJson
.
subPackages
.
forEach
(({
root
,
pages
})
=>
{
pages
&&
pages
.
forEach
((
pagePath
)
=>
importPageCode
(
path
.
join
(
root
,
pagePath
)))
})
}
return
`if(!Math){
${
importPagesCode
.
join
(
'
\n
'
)}
}`
...
...
packages/uni-mp-vite/src/plugins/virtual.ts
浏览文件 @
2326c09e
...
...
@@ -54,6 +54,7 @@ export function uniVirtualPlugin({
const
filepath
=
normalizePath
(
path
.
resolve
(
inputDir
,
parseVirtualPagePath
(
id
))
)
this
.
addWatchFile
(
filepath
)
return
{
code
:
`import Page from '
${
filepath
}
?mpType=page'
${
global
}
.createPage(Page)`
,
...
...
@@ -62,6 +63,7 @@ ${global}.createPage(Page)`,
const
filepath
=
normalizePath
(
path
.
resolve
(
inputDir
,
parseVirtualComponentPath
(
id
))
)
this
.
addWatchFile
(
filepath
)
return
{
code
:
`import Component from '
${
filepath
}
'
${
global
}
.createComponent(Component)`
,
...
...
packages/uni-stat/dist/uni-stat.cjs.js
浏览文件 @
2326c09e
此差异已折叠。
点击以展开。
packages/uni-stat/dist/uni-stat.es.js
浏览文件 @
2326c09e
此差异已折叠。
点击以展开。
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录