Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
yangkaifeng
uni-app
提交
2972d0c2
U
uni-app
项目概览
yangkaifeng
/
uni-app
与 Fork 源项目一致
Fork自
DCloud / uni-app
通知
3
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
2972d0c2
编写于
4月 28, 2021
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(easycom): support hmr
上级
22bc2dfa
变更
19
隐藏空白更改
内联
并排
Showing
19 changed file
with
201 addition
and
105 deletion
+201
-105
packages/shims-uni-app.d.ts
packages/shims-uni-app.d.ts
+6
-0
packages/uni-cli-shared/src/index.ts
packages/uni-cli-shared/src/index.ts
+1
-1
packages/uni-cli-shared/src/json/index.ts
packages/uni-cli-shared/src/json/index.ts
+3
-0
packages/uni-cli-shared/src/json/json.ts
packages/uni-cli-shared/src/json/json.ts
+1
-1
packages/uni-cli-shared/src/json/manifest.ts
packages/uni-cli-shared/src/json/manifest.ts
+14
-0
packages/uni-cli-shared/src/json/pages.ts
packages/uni-cli-shared/src/json/pages.ts
+18
-2
packages/uni-cli-shared/tsconfig.json
packages/uni-cli-shared/tsconfig.json
+5
-1
packages/uni-shared/dist/uni-shared.cjs.js
packages/uni-shared/dist/uni-shared.cjs.js
+2
-2
packages/uni-shared/dist/uni-shared.d.ts
packages/uni-shared/dist/uni-shared.d.ts
+1
-1
packages/uni-shared/dist/uni-shared.esm.js
packages/uni-shared/dist/uni-shared.esm.js
+2
-2
packages/uni-shared/src/utils.ts
packages/uni-shared/src/utils.ts
+6
-3
packages/vite-plugin-uni/src/config/build.ts
packages/vite-plugin-uni/src/config/build.ts
+2
-2
packages/vite-plugin-uni/src/config/define.ts
packages/vite-plugin-uni/src/config/define.ts
+14
-4
packages/vite-plugin-uni/src/configResolved/plugins/pagesJson.ts
...s/vite-plugin-uni/src/configResolved/plugins/pagesJson.ts
+3
-3
packages/vite-plugin-uni/src/configureServer/easycom.ts
packages/vite-plugin-uni/src/configureServer/easycom.ts
+5
-2
packages/vite-plugin-uni/src/handleHotUpdate/index.ts
packages/vite-plugin-uni/src/handleHotUpdate/index.ts
+45
-19
packages/vite-plugin-uni/src/utils/easycom.ts
packages/vite-plugin-uni/src/utils/easycom.ts
+40
-25
packages/vite-plugin-uni/src/utils/features.ts
packages/vite-plugin-uni/src/utils/features.ts
+32
-35
packages/vite-plugin-uni/src/utils/index.ts
packages/vite-plugin-uni/src/utils/index.ts
+1
-2
未找到文件。
packages/shims-uni-app.d.ts
浏览文件 @
2972d0c2
...
...
@@ -173,6 +173,12 @@ declare namespace UniApp {
topWindow
?:
PagesJsonWindowOptions
leftWindow
?:
PagesJsonWindowOptions
rightWindow
?:
PagesJsonWindowOptions
easycom
?:
{
autoscan
?:
boolean
custom
?:
{
[
name
:
string
]:
string
}
}
}
interface
TabBarItemBaseOptions
{
...
...
packages/uni-cli-shared/src/index.ts
浏览文件 @
2972d0c2
...
...
@@ -3,4 +3,4 @@ export * from './url'
export
*
from
'
./json
'
export
*
from
'
./utils
'
export
*
from
'
./constants
'
export
*
from
'
./preprocess
/index
'
export
*
from
'
./preprocess
'
packages/uni-cli-shared/src/json/index.ts
0 → 100644
浏览文件 @
2972d0c2
export
*
from
'
./json
'
export
*
from
'
./pages
'
export
*
from
'
./manifest
'
packages/uni-cli-shared/src/json.ts
→
packages/uni-cli-shared/src/json
/json
.ts
浏览文件 @
2972d0c2
import
{
parse
}
from
'
jsonc-parser
'
import
{
preJson
}
from
'
./preprocess
'
import
{
preJson
}
from
'
.
.
/preprocess
'
export
function
parseJson
(
jsonStr
:
string
,
shouldPre
:
boolean
=
false
)
{
return
parse
(
shouldPre
?
preJson
(
jsonStr
)
:
jsonStr
)
...
...
packages/uni-cli-shared/src/json/manifest.ts
0 → 100644
浏览文件 @
2972d0c2
import
fs
from
'
fs
'
import
path
from
'
path
'
import
{
once
}
from
'
@dcloudio/uni-shared
'
import
{
parseJson
}
from
'
./json
'
export
const
parseManifestJson
=
(
inputDir
:
string
)
=>
{
return
parseJson
(
fs
.
readFileSync
(
path
.
join
(
inputDir
,
'
manifest.json
'
),
'
utf8
'
)
)
}
export
const
parseManifestJsonOnce
=
once
(
parseManifestJson
)
packages/
vite-plugin-uni/src/utils/pagesJson
.ts
→
packages/
uni-cli-shared/src/json/pages
.ts
浏览文件 @
2972d0c2
import
fs
from
'
fs
'
import
path
from
'
path
'
import
slash
from
'
slash
'
import
{
extend
,
hasOwn
,
isArray
,
isPlainObject
}
from
'
@vue/shared
'
import
{
parseJson
}
from
'
@dcloudio/uni-cli-shared
'
import
{
TABBAR_HEIGHT
}
from
'
@dcloudio/uni-shared
'
import
{
once
,
TABBAR_HEIGHT
}
from
'
@dcloudio/uni-shared
'
import
{
parseJson
}
from
'
./json
'
export
const
parsePagesJson
=
(
inputDir
:
string
,
platform
:
UniApp
.
PLATFORM
,
normalize
:
boolean
=
true
)
=>
{
const
jsonStr
=
fs
.
readFileSync
(
path
.
join
(
inputDir
,
'
pages.json
'
),
'
utf8
'
)
if
(
normalize
)
{
return
normalizePagesJson
(
jsonStr
,
platform
)
}
return
parseJson
(
jsonStr
,
true
)
as
UniApp
.
PagesJson
}
export
const
parsePagesJsonOnce
=
once
(
parsePagesJson
)
export
function
normalizePagesJson
(
jsonStr
:
string
,
platform
:
UniApp
.
PLATFORM
)
{
let
pagesJson
:
UniApp
.
PagesJson
=
{
...
...
packages/uni-cli-shared/tsconfig.json
浏览文件 @
2972d0c2
...
...
@@ -3,5 +3,9 @@
"compilerOptions"
:
{
"outDir"
:
"dist"
},
"include"
:
[
"src"
]
"include"
:
[
"src"
,
"../shims-node.d.ts"
,
"../shims-uni-app.d.ts"
]
}
packages/uni-shared/dist/uni-shared.cjs.js
浏览文件 @
2972d0c2
...
...
@@ -185,13 +185,13 @@ function updateElementStyle(element, styles) {
}
function
once
(
fn
,
ctx
=
null
)
{
let
res
;
return
(...
args
)
=>
{
return
(
(
...
args
)
=>
{
if
(
fn
)
{
res
=
fn
.
apply
(
ctx
,
args
);
fn
=
null
;
}
return
res
;
};
}
)
;
}
const
encode
=
encodeURIComponent
;
...
...
packages/uni-shared/dist/uni-shared.d.ts
浏览文件 @
2972d0c2
...
...
@@ -49,7 +49,7 @@ export declare function normalizeTarget(el: HTMLElement): {
export
declare
const
ON_REACH_BOTTOM_DISTANCE
=
50
;
export
declare
function
once
(
fn
:
(...
args
:
any
[])
=>
any
,
ctx
?:
unknown
):
(...
args
:
any
[])
=>
any
;
export
declare
function
once
<
T
extends
(...
args
:
any
[])
=>
any
>
(
fn
:
T
,
ctx
?:
unknown
):
T
;
/**
* https://github.com/vuejs/vue-router-next/blob/master/src/query.ts
...
...
packages/uni-shared/dist/uni-shared.esm.js
浏览文件 @
2972d0c2
...
...
@@ -181,13 +181,13 @@ function updateElementStyle(element, styles) {
}
function
once
(
fn
,
ctx
=
null
)
{
let
res
;
return
(...
args
)
=>
{
return
(
(
...
args
)
=>
{
if
(
fn
)
{
res
=
fn
.
apply
(
ctx
,
args
);
fn
=
null
;
}
return
res
;
};
}
)
;
}
const
encode
=
encodeURIComponent
;
...
...
packages/uni-shared/src/utils.ts
浏览文件 @
2972d0c2
...
...
@@ -23,13 +23,16 @@ export function updateElementStyle(
}
}
export
function
once
(
fn
:
(...
args
:
any
[])
=>
any
,
ctx
:
unknown
=
null
)
{
export
function
once
<
T
extends
(...
args
:
any
[])
=>
any
>
(
fn
:
T
,
ctx
:
unknown
=
null
):
T
{
let
res
:
any
return
(...
args
:
any
[])
=>
{
return
(
(
...
args
:
any
[])
=>
{
if
(
fn
)
{
res
=
fn
.
apply
(
ctx
,
args
)
fn
=
null
as
any
}
return
res
}
}
)
as
T
}
packages/vite-plugin-uni/src/config/build.ts
浏览文件 @
2972d0c2
...
...
@@ -2,13 +2,13 @@ import path from 'path'
import
slash
from
'
slash
'
import
{
UserConfig
}
from
'
vite
'
import
{
VitePluginUniResolvedOptions
}
from
'
..
'
import
{
FEATURE_DEFINES
,
initEasycoms
}
from
'
../utils
'
import
{
FEATURE_DEFINES
,
initEasycoms
Once
}
from
'
../utils
'
export
function
createBuild
(
options
:
VitePluginUniResolvedOptions
,
features
:
FEATURE_DEFINES
):
UserConfig
[
'
build
'
]
{
initEasycoms
(
options
.
inputDir
)
initEasycoms
Once
(
options
.
inputDir
,
options
.
platform
)
return
{
polyfillDynamicImport
:
features
.
__UNI_FEATURE_PAGES__
,
rollupOptions
:
{
...
...
packages/vite-plugin-uni/src/config/define.ts
浏览文件 @
2972d0c2
import
{
ConfigEnv
,
UserConfig
}
from
'
vite
'
import
{
VitePluginUniResolvedOptions
}
from
'
..
'
import
{
getFeatures
}
from
'
../utils
'
import
{
parsePagesJsonOnce
,
parseManifestJsonOnce
,
}
from
'
@dcloudio/uni-cli-shared
'
import
{
initFeatures
}
from
'
../utils
'
export
function
createDefine
(
options
:
VitePluginUniResolvedOptions
,
env
:
ConfigEnv
{
inputDir
,
platform
}
:
VitePluginUniResolvedOptions
,
{
command
}
:
ConfigEnv
):
UserConfig
[
'
define
'
]
{
return
getFeatures
(
options
,
env
.
command
)
return
initFeatures
({
inputDir
,
command
,
platform
,
pagesJson
:
parsePagesJsonOnce
(
inputDir
,
platform
),
manifestJson
:
parseManifestJsonOnce
(
inputDir
),
})
}
packages/vite-plugin-uni/src/configResolved/plugins/pagesJson.ts
浏览文件 @
2972d0c2
...
...
@@ -4,13 +4,13 @@ import slash from 'slash'
import
{
Plugin
,
ResolvedConfig
}
from
'
vite
'
import
{
parse
}
from
'
jsonc-parser
'
import
{
camelize
,
capitalize
}
from
'
@vue/shared
'
import
{
normalizePagesJson
}
from
'
@dcloudio/uni-cli-shared
'
import
{
VitePluginUniResolvedOptions
}
from
'
../..
'
import
{
BASE_COMPONENTS_STYLE_PATH
,
FEATURE_DEFINES
,
H5_API_STYLE_PATH
,
H5_FRAMEWORK_STYLE_PATH
,
normalizePagesJson
,
}
from
'
../../utils
'
const
pkg
=
require
(
'
@dcloudio/vite-plugin-uni/package.json
'
)
...
...
@@ -35,7 +35,7 @@ export function uniPagesJsonPlugin(
code
:
(
config
.
define
!
.
__UNI_FEATURE_RPX__
?
registerGlobalCode
:
''
)
+
(
options
.
command
===
'
serve
'
?
registerDevServerGlobalCode
:
''
)
+
parsePagesJson
(
code
,
config
,
options
),
generatePagesJsonCode
(
code
,
config
,
options
),
map
:
{
mappings
:
''
},
}
}
...
...
@@ -54,7 +54,7 @@ interface PageRouteOptions {
meta
:
Partial
<
UniApp
.
PageRouteMeta
>
}
function
parsePagesJson
(
function
generatePagesJsonCode
(
jsonStr
:
string
,
config
:
ResolvedConfig
,
options
:
VitePluginUniResolvedOptions
...
...
packages/vite-plugin-uni/src/configureServer/easycom.ts
浏览文件 @
2972d0c2
import
{
ViteDevServer
}
from
'
vite
'
import
{
debounce
}
from
'
@dcloudio/uni-shared
'
import
{
VitePluginUniResolvedOptions
}
from
'
..
'
import
{
debugEasycom
,
initEasycoms
}
from
'
../utils
'
import
{
debugEasycom
,
initEasycoms
Once
}
from
'
../utils
'
export
const
serveEasycom
=
(
server
:
ViteDevServer
,
options
:
VitePluginUniResolvedOptions
)
=>
{
const
{
filter
,
refresh
}
=
initEasycoms
(
options
.
inputDir
)
const
{
filter
,
refresh
}
=
initEasycomsOnce
(
options
.
inputDir
,
options
.
platform
)
const
refreshEasycom
=
debounce
(
refresh
,
100
)
server
.
watcher
.
on
(
'
all
'
,
(
eventName
,
path
)
=>
{
if
(
!
[
'
add
'
,
'
unlink
'
].
includes
(
eventName
))
{
...
...
packages/vite-plugin-uni/src/handleHotUpdate/index.ts
浏览文件 @
2972d0c2
...
...
@@ -2,8 +2,11 @@ import path from 'path'
import
debug
from
'
debug
'
import
slash
from
'
slash
'
import
{
ModuleGraph
,
Plugin
}
from
'
vite
'
import
{
parseManifestJson
,
parsePagesJson
}
from
'
@dcloudio/uni-cli-shared
'
import
{
VitePluginUniResolvedOptions
}
from
'
..
'
import
{
ge
tFeatures
}
from
'
../utils
'
import
{
initEasycomsOnce
,
ini
tFeatures
}
from
'
../utils
'
const
debugHmr
=
debug
(
'
uni:hmr
'
)
...
...
@@ -16,14 +19,12 @@ async function invalidate(file: string, moduleGraph: ModuleGraph) {
})
}
}
let
invalidateFiles
:
string
[]
export
function
createHandleHotUpdate
(
options
:
VitePluginUniResolvedOptions
):
Plugin
[
'
handleHotUpdate
'
]
{
return
async
function
({
file
,
server
})
{
if
(
!
invalidateFiles
)
{
// options.inputDir 的赋值时机是在config中,不能直接使用在上边声明使用
invalidateFiles
=
[
path
.
resolve
(
options
.
inputDir
,
'
pages.json.js
'
),
path
.
resolve
(
options
.
inputDir
,
'
manifest.json.js
'
),
...
...
@@ -34,24 +35,49 @@ export function createHandleHotUpdate(
// TODO 目前简单处理,当pages.json,manifest.json发生变化,就直接刷新,理想情况下,应该区分变化的内容,仅必要时做整页面刷新
const
isPagesJson
=
file
.
endsWith
(
'
pages.json
'
)
const
isManifestJson
=
file
.
endsWith
(
'
manifest.json
'
)
if
(
isPagesJson
||
isManifestJson
)
{
debugHmr
(
file
)
server
.
ws
.
send
({
type
:
'
custom
'
,
event
:
'
invalidate
'
,
data
:
{},
if
(
!
isPagesJson
&&
!
isManifestJson
)
{
return
}
debugHmr
(
file
)
server
.
ws
.
send
({
type
:
'
custom
'
,
event
:
'
invalidate
'
,
data
:
{},
})
const
{
inputDir
,
command
,
platform
}
=
options
const
pagesJson
=
parsePagesJson
(
inputDir
,
platform
)
// 更新define
Object
.
assign
(
server
.
config
.
define
!
,
initFeatures
({
inputDir
,
command
,
platform
,
pagesJson
,
manifestJson
:
parseManifestJson
(
inputDir
),
})
// 更新define
Object
.
assign
(
server
.
config
.
define
!
,
getFeatures
(
options
,
server
.
config
.
command
)
)
debugHmr
(
'
define
'
,
server
.
config
.
define
)
// 当pages.json,manifest.json发生变化时,作废pages.json.js缓存
for
(
const
file
of
invalidateFiles
)
{
await
invalidate
(
file
,
server
.
moduleGraph
)
)
debugHmr
(
'
define
'
,
server
.
config
.
define
)
if
(
isPagesJson
)
{
const
easycom
=
pagesJson
.
easycom
||
{}
const
{
options
,
refresh
}
=
initEasycomsOnce
(
inputDir
,
platform
)
if
(
!
equal
(
{
autoscan
:
easycom
.
autoscan
,
custom
:
easycom
.
custom
},
{
autoscan
:
options
.
autoscan
,
custom
:
options
.
custom
}
)
)
{
refresh
()
}
return
[]
}
// 当pages.json,manifest.json发生变化时,作废pages.json.js缓存
for
(
const
file
of
invalidateFiles
)
{
await
invalidate
(
file
,
server
.
moduleGraph
)
}
return
[]
}
}
function
equal
(
obj1
:
Record
<
string
,
any
>
,
obj2
:
Record
<
string
,
any
>
)
{
return
JSON
.
stringify
(
obj1
)
===
JSON
.
stringify
(
obj2
)
}
packages/vite-plugin-uni/src/utils/easycom.ts
浏览文件 @
2972d0c2
...
...
@@ -5,12 +5,14 @@ import debug from 'debug'
import
{
createFilter
}
from
'
@rollup/pluginutils
'
import
{
once
}
from
'
@dcloudio/uni-shared
'
import
{
parsePagesJson
,
parsePagesJsonOnce
}
from
'
@dcloudio/uni-cli-shared
'
interface
EasycomOption
{
dirs
?:
string
[]
rootDir
?:
string
custom
?:
EasycomCustom
extensions
?:
string
[]
autoscan
?:
boolean
custom
?:
EasycomCustom
}
interface
EasycomMatcher
{
pattern
:
RegExp
...
...
@@ -36,31 +38,44 @@ function clearEasycom() {
easycomsInvalidCache
.
clear
()
}
export
const
initEasycoms
=
once
((
inputDir
:
string
)
=>
{
const
componentsDir
=
path
.
resolve
(
inputDir
,
'
components
'
)
const
uniModulesDir
=
path
.
resolve
(
inputDir
,
'
uni_modules
'
)
const
initEasycomOptions
=
()
=>
{
const
easycomOptions
=
{
dirs
:
[
componentsDir
,
...
initUniModulesEasycomDirs
(
uniModulesDir
)],
rootDir
:
inputDir
,
}
debugEasycom
(
easycomOptions
)
return
easycomOptions
}
initEasycom
(
initEasycomOptions
())
return
{
filter
:
createFilter
(
[
'
components/*/*.vue
'
,
'
uni_modules/*/components/*/*.vue
'
],
[],
{
resolve
:
inputDir
,
export
const
initEasycomsOnce
=
once
(
(
inputDir
:
string
,
platform
:
UniApp
.
PLATFORM
)
=>
{
const
componentsDir
=
path
.
resolve
(
inputDir
,
'
components
'
)
const
uniModulesDir
=
path
.
resolve
(
inputDir
,
'
uni_modules
'
)
const
initEasycomOptions
=
(
pagesJson
?:
UniApp
.
PagesJson
)
=>
{
// 初始化时,从once中读取缓存,refresh时,实时读取
const
{
easycom
}
=
pagesJson
||
parsePagesJson
(
inputDir
,
platform
,
false
)
const
easycomOptions
:
EasycomOption
=
{
dirs
:
easycom
&&
easycom
.
autoscan
===
false
?
[]
// 禁止自动扫描
:
[
componentsDir
,
...
initUniModulesEasycomDirs
(
uniModulesDir
)],
rootDir
:
inputDir
,
autoscan
:
!!
(
easycom
&&
easycom
.
autoscan
),
custom
:
(
easycom
&&
easycom
.
custom
)
||
{},
}
),
refresh
()
{
initEasycom
(
initEasycomOptions
())
},
debugEasycom
(
easycomOptions
)
return
easycomOptions
}
const
options
=
initEasycomOptions
(
parsePagesJsonOnce
(
inputDir
,
platform
))
initEasycom
(
options
)
const
res
=
{
options
,
filter
:
createFilter
(
[
'
components/*/*.vue
'
,
'
uni_modules/*/components/*/*.vue
'
],
[],
{
resolve
:
inputDir
,
}
),
refresh
()
{
res
.
options
=
initEasycomOptions
()
initEasycom
(
res
.
options
)
},
}
return
res
}
}
)
)
function
initUniModulesEasycomDirs
(
uniModulesDir
:
string
)
{
if
(
!
fs
.
existsSync
(
uniModulesDir
))
{
...
...
@@ -89,7 +104,7 @@ function initEasycom({
}:
EasycomOption
)
{
clearEasycom
()
const
easycomsObj
=
Object
.
create
(
null
)
if
(
dirs
&&
rootDir
)
{
if
(
dirs
&&
dirs
.
length
&&
rootDir
)
{
Object
.
assign
(
easycomsObj
,
initAutoScanEasycoms
(
dirs
,
rootDir
,
extensions
))
}
if
(
custom
)
{
...
...
packages/vite-plugin-uni/src/utils/
define
.ts
→
packages/vite-plugin-uni/src/utils/
features
.ts
浏览文件 @
2972d0c2
import
fs
from
'
fs
'
import
path
from
'
path
'
import
{
ConfigEnv
}
from
'
vite
'
import
{
parse
}
from
'
jsonc-parser
'
import
{
isArray
}
from
'
@vue/shared
'
import
{
VitePluginUniResolvedOptions
}
from
'
..
'
import
{
normalizePagesJson
}
from
'
./pagesJson
'
interface
ProjectFeatures
{}
interface
PagesFeatures
{
...
...
@@ -35,20 +32,18 @@ interface ManifestFeatures {
i18nZhHant
:
boolean
}
function
resolveProjectFeature
(
options
:
VitePluginUniResolvedOptions
,
command
:
ConfigEnv
[
'
command
'
]
)
{
function
initProjectFeature
({
command
}:
InitFeaturesOptions
)
{
const
features
:
ProjectFeatures
=
{}
if
(
command
===
'
build
'
)
{
}
return
features
}
function
resolvePagesFeature
(
options
:
VitePluginUniResolvedOptions
,
command
:
ConfigEnv
[
'
command
'
]
):
PagesFeatures
{
function
initPagesFeature
({
pagesJson
,
command
,
inputDir
,
}:
InitFeaturesOptions
):
PagesFeatures
{
const
features
:
PagesFeatures
=
{
nvue
:
true
,
pages
:
true
,
...
...
@@ -71,10 +66,7 @@ function resolvePagesFeature(
leftWindow
,
rightWindow
,
globalStyle
,
}
=
normalizePagesJson
(
fs
.
readFileSync
(
path
.
join
(
options
.
inputDir
,
'
pages.json
'
),
'
utf8
'
),
options
.
platform
)
}
=
pagesJson
if
(
pages
&&
pages
.
length
===
1
)
{
features
.
pages
=
false
}
...
...
@@ -104,7 +96,7 @@ function resolvePagesFeature(
if
(
command
===
'
build
'
)
{
if
(
!
pages
.
find
((
page
)
=>
fs
.
existsSync
(
path
.
resolve
(
options
.
inputDir
,
page
.
path
,
'
.nvue
'
))
fs
.
existsSync
(
path
.
resolve
(
inputDir
,
page
.
path
,
'
.nvue
'
))
)
)
{
features
.
nvue
=
false
...
...
@@ -153,9 +145,11 @@ function resolvePagesFeature(
return
features
}
function
resolveManifestFeature
(
options
:
VitePluginUniResolvedOptions
):
ManifestFeatures
{
function
initManifestFeature
({
manifestJson
,
command
,
platform
,
}:
InitFeaturesOptions
):
ManifestFeatures
{
const
features
:
ManifestFeatures
=
{
wx
:
false
,
wxs
:
true
,
...
...
@@ -169,23 +163,21 @@ function resolveManifestFeature(
i18nZhHans
:
true
,
i18nZhHant
:
true
,
}
const
manifest
=
parse
(
fs
.
readFileSync
(
path
.
join
(
options
.
inputDir
,
'
manifest.json
'
),
'
utf8
'
)
)
if
(
options
.
command
===
'
build
'
)
{
if
(
command
===
'
build
'
)
{
// TODO 需要预编译一遍?
features
.
wxs
=
false
features
.
longpress
=
false
}
if
(
manifest
.
h5
&&
manifest
.
h5
.
router
&&
manifest
.
h5
.
router
.
mode
===
'
history
'
manifest
Json
.
h5
&&
manifest
Json
.
h5
.
router
&&
manifest
Json
.
h5
.
router
.
mode
===
'
history
'
)
{
features
.
routerMode
=
'
"history"
'
}
const
platform
=
manifest
[
options
.
platform
]
||
{}
const
manifestFeatures
=
platform
.
features
const
platform
Json
=
manifestJson
[
platform
]
||
{}
const
manifestFeatures
=
platform
Json
.
features
if
(
manifestFeatures
)
{
const
{
i18n
}
=
manifestFeatures
if
(
isArray
(
i18n
))
{
...
...
@@ -210,12 +202,17 @@ function resolveManifestFeature(
return
features
}
export
type
FEATURE_DEFINES
=
ReturnType
<
typeof
ge
tFeatures
>
export
type
FEATURE_DEFINES
=
ReturnType
<
typeof
ini
tFeatures
>
export
function
getFeatures
(
options
:
VitePluginUniResolvedOptions
,
interface
InitFeaturesOptions
{
pagesJson
:
UniApp
.
PagesJson
manifestJson
:
any
inputDir
:
string
platform
:
UniApp
.
PLATFORM
command
:
ConfigEnv
[
'
command
'
]
)
{
}
export
function
initFeatures
(
options
:
InitFeaturesOptions
)
{
const
{
wx
,
wxs
,
...
...
@@ -241,9 +238,9 @@ export function getFeatures(
navigationBarSearchInput
,
navigationBarTransparent
,
}
=
Object
.
assign
(
resolve
ManifestFeature
(
options
),
resolvePagesFeature
(
options
,
command
),
resolveProjectFeature
(
options
,
command
)
init
ManifestFeature
(
options
),
initPagesFeature
(
options
),
initProjectFeature
(
options
)
)
return
{
__UNI_FEATURE_WX__
:
wx
,
// 是否启用小程序的组件实例 API,如:selectComponent 等(uni-core/src/service/plugin/appConfig)
...
...
packages/vite-plugin-uni/src/utils/index.ts
浏览文件 @
2972d0c2
export
*
from
'
./filter
'
export
*
from
'
./
define
'
export
*
from
'
./
features
'
export
*
from
'
./easycom
'
export
*
from
'
./postcss
'
export
*
from
'
./pagesJson
'
export
*
from
'
./constants
'
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录