Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
qianlong66
uni-app
提交
3f7548b8
U
uni-app
项目概览
qianlong66
/
uni-app
与 Fork 源项目一致
Fork自
DCloud / uni-app
通知
1
Star
1
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,发现更多精彩内容 >>
提交
3f7548b8
编写于
6月 22, 2021
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
wip(app): uni-app-vite
上级
d9cedce2
变更
64
隐藏空白更改
内联
并排
Showing
64 changed file
with
967 addition
and
1041 deletion
+967
-1041
package.json
package.json
+1
-0
packages/playground/ssr/yarn.lock
packages/playground/ssr/yarn.lock
+6
-0
packages/size-check/vite.config.ts
packages/size-check/vite.config.ts
+1
-0
packages/uni-api/src/helpers/api/index.ts
packages/uni-api/src/helpers/api/index.ts
+1
-4
packages/uni-app-plus/dist/uni-app-view.umd.js
packages/uni-app-plus/dist/uni-app-view.umd.js
+64
-1
packages/uni-app-plus/package.json
packages/uni-app-plus/package.json
+0
-4
packages/uni-app-vite/dist/index.js
packages/uni-app-vite/dist/index.js
+26
-2
packages/uni-app-vite/dist/plugins/mainJs.js
packages/uni-app-vite/dist/plugins/mainJs.js
+1
-1
packages/uni-app-vite/dist/plugins/manifestJson.js
packages/uni-app-vite/dist/plugins/manifestJson.js
+10
-51
packages/uni-app-vite/dist/plugins/pagesJson.js
packages/uni-app-vite/dist/plugins/pagesJson.js
+5
-212
packages/uni-app-vite/dist/plugins/resolveId.js
packages/uni-app-vite/dist/plugins/resolveId.js
+0
-37
packages/uni-app-vite/src/index.ts
packages/uni-app-vite/src/index.ts
+29
-3
packages/uni-app-vite/src/plugins/mainJs.ts
packages/uni-app-vite/src/plugins/mainJs.ts
+1
-1
packages/uni-app-vite/src/plugins/manifestJson.ts
packages/uni-app-vite/src/plugins/manifestJson.ts
+14
-66
packages/uni-app-vite/src/plugins/pagesJson.ts
packages/uni-app-vite/src/plugins/pagesJson.ts
+10
-284
packages/uni-app-vite/src/plugins/resolveId.ts
packages/uni-app-vite/src/plugins/resolveId.ts
+0
-43
packages/uni-cli-shared/package.json
packages/uni-cli-shared/package.json
+1
-0
packages/uni-cli-shared/src/easycom.ts
packages/uni-cli-shared/src/easycom.ts
+2
-2
packages/uni-cli-shared/src/index.ts
packages/uni-cli-shared/src/index.ts
+1
-0
packages/uni-cli-shared/src/json/app.ts
packages/uni-cli-shared/src/json/app.ts
+99
-0
packages/uni-cli-shared/src/json/index.ts
packages/uni-cli-shared/src/json/index.ts
+1
-0
packages/uni-cli-shared/src/json/manifest.ts
packages/uni-cli-shared/src/json/manifest.ts
+0
-1
packages/uni-cli-shared/src/utils.ts
packages/uni-cli-shared/src/utils.ts
+5
-0
packages/uni-cli-shared/src/vite/index.ts
packages/uni-cli-shared/src/vite/index.ts
+5
-0
packages/uni-h5-vite/dist/handleHotUpdate/index.js
packages/uni-h5-vite/dist/handleHotUpdate/index.js
+91
-0
packages/uni-h5-vite/dist/index.js
packages/uni-h5-vite/dist/index.js
+15
-0
packages/uni-h5-vite/dist/plugins/pagesJson.js
packages/uni-h5-vite/dist/plugins/pagesJson.js
+3
-6
packages/uni-h5-vite/dist/plugins/setup.js
packages/uni-h5-vite/dist/plugins/setup.js
+34
-0
packages/uni-h5-vite/dist/plugins/ssr.js
packages/uni-h5-vite/dist/plugins/ssr.js
+50
-0
packages/uni-h5-vite/dist/utils/features.js
packages/uni-h5-vite/dist/utils/features.js
+210
-0
packages/uni-h5-vite/dist/utils/index.js
packages/uni-h5-vite/dist/utils/index.js
+1
-0
packages/uni-h5-vite/lib/ssr/define.js
packages/uni-h5-vite/lib/ssr/define.js
+0
-0
packages/uni-h5-vite/lib/ssr/entry-server.js
packages/uni-h5-vite/lib/ssr/entry-server.js
+0
-0
packages/uni-h5-vite/package.json
packages/uni-h5-vite/package.json
+2
-1
packages/uni-h5-vite/src/handleHotUpdate/index.ts
packages/uni-h5-vite/src/handleHotUpdate/index.ts
+12
-10
packages/uni-h5-vite/src/index.ts
packages/uni-h5-vite/src/index.ts
+16
-0
packages/uni-h5-vite/src/plugins/pagesJson.ts
packages/uni-h5-vite/src/plugins/pagesJson.ts
+5
-8
packages/uni-h5-vite/src/plugins/setup.ts
packages/uni-h5-vite/src/plugins/setup.ts
+34
-0
packages/uni-h5-vite/src/plugins/ssr.ts
packages/uni-h5-vite/src/plugins/ssr.ts
+65
-0
packages/uni-h5-vite/src/utils/features.ts
packages/uni-h5-vite/src/utils/features.ts
+22
-1
packages/uni-h5-vite/src/utils/index.ts
packages/uni-h5-vite/src/utils/index.ts
+1
-0
packages/uni-h5/dist/uni-h5.cjs.js
packages/uni-h5/dist/uni-h5.cjs.js
+1
-1
packages/uni-h5/dist/uni-h5.es.js
packages/uni-h5/dist/uni-h5.es.js
+38
-24
packages/uni-shared/dist/uni-shared.cjs.js
packages/uni-shared/dist/uni-shared.cjs.js
+8
-0
packages/uni-shared/dist/uni-shared.d.ts
packages/uni-shared/dist/uni-shared.d.ts
+4
-0
packages/uni-shared/dist/uni-shared.es.js
packages/uni-shared/dist/uni-shared.es.js
+7
-1
packages/uni-shared/src/tags.ts
packages/uni-shared/src/tags.ts
+8
-0
packages/vite-plugin-uni/package.json
packages/vite-plugin-uni/package.json
+1
-2
packages/vite-plugin-uni/src/config/build.ts
packages/vite-plugin-uni/src/config/build.ts
+1
-1
packages/vite-plugin-uni/src/config/define.ts
packages/vite-plugin-uni/src/config/define.ts
+7
-23
packages/vite-plugin-uni/src/config/index.ts
packages/vite-plugin-uni/src/config/index.ts
+1
-3
packages/vite-plugin-uni/src/config/optimizeDeps.ts
packages/vite-plugin-uni/src/config/optimizeDeps.ts
+0
-2
packages/vite-plugin-uni/src/configResolved/config.ts
packages/vite-plugin-uni/src/configResolved/config.ts
+0
-37
packages/vite-plugin-uni/src/configResolved/index.ts
packages/vite-plugin-uni/src/configResolved/index.ts
+0
-2
packages/vite-plugin-uni/src/configResolved/plugins/easycom.ts
...ges/vite-plugin-uni/src/configResolved/plugins/easycom.ts
+1
-2
packages/vite-plugin-uni/src/configResolved/plugins/index.ts
packages/vite-plugin-uni/src/configResolved/plugins/index.ts
+0
-2
packages/vite-plugin-uni/src/configResolved/plugins/resolveId.ts
...s/vite-plugin-uni/src/configResolved/plugins/resolveId.ts
+11
-2
packages/vite-plugin-uni/src/configResolved/plugins/ssr.ts
packages/vite-plugin-uni/src/configResolved/plugins/ssr.ts
+3
-35
packages/vite-plugin-uni/src/configureServer/easycom.ts
packages/vite-plugin-uni/src/configureServer/easycom.ts
+3
-1
packages/vite-plugin-uni/src/index.ts
packages/vite-plugin-uni/src/index.ts
+0
-2
packages/vite-plugin-uni/src/utils/index.ts
packages/vite-plugin-uni/src/utils/index.ts
+0
-3
packages/vite-plugin-uni/src/utils/ssr.ts
packages/vite-plugin-uni/src/utils/ssr.ts
+0
-146
packages/vite-plugin-uni/src/vue/options.ts
packages/vite-plugin-uni/src/vue/options.ts
+24
-14
yarn.lock
yarn.lock
+5
-0
未找到文件。
package.json
浏览文件 @
3f7548b8
...
...
@@ -7,6 +7,7 @@
"scripts"
:
{
"build"
:
"node scripts/build.js"
,
"build:h5"
:
"node scripts/build.js uni-app uni-cli-shared uni-h5 uni-i18n uni-shared uni-h5-vite vite-plugin-uni"
,
"build:app"
:
"node scripts/build.js uni-app-plus uni-app-vite uni-app-vue"
,
"size"
:
"npm run build size-check"
,
"lint"
:
"eslint packages/*/src/**/*.ts"
,
"format"
:
"prettier --write --parser typescript
\"
packages/**/*.ts?(x)
\"
"
,
...
...
packages/playground/ssr/yarn.lock
浏览文件 @
3f7548b8
...
...
@@ -74,6 +74,7 @@
debug "^4.3.1"
estree-walker "^2.0.2"
jsonc-parser "^3.0.0"
merge "^2.1.1"
slash "^3.0.0"
tapable "^2.2.0"
xregexp "3.1.0"
...
...
@@ -1551,6 +1552,11 @@ merge2@^1.2.3, merge2@^1.3.0:
resolved "https://registry.yarnpkg.com/merge2/-/merge2-1.4.1.tgz#4368892f885e907455a6fd7dc55c0c9d404990ae"
integrity sha512-8q7VEgMJW4J8tcfVPy8g09NcQwZdbwFEqhe/WZkoIzjn/3TGDwtOCYtXGxA3O8tPzpczCCDgv+P2P5y00ZJOOg==
merge@^2.1.1:
version "2.1.1"
resolved "https://registry.yarnpkg.com/merge/-/merge-2.1.1.tgz#59ef4bf7e0b3e879186436e8481c06a6c162ca98"
integrity sha512-jz+Cfrg9GWOZbQAnDQ4hlVnQky+341Yk5ru8bZSe6sIDTCIg8n9i/u7hSQGSVOF3C7lH6mGtqjkiT9G4wFLL0w==
methods@~1.1.2:
version "1.1.2"
resolved "https://registry.yarnpkg.com/methods/-/methods-1.1.2.tgz#5529a4d67654134edcc5266656835b0f851afcee"
...
...
packages/size-check/vite.config.ts
浏览文件 @
3f7548b8
...
...
@@ -4,6 +4,7 @@ import uni from '@dcloudio/vite-plugin-uni'
process
.
env
.
UNI_CLI_CONTEXT
=
__dirname
process
.
env
.
UNI_INPUT_DIR
=
path
.
resolve
(
__dirname
,
'
src
'
)
process
.
env
.
UNI_PLATFORM
=
'
h5
'
/**
* @type {import('vite').UserConfig}
*/
...
...
packages/uni-api/src/helpers/api/index.ts
浏览文件 @
3f7548b8
...
...
@@ -55,10 +55,7 @@ function invokeSuccess(id: number, name: string, res: unknown) {
function
invokeFail
(
id
:
number
,
name
:
string
,
errMsg
?:
string
,
errRes
?:
any
)
{
return
invokeCallback
(
id
,
Object
.
assign
(
{
errMsg
:
name
+
'
:fail
'
+
(
errMsg
?
'
'
+
errMsg
:
''
)
},
errRes
)
extend
({
errMsg
:
name
+
'
:fail
'
+
(
errMsg
?
'
'
+
errMsg
:
''
)
},
errRes
)
)
}
...
...
packages/uni-app-plus/dist/uni-app-view.umd.js
浏览文件 @
3f7548b8
...
...
@@ -300,7 +300,16 @@
offsetLeft
};
}
const
cacheStringFunction
=
(
fn
)
=>
{
const
cache
=
Object
.
create
(
null
);
return
(
str
)
=>
{
const
hit
=
cache
[
str
];
return
hit
||
(
cache
[
str
]
=
fn
(
str
));
};
};
const
PRIMARY_COLOR
=
"
#007aff
"
;
const
SCHEME_RE
=
/^
([
a-z-
]
+:
)?\/\/
/i
;
const
DATA_RE
=
/^data:.*,.*/
;
const
isObject
=
(
val
)
=>
val
!==
null
&&
typeof
val
===
"
object
"
;
class
BaseFormatter
{
constructor
()
{
...
...
@@ -650,6 +659,24 @@
function
useCurrentPageId
()
{
return
vue
.
getCurrentInstance
().
root
.
proxy
.
$page
.
id
;
}
function
getRealRoute
(
fromRoute
,
toRoute
)
{
if
(
toRoute
.
indexOf
(
"
/
"
)
===
0
)
{
return
toRoute
;
}
if
(
toRoute
.
indexOf
(
"
./
"
)
===
0
)
{
return
getRealRoute
(
fromRoute
,
toRoute
.
substr
(
2
));
}
const
toRouteArray
=
toRoute
.
split
(
"
/
"
);
const
toRouteLength
=
toRouteArray
.
length
;
let
i
=
0
;
for
(;
i
<
toRouteLength
&&
toRouteArray
[
i
]
===
"
..
"
;
i
++
)
{
}
toRouteArray
.
splice
(
0
,
i
);
toRoute
=
toRouteArray
.
join
(
"
/
"
);
const
fromRouteArray
=
fromRoute
.
length
>
0
?
fromRoute
.
split
(
"
/
"
)
:
[];
fromRouteArray
.
splice
(
fromRouteArray
.
length
-
i
-
1
,
i
+
1
);
return
"
/
"
+
fromRouteArray
.
concat
(
toRouteArray
).
join
(
"
/
"
);
}
const
callbacks
=
{};
function
createCallbacks
(
namespace
)
{
let
scopedCallbacks
=
callbacks
[
namespace
];
...
...
@@ -1059,7 +1086,43 @@
};
}
});
function
getRealPath
()
{
function
getRealPath
(
filepath
)
{
if
(
filepath
.
indexOf
(
"
//
"
)
===
0
)
{
return
"
https:
"
+
filepath
;
}
if
(
SCHEME_RE
.
test
(
filepath
)
||
DATA_RE
.
test
(
filepath
))
{
return
filepath
;
}
if
(
isSystemURL
(
filepath
))
{
return
"
file://
"
+
normalizeLocalPath
(
filepath
);
}
const
wwwPath
=
"
file://
"
+
normalizeLocalPath
(
"
_www
"
);
if
(
filepath
.
indexOf
(
"
/
"
)
===
0
)
{
if
(
filepath
.
startsWith
(
"
/storage/
"
)
||
filepath
.
includes
(
"
/Containers/Data/Application/
"
))
{
return
"
file://
"
+
filepath
;
}
return
wwwPath
+
filepath
;
}
if
(
filepath
.
indexOf
(
"
../
"
)
===
0
||
filepath
.
indexOf
(
"
./
"
)
===
0
)
{
if
(
typeof
__id__
===
"
string
"
)
{
return
wwwPath
+
getRealRoute
(
"
/
"
+
__id__
,
filepath
);
}
else
{
const
pages
=
getCurrentPages
();
if
(
pages
.
length
)
{
return
wwwPath
+
getRealRoute
(
"
/
"
+
pages
[
pages
.
length
-
1
].
route
,
filepath
);
}
}
}
return
filepath
;
}
const
normalizeLocalPath
=
cacheStringFunction
((
filepath
)
=>
{
return
plus
.
io
.
convertLocalFileSystemURL
(
filepath
).
replace
(
/^
\/?
apps
\/
/
,
"
/android_asset/apps/
"
).
replace
(
/
\/
$/
,
""
);
});
function
isSystemURL
(
filepath
)
{
if
(
filepath
.
indexOf
(
"
_www
"
)
===
0
||
filepath
.
indexOf
(
"
_doc
"
)
===
0
||
filepath
.
indexOf
(
"
_documents
"
)
===
0
||
filepath
.
indexOf
(
"
_downloads
"
)
===
0
)
{
return
true
;
}
return
false
;
}
var
ResizeSensor
=
/* @__PURE__ */
defineBuiltInComponent
({
name
:
"
ResizeSensor
"
,
...
...
packages/uni-app-plus/package.json
浏览文件 @
3f7548b8
...
...
@@ -16,10 +16,6 @@
"bugs"
:
{
"url"
:
"https://github.com/dcloudio/uni-app/issues"
},
"uni-app"
:
{
"name"
:
"uni-app"
,
"apply"
:
"app"
},
"dependencies"
:
{
"vue3-webcomponent-wrapper"
:
"^0.1.4"
},
...
...
packages/uni-app-vite/dist/index.js
浏览文件 @
3f7548b8
"
use strict
"
;
Object
.
defineProperty
(
exports
,
"
__esModule
"
,
{
value
:
true
});
const
uni_shared_1
=
require
(
"
@dcloudio/uni-shared
"
);
const
uni_cli_shared_1
=
require
(
"
@dcloudio/uni-cli-shared
"
);
const
mainJs_1
=
require
(
"
./plugins/mainJs
"
);
const
manifestJson_1
=
require
(
"
./plugins/manifestJson
"
);
const
pagesJson_1
=
require
(
"
./plugins/pagesJson
"
);
const
resolveId_1
=
require
(
"
./plugins/resolveId
"
);
const
UniAppPlugin
=
{
name
:
'
vite:uni-app
'
,
uni
:
{
compilerOptions
:
{
isNativeTag
:
uni_shared_1
.
isServiceNativeTag
,
isCustomElement
:
uni_shared_1
.
isServiceCustomElement
,
},
transformEvent
:
{
tap
:
'
click
'
,
},
},
config
()
{
return
{
build
:
{
lib
:
{
name
:
'
AppService
'
,
entry
:
uni_cli_shared_1
.
resolveMainPathOnce
(
process
.
env
.
UNI_INPUT_DIR
),
formats
:
[
'
iife
'
],
},
rollupOptions
:
{
external
:
[
'
vue
'
],
output
:
{
entryFileNames
:
'
app-service.js
'
,
globals
:
{
vue
:
'
Vue
'
,
},
},
},
},
};
},
};
exports
.
default
=
[
resolveId_1
.
uniResolveIdPlugin
(),
mainJs_1
.
uniMainJsPlugin
(),
manifestJson_1
.
uniManifestJsonPlugin
(),
pagesJson_1
.
uniPagesJsonPlugin
(),
...
...
packages/uni-app-vite/dist/plugins/mainJs.js
浏览文件 @
3f7548b8
...
...
@@ -13,7 +13,7 @@ function uniMainJsPlugin() {
?
createApp
(
code
)
:
createLegacyApp
(
code
);
return
{
code
,
code
:
`import './pages.json.js';`
+
code
,
map
:
this
.
getCombinedSourcemap
(),
};
}
...
...
packages/uni-app-vite/dist/plugins/manifestJson.js
浏览文件 @
3f7548b8
...
...
@@ -2,25 +2,8 @@
Object
.
defineProperty
(
exports
,
"
__esModule
"
,
{
value
:
true
});
exports
.
uniManifestJsonPlugin
=
void
0
;
const
uni_cli_shared_1
=
require
(
"
@dcloudio/uni-cli-shared
"
);
const
defaultRouter
=
{
mode
:
'
hash
'
,
base
:
'
/
'
,
};
const
defaultAsync
=
{
loading
:
'
AsyncLoading
'
,
error
:
'
AsyncError
'
,
delay
:
200
,
timeout
:
60000
,
suspensible
:
true
,
};
const
defaultNetworkTimeout
=
{
request
:
60000
,
connectSocket
:
60000
,
uploadFile
:
60000
,
downloadFile
:
60000
,
};
const
defaultQQMapKey
=
'
XVXBZ-NDMC4-JOGUS-XGIEE-QVHDZ-AMFV2
'
;
function
uniManifestJsonPlugin
()
{
let
manifestJson
;
return
uni_cli_shared_1
.
defineUniManifestJsonPlugin
((
opts
)
=>
{
return
{
name
:
'
vite:uni-app-manifest-json
'
,
...
...
@@ -29,39 +12,15 @@ function uniManifestJsonPlugin() {
if
(
!
opts
.
filter
(
id
))
{
return
;
}
const
manifest
=
JSON
.
parse
(
code
);
const
{
debug
,
h5
}
=
manifest
;
const
appid
=
(
manifest
.
appid
||
''
).
replace
(
'
__UNI__
'
,
''
);
const
router
=
Object
.
assign
(
Object
.
assign
({},
defaultRouter
),
((
h5
&&
h5
.
router
)
||
{}));
if
(
!
router
.
base
)
{
router
.
base
=
'
/
'
;
}
const
async
=
Object
.
assign
(
Object
.
assign
({},
defaultAsync
),
((
h5
&&
h5
.
async
)
||
{}));
const
networkTimeout
=
Object
.
assign
(
Object
.
assign
({},
defaultNetworkTimeout
),
(
manifest
.
networkTimeout
||
{}));
const
sdkConfigs
=
(
h5
&&
h5
.
sdkConfigs
)
||
{};
const
qqMapKey
=
(
sdkConfigs
.
maps
&&
sdkConfigs
.
maps
.
qqmap
&&
sdkConfigs
.
maps
.
qqmap
.
key
)
||
defaultQQMapKey
;
const
flexDirection
=
(
manifest
[
'
app
'
]
&&
manifest
[
'
app
'
].
nvue
&&
manifest
[
'
app
'
].
nvue
[
'
flex-direction
'
])
||
'
column
'
;
return
{
code
:
`export const appid = '
${
appid
||
''
}
'
export const debug =
${
!!
debug
}
export const nvue =
${
JSON
.
stringify
({
'
flex-direction
'
:
flexDirection
,
})}
export const networkTimeout =
${
JSON
.
stringify
(
networkTimeout
)}
// h5
export const router =
${
JSON
.
stringify
(
router
)}
export const async =
${
JSON
.
stringify
(
async
)}
export const qqMapKey = '
${
qqMapKey
}
'
export const sdkConfigs =
${
JSON
.
stringify
(
sdkConfigs
)}
`
,
map
:
{
mappings
:
''
},
};
manifestJson
=
uni_cli_shared_1
.
normalizeAppManifestJson
(
JSON
.
parse
(
code
));
return
''
;
},
generateBundle
()
{
this
.
emitFile
({
fileName
:
`manifest.json`
,
type
:
'
asset
'
,
source
:
JSON
.
stringify
(
manifestJson
,
null
,
2
),
});
},
};
});
...
...
packages/uni-app-vite/dist/plugins/pagesJson.js
浏览文件 @
3f7548b8
"
use strict
"
;
var
__importDefault
=
(
this
&&
this
.
__importDefault
)
||
function
(
mod
)
{
return
(
mod
&&
mod
.
__esModule
)
?
mod
:
{
"
default
"
:
mod
};
};
Object
.
defineProperty
(
exports
,
"
__esModule
"
,
{
value
:
true
});
exports
.
uniPagesJsonPlugin
=
void
0
;
const
fs_1
=
__importDefault
(
require
(
"
fs
"
));
const
path_1
=
__importDefault
(
require
(
"
path
"
));
const
slash_1
=
__importDefault
(
require
(
"
slash
"
));
const
shared_1
=
require
(
"
@vue/shared
"
);
const
uni_cli_shared_1
=
require
(
"
@dcloudio/uni-cli-shared
"
);
const
pkg
=
require
(
'
@dcloudio/vite-plugin-uni/package.json
'
);
function
uniPagesJsonPlugin
()
{
return
uni_cli_shared_1
.
defineUniPagesJsonPlugin
((
opts
)
=>
{
return
{
name
:
'
vite:uni-app-pages-json
'
,
enforce
:
'
pre
'
,
transform
(
code
,
id
,
ssr
)
{
if
(
opts
.
filter
(
id
))
{
const
{
resolvedConfig
}
=
opts
;
return
{
code
:
(
resolvedConfig
.
command
===
'
serve
'
||
(
resolvedConfig
.
command
===
'
build
'
&&
ssr
)
?
registerGlobalCode
(
resolvedConfig
,
ssr
)
:
''
)
+
generatePagesJsonCode
(
ssr
,
code
,
resolvedConfig
),
map
:
{
mappings
:
''
},
};
transform
(
code
,
id
)
{
if
(
!
opts
.
filter
(
id
))
{
return
;
}
return
(
`import './manifest.json.js'\n`
+
uni_cli_shared_1
.
normalizeAppPagesJson
(
JSON
.
parse
(
code
)));
},
};
});
}
exports
.
uniPagesJsonPlugin
=
uniPagesJsonPlugin
;
function
generatePagesJsonCode
(
ssr
,
jsonStr
,
config
)
{
const
globalName
=
getGlobal
(
ssr
);
const
pagesJson
=
uni_cli_shared_1
.
normalizePagesJson
(
jsonStr
,
process
.
env
.
UNI_INPUT_DIR
,
process
.
env
.
UNI_PLATFORM
);
const
{
importLayoutComponentsCode
,
defineLayoutComponentsCode
}
=
generateLayoutComponentsCode
(
globalName
,
pagesJson
);
const
definePagesCode
=
generatePagesDefineCode
(
pagesJson
,
config
);
const
uniRoutesCode
=
generateRoutes
(
globalName
,
pagesJson
,
config
);
const
uniConfigCode
=
generateConfig
(
globalName
,
pagesJson
,
config
);
const
manifestJsonPath
=
slash_1
.
default
(
path_1
.
default
.
resolve
(
process
.
env
.
UNI_INPUT_DIR
,
'
manifest.json.js
'
));
const
cssCode
=
generateCssCode
(
config
);
return
`
import { defineAsyncComponent, resolveComponent, createVNode, withCtx, openBlock, createBlock } from 'vue'
import { PageComponent, AsyncLoadingComponent, AsyncErrorComponent } from '@dcloudio/uni-h5'
import { appid, debug, networkTimeout, router, async, sdkConfigs, qqMapKey, nvue } from '
${
manifestJsonPath
}
'
${
importLayoutComponentsCode
}
const extend = Object.assign
${
cssCode
}
${
uniConfigCode
}
${
defineLayoutComponentsCode
}
${
definePagesCode
}
${
uniRoutesCode
}
${
config
.
command
===
'
serve
'
?
hmrCode
:
''
}
export {}
`
;
}
const
hmrCode
=
`if(import.meta.hot){
import.meta.hot.on('invalidate', (data) => {
import.meta.hot.invalidate()
})
}`
;
function
getGlobal
(
ssr
)
{
return
ssr
?
'
global
'
:
'
window
'
;
}
function
registerGlobalCode
(
config
,
ssr
)
{
const
name
=
getGlobal
(
ssr
);
const
rpx2pxCode
=
!
ssr
&&
config
.
define
.
__UNI_FEATURE_RPX__
?
`import {upx2px} from '@dcloudio/uni-h5'
${
name
}
.rpx2px = upx2px
`
:
''
;
return
`
${
rpx2pxCode
}
import {uni,getCurrentPages,getApp,UniServiceJSBridge,UniViewJSBridge} from '@dcloudio/uni-h5'
${
name
}
.getApp = getApp
${
name
}
.getCurrentPages = getCurrentPages
${
name
}
.uni = uni
${
name
}
.UniViewJSBridge = UniViewJSBridge
${
name
}
.UniServiceJSBridge = UniServiceJSBridge
`
;
}
function
normalizePageIdentifier
(
path
)
{
return
shared_1
.
capitalize
(
shared_1
.
camelize
(
path
.
replace
(
/
\/
/g
,
'
-
'
)));
}
function
generateCssCode
(
config
)
{
const
define
=
config
.
define
;
const
cssFiles
=
[
uni_cli_shared_1
.
H5_FRAMEWORK_STYLE_PATH
+
'
base.css
'
];
// if (define.__UNI_FEATURE_PAGES__) {
cssFiles
.
push
(
uni_cli_shared_1
.
H5_FRAMEWORK_STYLE_PATH
+
'
async.css
'
);
// }
if
(
define
.
__UNI_FEATURE_RESPONSIVE__
)
{
cssFiles
.
push
(
uni_cli_shared_1
.
H5_FRAMEWORK_STYLE_PATH
+
'
layout.css
'
);
}
if
(
define
.
__UNI_FEATURE_NAVIGATIONBAR__
)
{
cssFiles
.
push
(
uni_cli_shared_1
.
H5_FRAMEWORK_STYLE_PATH
+
'
pageHead.css
'
);
}
if
(
define
.
__UNI_FEATURE_TABBAR__
)
{
cssFiles
.
push
(
uni_cli_shared_1
.
H5_FRAMEWORK_STYLE_PATH
+
'
tabBar.css
'
);
}
if
(
define
.
__UNI_FEATURE_NVUE__
)
{
cssFiles
.
push
(
uni_cli_shared_1
.
H5_FRAMEWORK_STYLE_PATH
+
'
nvue.css
'
);
}
if
(
define
.
__UNI_FEATURE_PULL_DOWN_REFRESH__
)
{
cssFiles
.
push
(
uni_cli_shared_1
.
H5_FRAMEWORK_STYLE_PATH
+
'
pageRefresh.css
'
);
}
if
(
define
.
__UNI_FEATURE_NAVIGATIONBAR_SEARCHINPUT__
)
{
cssFiles
.
push
(
uni_cli_shared_1
.
BASE_COMPONENTS_STYLE_PATH
+
'
input.css
'
);
}
if
(
config
.
command
===
'
serve
'
)
{
// 开发模式,自动添加所有API相关css
Object
.
keys
(
uni_cli_shared_1
.
API_DEPS_CSS
).
forEach
((
name
)
=>
{
const
styles
=
uni_cli_shared_1
.
API_DEPS_CSS
[
name
];
styles
.
forEach
((
style
)
=>
{
if
(
!
cssFiles
.
includes
(
style
))
{
cssFiles
.
push
(
style
);
}
});
});
}
return
cssFiles
.
map
((
file
)
=>
`import '
${
file
}
'`
).
join
(
'
\n
'
);
}
function
generateLayoutComponentsCode
(
globalName
,
pagesJson
)
{
const
windowNames
=
[
'
topWindow
'
,
'
leftWindow
'
,
'
rightWindow
'
,
];
let
importLayoutComponentsCode
=
''
;
let
defineLayoutComponentsCode
=
`
${
globalName
}
.__uniLayout =
${
globalName
}
.__uniLayout || {}\n`
;
windowNames
.
forEach
((
name
)
=>
{
const
windowConfig
=
pagesJson
[
name
];
if
(
windowConfig
&&
windowConfig
.
path
)
{
importLayoutComponentsCode
+=
`import
${
name
}
from './
${
windowConfig
.
path
}
'\n`
;
defineLayoutComponentsCode
+=
`
${
globalName
}
.__uniConfig.
${
name
}
.component =
${
name
}
\n`
;
}
});
return
{
importLayoutComponentsCode
,
defineLayoutComponentsCode
,
};
}
function
generatePageDefineCode
(
pageOptions
)
{
const
pageIdent
=
normalizePageIdentifier
(
pageOptions
.
path
);
return
`const
${
pageIdent
}
Loader = ()=>import('./
${
pageOptions
.
path
}
?mpType=page')
const
${
pageIdent
}
= defineAsyncComponent(extend({loader:
${
pageIdent
}
Loader},AsyncComponentOptions))`
;
}
function
generatePagesDefineCode
(
pagesJson
,
_config
)
{
const
{
pages
}
=
pagesJson
;
return
(
`const AsyncComponentOptions = {
loadingComponent: AsyncLoadingComponent,
errorComponent: AsyncErrorComponent,
delay: async.delay,
timeout: async.timeout,
suspensible: async.suspensible
}
`
+
pages
.
map
((
pageOptions
)
=>
generatePageDefineCode
(
pageOptions
)).
join
(
'
\n
'
));
}
function
normalizePagesRoute
(
pagesJson
)
{
const
firstPagePath
=
pagesJson
.
pages
[
0
].
path
;
const
tabBarList
=
(
pagesJson
.
tabBar
&&
pagesJson
.
tabBar
.
list
)
||
[];
return
pagesJson
.
pages
.
map
((
pageOptions
)
=>
{
const
pagePath
=
pageOptions
.
path
;
const
name
=
normalizePageIdentifier
(
pagePath
);
const
isEntry
=
firstPagePath
===
pagePath
?
true
:
undefined
;
const
tabBarIndex
=
tabBarList
.
findIndex
((
tabBarPage
)
=>
tabBarPage
.
pagePath
===
pagePath
);
const
isTabBar
=
tabBarIndex
!==
-
1
?
true
:
undefined
;
const
isNVue
=
fs_1
.
default
.
existsSync
(
path_1
.
default
.
join
(
process
.
env
.
UNI_INPUT_DIR
,
pagePath
+
'
.nvue
'
));
let
windowTop
=
0
;
const
meta
=
shared_1
.
extend
({
route
:
pageOptions
.
path
,
isNVue
:
isNVue
?
true
:
undefined
,
isQuit
:
isEntry
||
isTabBar
?
true
:
undefined
,
isEntry
,
isTabBar
,
tabBarIndex
,
windowTop
,
},
pageOptions
.
style
);
return
{
name
,
path
:
pageOptions
.
path
,
meta
,
};
});
}
function
generatePageRoute
({
name
,
path
,
meta
},
config
)
{
const
{
isEntry
}
=
meta
;
const
alias
=
isEntry
?
`\n alias:'/
${
path
}
',`
:
''
;
return
`{
path:'/
${
isEntry
?
''
:
path
}
',
${
alias
}
component:{setup(){return ()=>renderPage(
${
name
}
)}},
loader:
${
normalizePageIdentifier
(
path
)}
Loader,
meta:
${
JSON
.
stringify
(
meta
)}
}`
;
}
function
generatePagesRoute
(
pagesRouteOptions
,
config
)
{
return
pagesRouteOptions
.
map
((
pageOptions
)
=>
generatePageRoute
(
pageOptions
,
config
));
}
function
generateRoutes
(
globalName
,
pagesJson
,
config
)
{
return
`
function renderPage(component){
return (openBlock(), createBlock(PageComponent, null, {page: withCtx(() => [createVNode(component, { ref: "page" }, null, 512 /* NEED_PATCH */)]), _: 1 /* STABLE */}))
}
${
globalName
}
.__uniRoutes=[
${[
...
generatePagesRoute
(
normalizePagesRoute
(
pagesJson
),
config
),
].
join
(
'
,
'
)}
]`
;
}
function
generateConfig
(
globalName
,
pagesJson
,
config
)
{
delete
pagesJson
.
pages
;
delete
pagesJson
.
subPackages
;
delete
pagesJson
.
subpackages
;
pagesJson
.
compilerVersion
=
pkg
[
'
uni-app
'
].
compilerVersion
;
return
((
config
.
command
===
'
serve
'
?
''
:
`
${
globalName
}
['____'+appid+'____']=true
delete
${
globalName
}
['____'+appid+'____']
`
)
+
`
${
globalName
}
.__uniConfig=extend(
${
JSON
.
stringify
(
pagesJson
)}
,{
async,
debug,
networkTimeout,
sdkConfigs,
qqMapKey,
nvue,
router
})
`
);
}
packages/uni-app-vite/dist/plugins/resolveId.js
已删除
100644 → 0
浏览文件 @
d9cedce2
"
use strict
"
;
var
__importDefault
=
(
this
&&
this
.
__importDefault
)
||
function
(
mod
)
{
return
(
mod
&&
mod
.
__esModule
)
?
mod
:
{
"
default
"
:
mod
};
};
Object
.
defineProperty
(
exports
,
"
__esModule
"
,
{
value
:
true
});
exports
.
uniResolveIdPlugin
=
void
0
;
const
path_1
=
__importDefault
(
require
(
"
path
"
));
const
debug_1
=
__importDefault
(
require
(
"
debug
"
));
const
uni_cli_shared_1
=
require
(
"
@dcloudio/uni-cli-shared
"
);
const
debugResolve
=
debug_1
.
default
(
'
vite:uni:resolve
'
);
function
uniResolveIdPlugin
()
{
const
resolveCache
=
{};
return
{
name
:
'
vite:uni-app-resolve-id
'
,
enforce
:
'
pre
'
,
configResolved
()
{
const
{
MODE
}
=
uni_cli_shared_1
.
parseCompatConfigOnce
(
process
.
env
.
UNI_INPUT_DIR
);
resolveCache
[
'
@dcloudio/uni-h5
'
]
=
uni_cli_shared_1
.
resolveBuiltIn
(
path_1
.
default
.
join
(
'
@dcloudio/uni-h5
'
,
'
dist/uni-h5.es.js
'
));
resolveCache
[
'
@dcloudio/uni-h5-vue
'
]
=
uni_cli_shared_1
.
resolveBuiltIn
(
path_1
.
default
.
join
(
'
@dcloudio/uni-h5-vue
'
,
`dist/vue.runtime.
${
MODE
===
2
?
'
compat.
'
:
''
}
esm.js`
));
},
resolveId
(
id
)
{
if
(
id
===
'
vue
'
)
{
id
=
'
@dcloudio/uni-h5-vue
'
;
}
const
cache
=
resolveCache
[
id
];
if
(
cache
)
{
debugResolve
(
'
cache
'
,
id
,
cache
);
return
cache
;
}
if
(
id
.
startsWith
(
'
@dcloudio/uni-h5/style
'
)
||
id
.
startsWith
(
'
@dcloudio/uni-components/style
'
))
{
return
(
resolveCache
[
id
]
=
uni_cli_shared_1
.
resolveBuiltIn
(
id
));
}
},
};
}
exports
.
uniResolveIdPlugin
=
uniResolveIdPlugin
;
packages/uni-app-vite/src/index.ts
浏览文件 @
3f7548b8
import
{
UniVitePlugin
}
from
'
@dcloudio/uni-cli-shared
'
import
{
isServiceNativeTag
,
isServiceCustomElement
,
}
from
'
@dcloudio/uni-shared
'
import
{
resolveMainPathOnce
,
UniVitePlugin
}
from
'
@dcloudio/uni-cli-shared
'
import
{
uniMainJsPlugin
}
from
'
./plugins/mainJs
'
import
{
uniManifestJsonPlugin
}
from
'
./plugins/manifestJson
'
import
{
uniPagesJsonPlugin
}
from
'
./plugins/pagesJson
'
import
{
uniResolveIdPlugin
}
from
'
./plugins/resolveId
'
const
UniAppPlugin
:
UniVitePlugin
=
{
name
:
'
vite:uni-app
'
,
uni
:
{
compilerOptions
:
{
isNativeTag
:
isServiceNativeTag
,
isCustomElement
:
isServiceCustomElement
,
},
transformEvent
:
{
tap
:
'
click
'
,
},
},
config
()
{
return
{
build
:
{
lib
:
{
name
:
'
AppService
'
,
entry
:
resolveMainPathOnce
(
process
.
env
.
UNI_INPUT_DIR
),
formats
:
[
'
iife
'
],
},
rollupOptions
:
{
external
:
[
'
vue
'
],
output
:
{
entryFileNames
:
'
app-service.js
'
,
globals
:
{
vue
:
'
Vue
'
,
},
},
},
},
}
},
}
export
default
[
uniResolveIdPlugin
(),
uniMainJsPlugin
(),
uniManifestJsonPlugin
(),
uniPagesJsonPlugin
(),
...
...
packages/uni-app-vite/src/plugins/mainJs.ts
浏览文件 @
3f7548b8
...
...
@@ -11,7 +11,7 @@ export function uniMainJsPlugin() {
?
createApp
(
code
)
:
createLegacyApp
(
code
)
return
{
code
,
code
:
`import './pages.json.js';`
+
code
,
map
:
this
.
getCombinedSourcemap
(),
}
}
...
...
packages/uni-app-vite/src/plugins/manifestJson.ts
浏览文件 @
3f7548b8
import
{
Plugin
}
from
'
vite
'
import
{
defineUniManifestJsonPlugin
}
from
'
@dcloudio/uni-cli-shared
'
const
defaultRouter
=
{
mode
:
'
hash
'
,
base
:
'
/
'
,
}
const
defaultAsync
=
{
loading
:
'
AsyncLoading
'
,
error
:
'
AsyncError
'
,
delay
:
200
,
timeout
:
60000
,
suspensible
:
true
,
}
const
defaultNetworkTimeout
=
{
request
:
60000
,
connectSocket
:
60000
,
uploadFile
:
60000
,
downloadFile
:
60000
,
}
const
defaultQQMapKey
=
'
XVXBZ-NDMC4-JOGUS-XGIEE-QVHDZ-AMFV2
'
import
{
defineUniManifestJsonPlugin
,
normalizeAppManifestJson
,
}
from
'
@dcloudio/uni-cli-shared
'
export
function
uniManifestJsonPlugin
():
Plugin
{
let
manifestJson
:
Record
<
string
,
any
>
return
defineUniManifestJsonPlugin
((
opts
)
=>
{
return
{
name
:
'
vite:uni-app-manifest-json
'
,
...
...
@@ -33,49 +15,15 @@ export function uniManifestJsonPlugin(): Plugin {
if
(
!
opts
.
filter
(
id
))
{
return
}
const
manifest
=
JSON
.
parse
(
code
)
const
{
debug
,
h5
}
=
manifest
const
appid
=
(
manifest
.
appid
||
''
).
replace
(
'
__UNI__
'
,
''
)
const
router
=
{
...
defaultRouter
,
...((
h5
&&
h5
.
router
)
||
{})
}
if
(
!
router
.
base
)
{
router
.
base
=
'
/
'
}
const
async
=
{
...
defaultAsync
,
...((
h5
&&
h5
.
async
)
||
{})
}
const
networkTimeout
=
{
...
defaultNetworkTimeout
,
...(
manifest
.
networkTimeout
||
{}),
}
const
sdkConfigs
=
(
h5
&&
h5
.
sdkConfigs
)
||
{}
const
qqMapKey
=
(
sdkConfigs
.
maps
&&
sdkConfigs
.
maps
.
qqmap
&&
sdkConfigs
.
maps
.
qqmap
.
key
)
||
defaultQQMapKey
const
flexDirection
=
(
manifest
[
'
app
'
]
&&
manifest
[
'
app
'
].
nvue
&&
manifest
[
'
app
'
].
nvue
[
'
flex-direction
'
])
||
'
column
'
return
{
code
:
`export const appid = '
${
appid
||
''
}
'
export const debug =
${
!!
debug
}
export const nvue =
${
JSON
.
stringify
({
'
flex-direction
'
:
flexDirection
,
})}
export const networkTimeout =
${
JSON
.
stringify
(
networkTimeout
)}
// h5
export const router =
${
JSON
.
stringify
(
router
)}
export const async =
${
JSON
.
stringify
(
async
)}
export const qqMapKey = '
${
qqMapKey
}
'
export const sdkConfigs =
${
JSON
.
stringify
(
sdkConfigs
)}
`
,
map
:
{
mappings
:
''
},
}
manifestJson
=
normalizeAppManifestJson
(
JSON
.
parse
(
code
))
return
''
},
generateBundle
()
{
this
.
emitFile
({
fileName
:
`manifest.json`
,
type
:
'
asset
'
,
source
:
JSON
.
stringify
(
manifestJson
,
null
,
2
),
})
},
}
})
...
...
packages/uni-app-vite/src/plugins/pagesJson.ts
浏览文件 @
3f7548b8
import
fs
from
'
fs
'
import
path
from
'
path
'
import
slash
from
'
slash
'
import
{
Plugin
,
ResolvedConfig
}
from
'
vite
'
import
{
extend
,
camelize
,
capitalize
}
from
'
@vue/shared
'
import
{
Plugin
}
from
'
vite
'
import
{
API_DEPS_CSS
,
FEATURE_DEFINES
,
H5_FRAMEWORK_STYLE_PATH
,
BASE_COMPONENTS_STYLE_PATH
,
normalizePagesJson
,
defineUniPagesJsonPlugin
,
normalizeAppPagesJson
,
}
from
'
@dcloudio/uni-cli-shared
'
const
pkg
=
require
(
'
@dcloudio/vite-plugin-uni/package.json
'
)
export
function
uniPagesJsonPlugin
():
Plugin
{
return
defineUniPagesJsonPlugin
((
opts
)
=>
{
return
{
name
:
'
vite:uni-app-pages-json
'
,
enforce
:
'
pre
'
,
transform
(
code
,
id
,
ssr
)
{
if
(
opts
.
filter
(
id
))
{
const
{
resolvedConfig
}
=
opts
return
{
code
:
(
resolvedConfig
.
command
===
'
serve
'
||
(
resolvedConfig
.
command
===
'
build
'
&&
ssr
)
?
registerGlobalCode
(
resolvedConfig
,
ssr
)
:
''
)
+
generatePagesJsonCode
(
ssr
,
code
,
resolvedConfig
),
map
:
{
mappings
:
''
},
}
transform
(
code
,
id
)
{
if
(
!
opts
.
filter
(
id
))
{
return
}
return
(
`import './manifest.json.js'\n`
+
normalizeAppPagesJson
(
JSON
.
parse
(
code
))
)
},
}
})
}
interface
PageRouteOptions
{
name
:
string
path
:
string
meta
:
Partial
<
UniApp
.
PageRouteMeta
>
}
function
generatePagesJsonCode
(
ssr
:
boolean
|
undefined
,
jsonStr
:
string
,
config
:
ResolvedConfig
)
{
const
globalName
=
getGlobal
(
ssr
)
const
pagesJson
=
normalizePagesJson
(
jsonStr
,
process
.
env
.
UNI_INPUT_DIR
,
process
.
env
.
UNI_PLATFORM
)
const
{
importLayoutComponentsCode
,
defineLayoutComponentsCode
}
=
generateLayoutComponentsCode
(
globalName
,
pagesJson
)
const
definePagesCode
=
generatePagesDefineCode
(
pagesJson
,
config
)
const
uniRoutesCode
=
generateRoutes
(
globalName
,
pagesJson
,
config
)
const
uniConfigCode
=
generateConfig
(
globalName
,
pagesJson
,
config
)
const
manifestJsonPath
=
slash
(
path
.
resolve
(
process
.
env
.
UNI_INPUT_DIR
,
'
manifest.json.js
'
)
)
const
cssCode
=
generateCssCode
(
config
)
return
`
import { defineAsyncComponent, resolveComponent, createVNode, withCtx, openBlock, createBlock } from 'vue'
import { PageComponent, AsyncLoadingComponent, AsyncErrorComponent } from '@dcloudio/uni-h5'
import { appid, debug, networkTimeout, router, async, sdkConfigs, qqMapKey, nvue } from '
${
manifestJsonPath
}
'
${
importLayoutComponentsCode
}
const extend = Object.assign
${
cssCode
}
${
uniConfigCode
}
${
defineLayoutComponentsCode
}
${
definePagesCode
}
${
uniRoutesCode
}
${
config
.
command
===
'
serve
'
?
hmrCode
:
''
}
export {}
`
}
const
hmrCode
=
`if(import.meta.hot){
import.meta.hot.on('invalidate', (data) => {
import.meta.hot.invalidate()
})
}`
function
getGlobal
(
ssr
?:
boolean
)
{
return
ssr
?
'
global
'
:
'
window
'
}
function
registerGlobalCode
(
config
:
ResolvedConfig
,
ssr
?:
boolean
)
{
const
name
=
getGlobal
(
ssr
)
const
rpx2pxCode
=
!
ssr
&&
config
.
define
!
.
__UNI_FEATURE_RPX__
?
`import {upx2px} from '@dcloudio/uni-h5'
${
name
}
.rpx2px = upx2px
`
:
''
return
`
${
rpx2pxCode
}
import {uni,getCurrentPages,getApp,UniServiceJSBridge,UniViewJSBridge} from '@dcloudio/uni-h5'
${
name
}
.getApp = getApp
${
name
}
.getCurrentPages = getCurrentPages
${
name
}
.uni = uni
${
name
}
.UniViewJSBridge = UniViewJSBridge
${
name
}
.UniServiceJSBridge = UniServiceJSBridge
`
}
function
normalizePageIdentifier
(
path
:
string
)
{
return
capitalize
(
camelize
(
path
.
replace
(
/
\/
/g
,
'
-
'
)))
}
function
generateCssCode
(
config
:
ResolvedConfig
)
{
const
define
=
config
.
define
!
as
FEATURE_DEFINES
const
cssFiles
=
[
H5_FRAMEWORK_STYLE_PATH
+
'
base.css
'
]
// if (define.__UNI_FEATURE_PAGES__) {
cssFiles
.
push
(
H5_FRAMEWORK_STYLE_PATH
+
'
async.css
'
)
// }
if
(
define
.
__UNI_FEATURE_RESPONSIVE__
)
{
cssFiles
.
push
(
H5_FRAMEWORK_STYLE_PATH
+
'
layout.css
'
)
}
if
(
define
.
__UNI_FEATURE_NAVIGATIONBAR__
)
{
cssFiles
.
push
(
H5_FRAMEWORK_STYLE_PATH
+
'
pageHead.css
'
)
}
if
(
define
.
__UNI_FEATURE_TABBAR__
)
{
cssFiles
.
push
(
H5_FRAMEWORK_STYLE_PATH
+
'
tabBar.css
'
)
}
if
(
define
.
__UNI_FEATURE_NVUE__
)
{
cssFiles
.
push
(
H5_FRAMEWORK_STYLE_PATH
+
'
nvue.css
'
)
}
if
(
define
.
__UNI_FEATURE_PULL_DOWN_REFRESH__
)
{
cssFiles
.
push
(
H5_FRAMEWORK_STYLE_PATH
+
'
pageRefresh.css
'
)
}
if
(
define
.
__UNI_FEATURE_NAVIGATIONBAR_SEARCHINPUT__
)
{
cssFiles
.
push
(
BASE_COMPONENTS_STYLE_PATH
+
'
input.css
'
)
}
if
(
config
.
command
===
'
serve
'
)
{
// 开发模式,自动添加所有API相关css
Object
.
keys
(
API_DEPS_CSS
).
forEach
((
name
)
=>
{
const
styles
=
API_DEPS_CSS
[
name
as
keyof
typeof
API_DEPS_CSS
]
styles
.
forEach
((
style
)
=>
{
if
(
!
cssFiles
.
includes
(
style
))
{
cssFiles
.
push
(
style
)
}
})
})
}
return
cssFiles
.
map
((
file
)
=>
`import '
${
file
}
'`
).
join
(
'
\n
'
)
}
function
generateLayoutComponentsCode
(
globalName
:
string
,
pagesJson
:
UniApp
.
PagesJson
)
{
const
windowNames
:
Array
<
'
topWindow
'
|
'
leftWindow
'
|
'
rightWindow
'
>
=
[
'
topWindow
'
,
'
leftWindow
'
,
'
rightWindow
'
,
]
let
importLayoutComponentsCode
=
''
let
defineLayoutComponentsCode
=
`
${
globalName
}
.__uniLayout =
${
globalName
}
.__uniLayout || {}\n`
windowNames
.
forEach
((
name
)
=>
{
const
windowConfig
=
pagesJson
[
name
]
if
(
windowConfig
&&
windowConfig
.
path
)
{
importLayoutComponentsCode
+=
`import
${
name
}
from './
${
windowConfig
.
path
}
'\n`
defineLayoutComponentsCode
+=
`
${
globalName
}
.__uniConfig.
${
name
}
.component =
${
name
}
\n`
}
})
return
{
importLayoutComponentsCode
,
defineLayoutComponentsCode
,
}
}
function
generatePageDefineCode
(
pageOptions
:
UniApp
.
PagesJsonPageOptions
)
{
const
pageIdent
=
normalizePageIdentifier
(
pageOptions
.
path
)
return
`const
${
pageIdent
}
Loader = ()=>import('./
${
pageOptions
.
path
}
?mpType=page')
const
${
pageIdent
}
= defineAsyncComponent(extend({loader:
${
pageIdent
}
Loader},AsyncComponentOptions))`
}
function
generatePagesDefineCode
(
pagesJson
:
UniApp
.
PagesJson
,
_config
:
ResolvedConfig
)
{
const
{
pages
}
=
pagesJson
return
(
`const AsyncComponentOptions = {
loadingComponent: AsyncLoadingComponent,
errorComponent: AsyncErrorComponent,
delay: async.delay,
timeout: async.timeout,
suspensible: async.suspensible
}
`
+
pages
.
map
((
pageOptions
)
=>
generatePageDefineCode
(
pageOptions
)).
join
(
'
\n
'
)
)
}
function
normalizePagesRoute
(
pagesJson
:
UniApp
.
PagesJson
):
PageRouteOptions
[]
{
const
firstPagePath
=
pagesJson
.
pages
[
0
].
path
const
tabBarList
=
(
pagesJson
.
tabBar
&&
pagesJson
.
tabBar
.
list
)
||
[]
return
pagesJson
.
pages
.
map
((
pageOptions
)
=>
{
const
pagePath
=
pageOptions
.
path
const
name
=
normalizePageIdentifier
(
pagePath
)
const
isEntry
=
firstPagePath
===
pagePath
?
true
:
undefined
const
tabBarIndex
=
tabBarList
.
findIndex
(
(
tabBarPage
:
{
pagePath
:
string
})
=>
tabBarPage
.
pagePath
===
pagePath
)
const
isTabBar
=
tabBarIndex
!==
-
1
?
true
:
undefined
const
isNVue
=
fs
.
existsSync
(
path
.
join
(
process
.
env
.
UNI_INPUT_DIR
,
pagePath
+
'
.nvue
'
)
)
let
windowTop
=
0
const
meta
=
extend
(
{
route
:
pageOptions
.
path
,
isNVue
:
isNVue
?
true
:
undefined
,
isQuit
:
isEntry
||
isTabBar
?
true
:
undefined
,
isEntry
,
isTabBar
,
tabBarIndex
,
windowTop
,
},
pageOptions
.
style
)
return
{
name
,
path
:
pageOptions
.
path
,
meta
,
}
})
}
function
generatePageRoute
(
{
name
,
path
,
meta
}:
PageRouteOptions
,
config
:
ResolvedConfig
)
{
const
{
isEntry
}
=
meta
const
alias
=
isEntry
?
`\n alias:'/
${
path
}
',`
:
''
return
`{
path:'/
${
isEntry
?
''
:
path
}
',
${
alias
}
component:{setup(){return ()=>renderPage(
${
name
}
)}},
loader:
${
normalizePageIdentifier
(
path
)}
Loader,
meta:
${
JSON
.
stringify
(
meta
)}
}`
}
function
generatePagesRoute
(
pagesRouteOptions
:
PageRouteOptions
[],
config
:
ResolvedConfig
)
{
return
pagesRouteOptions
.
map
((
pageOptions
)
=>
generatePageRoute
(
pageOptions
,
config
)
)
}
function
generateRoutes
(
globalName
:
string
,
pagesJson
:
UniApp
.
PagesJson
,
config
:
ResolvedConfig
)
{
return
`
function renderPage(component){
return (openBlock(), createBlock(PageComponent, null, {page: withCtx(() => [createVNode(component, { ref: "page" }, null, 512 /* NEED_PATCH */)]), _: 1 /* STABLE */}))
}
${
globalName
}
.__uniRoutes=[
${[
...
generatePagesRoute
(
normalizePagesRoute
(
pagesJson
),
config
),
].
join
(
'
,
'
)}
]`
}
function
generateConfig
(
globalName
:
string
,
pagesJson
:
Record
<
string
,
any
>
,
config
:
ResolvedConfig
)
{
delete
pagesJson
.
pages
delete
pagesJson
.
subPackages
delete
pagesJson
.
subpackages
pagesJson
.
compilerVersion
=
pkg
[
'
uni-app
'
].
compilerVersion
return
(
(
config
.
command
===
'
serve
'
?
''
:
`
${
globalName
}
['____'+appid+'____']=true
delete
${
globalName
}
['____'+appid+'____']
`
)
+
`
${
globalName
}
.__uniConfig=extend(
${
JSON
.
stringify
(
pagesJson
)}
,{
async,
debug,
networkTimeout,
sdkConfigs,
qqMapKey,
nvue,
router
})
`
)
}
packages/uni-app-vite/src/plugins/resolveId.ts
已删除
100644 → 0
浏览文件 @
d9cedce2
import
path
from
'
path
'
import
debug
from
'
debug
'
import
{
Plugin
}
from
'
vite
'
import
{
resolveBuiltIn
,
parseCompatConfigOnce
}
from
'
@dcloudio/uni-cli-shared
'
const
debugResolve
=
debug
(
'
vite:uni:resolve
'
)
export
function
uniResolveIdPlugin
():
Plugin
{
const
resolveCache
:
Record
<
string
,
string
>
=
{}
return
{
name
:
'
vite:uni-app-resolve-id
'
,
enforce
:
'
pre
'
,
configResolved
()
{
const
{
MODE
}
=
parseCompatConfigOnce
(
process
.
env
.
UNI_INPUT_DIR
)
resolveCache
[
'
@dcloudio/uni-h5
'
]
=
resolveBuiltIn
(
path
.
join
(
'
@dcloudio/uni-h5
'
,
'
dist/uni-h5.es.js
'
)
)
resolveCache
[
'
@dcloudio/uni-h5-vue
'
]
=
resolveBuiltIn
(
path
.
join
(
'
@dcloudio/uni-h5-vue
'
,
`dist/vue.runtime.
${
MODE
===
2
?
'
compat.
'
:
''
}
esm.js`
)
)
},
resolveId
(
id
)
{
if
(
id
===
'
vue
'
)
{
id
=
'
@dcloudio/uni-h5-vue
'
}
const
cache
=
resolveCache
[
id
]
if
(
cache
)
{
debugResolve
(
'
cache
'
,
id
,
cache
)
return
cache
}
if
(
id
.
startsWith
(
'
@dcloudio/uni-h5/style
'
)
||
id
.
startsWith
(
'
@dcloudio/uni-components/style
'
)
)
{
return
(
resolveCache
[
id
]
=
resolveBuiltIn
(
id
))
}
},
}
}
packages/uni-cli-shared/package.json
浏览文件 @
3f7548b8
...
...
@@ -23,6 +23,7 @@
"debug"
:
"^4.3.1"
,
"estree-walker"
:
"^2.0.2"
,
"jsonc-parser"
:
"^3.0.0"
,
"merge"
:
"^2.1.1"
,
"slash"
:
"^3.0.0"
,
"tapable"
:
"^2.2.0"
,
"xregexp"
:
"3.1.0"
...
...
packages/
vite-plugin-uni/src/utils
/easycom.ts
→
packages/
uni-cli-shared/src
/easycom.ts
浏览文件 @
3f7548b8
...
...
@@ -6,7 +6,7 @@ import { extend } from '@vue/shared'
import
{
createFilter
}
from
'
@rollup/pluginutils
'
import
{
once
}
from
'
@dcloudio/uni-shared
'
import
{
parsePagesJson
,
parsePagesJsonOnce
}
from
'
@dcloudio/uni-cli-shared
'
import
{
parsePagesJson
,
parsePagesJsonOnce
}
from
'
./json/pages
'
interface
EasycomOption
{
dirs
?:
string
[]
...
...
@@ -23,7 +23,7 @@ interface EasycomCustom {
[
key
:
string
]:
string
}
export
const
debugEasycom
=
debug
(
'
vite:
uni:easycom
'
)
const
debugEasycom
=
debug
(
'
uni:easycom
'
)
const
easycoms
:
EasycomMatcher
[]
=
[]
...
...
packages/uni-cli-shared/src/index.ts
浏览文件 @
3f7548b8
...
...
@@ -3,5 +3,6 @@ export * from './deps'
export
*
from
'
./json
'
export
*
from
'
./vite
'
export
*
from
'
./utils
'
export
*
from
'
./easycom
'
export
*
from
'
./constants
'
export
*
from
'
./preprocess
'
packages/uni-cli-shared/src/json/app.ts
0 → 100644
浏览文件 @
3f7548b8
import
{
recursive
}
from
'
merge
'
import
{
normalizeIdentifier
}
from
'
../utils
'
export
function
normalizeAppManifestJson
(
userManifestJson
:
Record
<
string
,
any
>
)
{
const
manifestJson
=
getDefaultManifestJson
()
recursive
(
true
,
manifestJson
,
{
id
:
userManifestJson
.
appid
||
''
,
name
:
userManifestJson
.
name
||
''
,
description
:
userManifestJson
.
description
||
''
,
version
:
{
name
:
userManifestJson
.
versionName
,
code
:
userManifestJson
.
versionCode
,
},
},
{
plus
:
userManifestJson
[
'
app-plus
'
]
}
)
return
manifestJson
}
const
defaultManifestJson
=
`{
"@platforms": [
"android",
"iPhone",
"iPad"
],
"id": "__WEAPP_ID",
"name": "__WEAPP_NAME",
"version": {
"name": "1.0",
"code": ""
},
"description": "",
"launch_path": "__uniappservice.html",
"developer": {
"name": "",
"email": "",
"url": ""
},
"permissions": {},
"plus": {
"useragent": {
"value": "uni-app appservice",
"concatenate": true
},
"splashscreen": {
"target":"id:1",
"autoclose": true,
"waiting": true,
"alwaysShowBeforeRender":true
},
"popGesture": "close",
"launchwebview": {}
}
}`
function
getDefaultManifestJson
()
{
return
JSON
.
parse
(
defaultManifestJson
)
}
export
function
normalizeAppPagesJson
(
pagesJson
:
Record
<
string
,
any
>
)
{
return
polyfillCode
+
restoreGlobalCode
+
definePageCode
(
pagesJson
)
}
function
definePageCode
(
pagesJson
:
Record
<
string
,
any
>
)
{
const
importPagesCode
:
string
[]
=
[]
const
definePagesCode
:
string
[]
=
[]
pagesJson
.
pages
.
forEach
((
page
:
UniApp
.
UniRoute
)
=>
{
const
pagePath
=
page
.
path
const
pageIdentifier
=
normalizeIdentifier
(
pagePath
)
importPagesCode
.
push
(
`import
${
pageIdentifier
}
from './
${
pagePath
}
.vue?mpType=page'`
)
definePagesCode
.
push
(
`__definePage('
${
pagePath
}
',
${
pageIdentifier
}
)`
)
})
return
importPagesCode
.
join
(
'
\n
'
)
+
'
\n
'
+
definePagesCode
.
join
(
'
\n
'
)
}
const
polyfillCode
=
`
if (typeof Promise !== 'undefined' && !Promise.prototype.finally) {
Promise.prototype.finally = function(callback) {
const promise = this.constructor
return this.then(
value => promise.resolve(callback()).then(() => value),
reason => promise.resolve(callback()).then(() => {
throw reason
})
)
}
}
`
const
restoreGlobalCode
=
`
if(uni.restoreGlobal){
uni.restoreGlobal(weex,plus,setTimeout,clearTimeout,setInterval,clearInterval)
}
`
packages/uni-cli-shared/src/json/index.ts
浏览文件 @
3f7548b8
export
*
from
'
./app
'
export
*
from
'
./json
'
export
*
from
'
./pages
'
export
*
from
'
./manifest
'
packages/uni-cli-shared/src/json/manifest.ts
浏览文件 @
3f7548b8
import
fs
from
'
fs
'
import
path
from
'
path
'
import
{
extend
}
from
'
@vue/shared
'
import
{
once
,
defaultRpx2Unit
}
from
'
@dcloudio/uni-shared
'
...
...
packages/uni-cli-shared/src/utils.ts
浏览文件 @
3f7548b8
...
...
@@ -2,6 +2,7 @@ import fs from 'fs'
import
os
from
'
os
'
import
path
from
'
path
'
import
slash
from
'
slash
'
import
{
camelize
,
capitalize
}
from
'
@vue/shared
'
import
{
once
}
from
'
@dcloudio/uni-shared
'
const
isWindows
=
os
.
platform
()
===
'
win32
'
export
function
normalizePath
(
id
:
string
):
string
{
...
...
@@ -19,3 +20,7 @@ export const resolveMainPathOnce = once((inputDir: string) => {
export
function
resolveBuiltIn
(
path
:
string
)
{
return
require
.
resolve
(
path
,
{
paths
:
[
process
.
env
.
UNI_CLI_CONTEXT
]
})
}
export
function
normalizeIdentifier
(
str
:
string
)
{
return
capitalize
(
camelize
(
str
.
replace
(
/
\/
/g
,
'
-
'
)))
}
packages/uni-cli-shared/src/vite/index.ts
浏览文件 @
3f7548b8
import
{
Plugin
}
from
'
vite
'
import
{
ParserOptions
}
from
'
@vue/compiler-core
'
export
interface
UniVitePlugin
extends
Plugin
{
uni
?:
{
compilerOptions
?:
{
isNativeTag
:
ParserOptions
[
'
isNativeTag
'
]
isCustomElement
:
ParserOptions
[
'
isCustomElement
'
]
}
transformEvent
?:
Record
<
string
,
string
>
}
}
...
...
packages/uni-h5-vite/dist/handleHotUpdate/index.js
0 → 100644
浏览文件 @
3f7548b8
"
use strict
"
;
var
__awaiter
=
(
this
&&
this
.
__awaiter
)
||
function
(
thisArg
,
_arguments
,
P
,
generator
)
{
function
adopt
(
value
)
{
return
value
instanceof
P
?
value
:
new
P
(
function
(
resolve
)
{
resolve
(
value
);
});
}
return
new
(
P
||
(
P
=
Promise
))(
function
(
resolve
,
reject
)
{
function
fulfilled
(
value
)
{
try
{
step
(
generator
.
next
(
value
));
}
catch
(
e
)
{
reject
(
e
);
}
}
function
rejected
(
value
)
{
try
{
step
(
generator
[
"
throw
"
](
value
));
}
catch
(
e
)
{
reject
(
e
);
}
}
function
step
(
result
)
{
result
.
done
?
resolve
(
result
.
value
)
:
adopt
(
result
.
value
).
then
(
fulfilled
,
rejected
);
}
step
((
generator
=
generator
.
apply
(
thisArg
,
_arguments
||
[])).
next
());
});
};
var
__importDefault
=
(
this
&&
this
.
__importDefault
)
||
function
(
mod
)
{
return
(
mod
&&
mod
.
__esModule
)
?
mod
:
{
"
default
"
:
mod
};
};
Object
.
defineProperty
(
exports
,
"
__esModule
"
,
{
value
:
true
});
exports
.
createHandleHotUpdate
=
void
0
;
const
path_1
=
__importDefault
(
require
(
"
path
"
));
const
debug_1
=
__importDefault
(
require
(
"
debug
"
));
const
slash_1
=
__importDefault
(
require
(
"
slash
"
));
const
shared_1
=
require
(
"
@vue/shared
"
);
const
uni_cli_shared_1
=
require
(
"
@dcloudio/uni-cli-shared
"
);
const
utils_1
=
require
(
"
../utils
"
);
const
debugHmr
=
debug_1
.
default
(
'
vite:uni:hmr
'
);
function
invalidate
(
file
,
moduleGraph
)
{
return
__awaiter
(
this
,
void
0
,
void
0
,
function
*
()
{
const
mods
=
yield
moduleGraph
.
getModulesByFile
(
slash_1
.
default
(
file
));
if
(
mods
&&
mods
.
size
)
{
;
[...
mods
].
forEach
((
mod
)
=>
{
debugHmr
(
'
invalidate
'
,
mod
.
id
);
moduleGraph
.
invalidateModule
(
mod
);
});
}
});
}
let
invalidateFiles
;
function
createHandleHotUpdate
()
{
return
function
({
file
,
server
})
{
return
__awaiter
(
this
,
void
0
,
void
0
,
function
*
()
{
const
inputDir
=
process
.
env
.
UNI_INPUT_DIR
;
const
platform
=
process
.
env
.
UNI_PLATFORM
;
if
(
!
invalidateFiles
)
{
invalidateFiles
=
[
path_1
.
default
.
resolve
(
inputDir
,
'
pages.json.js
'
),
path_1
.
default
.
resolve
(
inputDir
,
'
manifest.json.js
'
),
require
.
resolve
(
'
@dcloudio/uni-h5/dist/uni-h5.es.js
'
),
require
.
resolve
(
'
vite/dist/client/env.js
'
),
];
}
// TODO 目前简单处理,当pages.json,manifest.json发生变化,就直接刷新,理想情况下,应该区分变化的内容,仅必要时做整页面刷新
const
isPagesJson
=
file
.
endsWith
(
'
pages.json
'
);
const
isManifestJson
=
file
.
endsWith
(
'
manifest.json
'
);
if
(
!
isPagesJson
&&
!
isManifestJson
)
{
return
;
}
debugHmr
(
file
);
server
.
ws
.
send
({
type
:
'
custom
'
,
event
:
'
invalidate
'
,
data
:
{},
});
const
pagesJson
=
uni_cli_shared_1
.
parsePagesJson
(
inputDir
,
platform
);
// 更新define
const
{
define
,
server
:
{
middlewareMode
},
}
=
server
.
config
;
shared_1
.
extend
(
define
,
utils_1
.
initFeatures
({
inputDir
,
command
:
'
serve
'
,
platform
,
pagesJson
,
manifestJson
:
uni_cli_shared_1
.
parseManifestJson
(
inputDir
),
ssr
:
!!
middlewareMode
,
}));
debugHmr
(
'
define
'
,
define
);
if
(
isPagesJson
)
{
const
easycom
=
pagesJson
.
easycom
||
{};
const
{
options
,
refresh
}
=
uni_cli_shared_1
.
initEasycomsOnce
(
inputDir
,
platform
);
if
(
!
equal
({
autoscan
:
easycom
.
autoscan
,
custom
:
easycom
.
custom
},
{
autoscan
:
options
.
autoscan
,
custom
:
options
.
custom
}))
{
refresh
();
}
}
// 当pages.json,manifest.json发生变化时,作废pages.json.js缓存
for
(
const
file
of
invalidateFiles
)
{
yield
invalidate
(
file
,
server
.
moduleGraph
);
}
return
[];
});
};
}
exports
.
createHandleHotUpdate
=
createHandleHotUpdate
;
function
equal
(
obj1
,
obj2
)
{
return
JSON
.
stringify
(
obj1
)
===
JSON
.
stringify
(
obj2
);
}
packages/uni-h5-vite/dist/index.js
浏览文件 @
3f7548b8
...
...
@@ -7,6 +7,10 @@ const mainJs_1 = require("./plugins/mainJs");
const
manifestJson_1
=
require
(
"
./plugins/manifestJson
"
);
const
pagesJson_1
=
require
(
"
./plugins/pagesJson
"
);
const
resolveId_1
=
require
(
"
./plugins/resolveId
"
);
const
setup_1
=
require
(
"
./plugins/setup
"
);
const
ssr_1
=
require
(
"
./plugins/ssr
"
);
const
utils_1
=
require
(
"
./utils
"
);
const
handleHotUpdate_1
=
require
(
"
./handleHotUpdate
"
);
function
initLogger
({
logger
,
command
})
{
if
(
command
!==
'
serve
'
)
{
return
;
...
...
@@ -27,9 +31,18 @@ const UniH5Plugin = {
tap
:
'
click
'
,
},
},
config
(
config
,
env
)
{
return
{
optimizeDeps
:
{
exclude
:
[
'
@dcloudio/uni-h5
'
,
'
@dcloudio/uni-h5-vue
'
],
},
define
:
utils_1
.
createDefine
(
env
.
command
,
config
),
};
},
configResolved
(
config
)
{
initLogger
(
config
);
},
handleHotUpdate
:
handleHotUpdate_1
.
createHandleHotUpdate
(),
};
exports
.
default
=
[
cssScoped_1
.
uniCssScopedPlugin
(),
...
...
@@ -39,5 +52,7 @@ exports.default = [
pagesJson_1
.
uniPagesJsonPlugin
(),
inject_1
.
uniInjectPlugin
(),
css_1
.
uniCssPlugin
(),
ssr_1
.
uniSSRPlugin
(),
setup_1
.
uniSetupPlugin
(),
UniH5Plugin
,
];
packages/uni-h5-vite/dist/plugins/pagesJson.js
浏览文件 @
3f7548b8
...
...
@@ -79,9 +79,6 @@ ${name}.UniViewJSBridge = UniViewJSBridge
${
name
}
.UniServiceJSBridge = UniServiceJSBridge
`
;
}
function
normalizePageIdentifier
(
path
)
{
return
shared_1
.
capitalize
(
shared_1
.
camelize
(
path
.
replace
(
/
\/
/g
,
'
-
'
)));
}
function
generateCssCode
(
config
)
{
const
define
=
config
.
define
;
const
cssFiles
=
[
uni_cli_shared_1
.
H5_FRAMEWORK_STYLE_PATH
+
'
base.css
'
];
...
...
@@ -140,7 +137,7 @@ function generateLayoutComponentsCode(globalName, pagesJson) {
};
}
function
generatePageDefineCode
(
pageOptions
)
{
const
pageIdent
=
normalizePag
eIdentifier
(
pageOptions
.
path
);
const
pageIdent
=
uni_cli_shared_1
.
normaliz
eIdentifier
(
pageOptions
.
path
);
return
`const
${
pageIdent
}
Loader = ()=>import('./
${
pageOptions
.
path
}
?mpType=page')
const
${
pageIdent
}
= defineAsyncComponent(extend({loader:
${
pageIdent
}
Loader},AsyncComponentOptions))`
;
}
...
...
@@ -160,7 +157,7 @@ function normalizePagesRoute(pagesJson) {
const
tabBarList
=
(
pagesJson
.
tabBar
&&
pagesJson
.
tabBar
.
list
)
||
[];
return
pagesJson
.
pages
.
map
((
pageOptions
)
=>
{
const
pagePath
=
pageOptions
.
path
;
const
name
=
normalizePag
eIdentifier
(
pagePath
);
const
name
=
uni_cli_shared_1
.
normaliz
eIdentifier
(
pagePath
);
const
isEntry
=
firstPagePath
===
pagePath
?
true
:
undefined
;
const
tabBarIndex
=
tabBarList
.
findIndex
((
tabBarPage
)
=>
tabBarPage
.
pagePath
===
pagePath
);
const
isTabBar
=
tabBarIndex
!==
-
1
?
true
:
undefined
;
...
...
@@ -188,7 +185,7 @@ function generatePageRoute({ name, path, meta }, config) {
return
`{
path:'/
${
isEntry
?
''
:
path
}
',
${
alias
}
component:{setup(){return ()=>renderPage(
${
name
}
)}},
loader:
${
normalizePag
eIdentifier
(
path
)}
Loader,
loader:
${
uni_cli_shared_1
.
normaliz
eIdentifier
(
path
)}
Loader,
meta:
${
JSON
.
stringify
(
meta
)}
}`
;
}
...
...
packages/uni-h5-vite/dist/plugins/setup.js
0 → 100644
浏览文件 @
3f7548b8
"
use strict
"
;
var
__importDefault
=
(
this
&&
this
.
__importDefault
)
||
function
(
mod
)
{
return
(
mod
&&
mod
.
__esModule
)
?
mod
:
{
"
default
"
:
mod
};
};
Object
.
defineProperty
(
exports
,
"
__esModule
"
,
{
value
:
true
});
exports
.
uniSetupPlugin
=
void
0
;
const
path_1
=
__importDefault
(
require
(
"
path
"
));
const
slash_1
=
__importDefault
(
require
(
"
slash
"
));
const
debug_1
=
__importDefault
(
require
(
"
debug
"
));
const
uni_cli_shared_1
=
require
(
"
@dcloudio/uni-cli-shared
"
);
const
debugSetup
=
debug_1
.
default
(
'
vite:uni:setup
'
);
function
uniSetupPlugin
()
{
let
appVuePath
;
return
{
name
:
'
vite:uni-setup
'
,
configResolved
()
{
appVuePath
=
slash_1
.
default
(
path_1
.
default
.
resolve
(
process
.
env
.
UNI_INPUT_DIR
,
'
App.vue
'
));
},
transform
(
code
,
id
)
{
const
{
filename
,
query
}
=
uni_cli_shared_1
.
parseVueRequest
(
id
);
if
(
filename
===
appVuePath
&&
!
query
.
vue
)
{
debugSetup
(
filename
);
return
(
code
+
`;import { setupApp } from '@dcloudio/uni-h5';setupApp(_sfc_main);`
);
}
if
(
query
.
mpType
===
'
page
'
)
{
debugSetup
(
filename
);
return
(
code
+
`;import { setupPage } from '@dcloudio/uni-h5';setupPage(_sfc_main);`
);
}
},
};
}
exports
.
uniSetupPlugin
=
uniSetupPlugin
;
packages/uni-h5-vite/dist/plugins/ssr.js
0 → 100644
浏览文件 @
3f7548b8
"
use strict
"
;
var
__importDefault
=
(
this
&&
this
.
__importDefault
)
||
function
(
mod
)
{
return
(
mod
&&
mod
.
__esModule
)
?
mod
:
{
"
default
"
:
mod
};
};
Object
.
defineProperty
(
exports
,
"
__esModule
"
,
{
value
:
true
});
exports
.
uniSSRPlugin
=
void
0
;
const
path_1
=
__importDefault
(
require
(
"
path
"
));
const
uni_cli_shared_1
=
require
(
"
@dcloudio/uni-cli-shared
"
);
const
utils_1
=
require
(
"
../utils
"
);
const
ENTRY_SERVER_JS
=
'
entry-server.js
'
;
function
uniSSRPlugin
()
{
let
entryServerJs
;
let
resolvedConfig
;
const
entryServerJsCode
=
utils_1
.
generateSsrEntryServerCode
();
return
{
name
:
'
vite:uni-h5-ssr
'
,
configResolved
(
config
)
{
resolvedConfig
=
config
;
entryServerJs
=
path_1
.
default
.
join
(
process
.
env
.
UNI_INPUT_DIR
,
ENTRY_SERVER_JS
);
if
(
utils_1
.
isSsr
(
resolvedConfig
.
command
,
resolvedConfig
))
{
const
{
MODE
}
=
uni_cli_shared_1
.
parseCompatConfigOnce
(
process
.
env
.
UNI_INPUT_DIR
);
utils_1
.
initSsrDefine
(
resolvedConfig
);
utils_1
.
rewriteSsrVue
(
MODE
);
utils_1
.
rewriteSsrResolve
(
MODE
);
utils_1
.
rewriteSsrNativeTag
();
utils_1
.
rewriteSsrRenderStyle
(
process
.
env
.
UNI_INPUT_DIR
);
}
},
resolveId
(
id
)
{
if
(
id
.
endsWith
(
ENTRY_SERVER_JS
))
{
return
entryServerJs
;
}
},
load
(
id
)
{
if
(
id
.
endsWith
(
ENTRY_SERVER_JS
))
{
return
entryServerJsCode
;
}
},
generateBundle
(
_options
,
bundle
)
{
const
chunk
=
bundle
[
'
entry-server.js
'
];
if
(
chunk
)
{
chunk
.
code
=
utils_1
.
generateSsrDefineCode
(
resolvedConfig
,
uni_cli_shared_1
.
parseRpx2UnitOnce
(
process
.
env
.
UNI_INPUT_DIR
))
+
'
\n
'
+
chunk
.
code
;
}
},
};
}
exports
.
uniSSRPlugin
=
uniSSRPlugin
;
packages/uni-h5-vite/dist/utils/features.js
0 → 100644
浏览文件 @
3f7548b8
"
use strict
"
;
var
__importDefault
=
(
this
&&
this
.
__importDefault
)
||
function
(
mod
)
{
return
(
mod
&&
mod
.
__esModule
)
?
mod
:
{
"
default
"
:
mod
};
};
Object
.
defineProperty
(
exports
,
"
__esModule
"
,
{
value
:
true
});
exports
.
createDefine
=
exports
.
initFeatures
=
void
0
;
const
fs_1
=
__importDefault
(
require
(
"
fs
"
));
const
path_1
=
__importDefault
(
require
(
"
path
"
));
const
shared_1
=
require
(
"
@vue/shared
"
);
const
uni_cli_shared_1
=
require
(
"
@dcloudio/uni-cli-shared
"
);
const
ssr_1
=
require
(
"
./ssr
"
);
function
initProjectFeature
({
command
})
{
const
features
=
{};
if
(
command
===
'
build
'
)
{
}
return
features
;
}
function
initPagesFeature
({
pagesJson
,
command
,
inputDir
,
ssr
,
})
{
const
features
=
{
nvue
:
true
,
pages
:
true
,
tabBar
:
true
,
tabBarMidButton
:
true
,
topWindow
:
false
,
leftWindow
:
false
,
rightWindow
:
false
,
navigationBar
:
true
,
pullDownRefresh
:
false
,
navigationBarButtons
:
true
,
navigationBarSearchInput
:
true
,
navigationBarTransparent
:
true
,
};
const
{
tabBar
,
pages
,
topWindow
,
leftWindow
,
rightWindow
,
globalStyle
}
=
pagesJson
;
// ssr 时强制启用多页面(需要用到router)
if
(
!
ssr
&&
pages
&&
pages
.
length
===
1
)
{
features
.
pages
=
false
;
}
if
(
!
(
tabBar
&&
tabBar
.
list
&&
tabBar
.
list
.
length
))
{
features
.
tabBar
=
false
;
features
.
tabBarMidButton
=
false
;
}
if
(
features
.
tabBar
&&
!
tabBar
.
midButton
)
{
features
.
tabBarMidButton
=
false
;
}
if
(
topWindow
&&
topWindow
.
path
)
{
features
.
topWindow
=
true
;
}
if
(
leftWindow
&&
leftWindow
.
path
)
{
features
.
leftWindow
=
true
;
}
if
(
rightWindow
&&
rightWindow
.
path
)
{
features
.
rightWindow
=
true
;
}
if
(
globalStyle
.
enablePullDownRefresh
)
{
features
.
pullDownRefresh
=
true
;
}
else
{
if
(
pages
.
find
((
page
)
=>
page
.
style
&&
page
.
style
.
enablePullDownRefresh
))
{
features
.
pullDownRefresh
=
true
;
}
}
if
(
command
===
'
build
'
)
{
if
(
!
pages
.
find
((
page
)
=>
fs_1
.
default
.
existsSync
(
path_1
.
default
.
resolve
(
inputDir
,
page
.
path
+
'
.nvue
'
))))
{
features
.
nvue
=
false
;
}
let
isNavigationCustom
=
false
;
if
(
globalStyle
.
navigationBar
.
style
===
'
custom
'
)
{
isNavigationCustom
=
true
;
// 全局custom
if
(
pages
.
find
((
page
)
=>
page
.
style
.
navigationBar
.
style
===
'
default
'
))
{
isNavigationCustom
=
false
;
}
}
else
{
// 所有页面均custom
if
(
pages
.
every
((
page
)
=>
page
.
style
.
navigationBar
.
style
===
'
custom
'
))
{
isNavigationCustom
=
true
;
}
}
if
(
isNavigationCustom
)
{
features
.
navigationBar
=
false
;
features
.
navigationBarButtons
=
false
;
features
.
navigationBarSearchInput
=
false
;
features
.
navigationBarTransparent
=
false
;
}
else
{
if
(
!
pages
.
find
((
page
)
=>
shared_1
.
isArray
(
page
.
style
.
navigationBar
.
buttons
)
&&
page
.
style
.
navigationBar
.
buttons
.
length
))
{
features
.
navigationBarButtons
=
false
;
}
if
(
!
globalStyle
.
navigationBar
.
searchInput
&&
!
pages
.
find
((
page
)
=>
page
.
style
.
navigationBar
.
searchInput
))
{
features
.
navigationBarSearchInput
=
false
;
}
if
(
globalStyle
.
navigationBar
.
type
!==
'
transparent
'
&&
!
pages
.
find
((
page
)
=>
page
.
style
.
navigationBar
.
type
===
'
transparent
'
))
{
features
.
navigationBarTransparent
=
false
;
}
}
}
return
features
;
}
function
initManifestFeature
({
manifestJson
,
command
,
platform
,
})
{
const
features
=
{
wx
:
false
,
wxs
:
true
,
rpx
:
true
,
promise
:
false
,
longpress
:
true
,
routerMode
:
'
"hash"
'
,
i18nEn
:
true
,
i18nEs
:
true
,
i18nFr
:
true
,
i18nZhHans
:
true
,
i18nZhHant
:
true
,
vueOptionsApi
:
true
,
vueProdDevTools
:
false
,
};
if
(
command
===
'
build
'
)
{
// TODO 需要预编译一遍?
features
.
wxs
=
false
;
features
.
longpress
=
false
;
}
if
(
manifestJson
.
h5
&&
manifestJson
.
h5
.
router
&&
manifestJson
.
h5
.
router
.
mode
===
'
history
'
)
{
features
.
routerMode
=
'
"history"
'
;
}
const
platformJson
=
manifestJson
[
platform
]
||
{};
const
manifestFeatures
=
platformJson
.
features
;
if
(
manifestFeatures
)
{
const
{
i18n
}
=
manifestFeatures
;
if
(
shared_1
.
isArray
(
i18n
))
{
if
(
!
i18n
.
includes
(
'
en
'
))
{
features
.
i18nEn
=
false
;
}
if
(
!
i18n
.
includes
(
'
es
'
))
{
features
.
i18nEs
=
false
;
}
if
(
!
i18n
.
includes
(
'
fr
'
))
{
features
.
i18nFr
=
false
;
}
if
(
!
i18n
.
includes
(
'
zh-Hans
'
))
{
features
.
i18nZhHans
=
false
;
}
if
(
!
i18n
.
includes
(
'
zh-Hant
'
))
{
features
.
i18nZhHant
=
false
;
}
}
}
// TODO other features
return
features
;
}
function
initFeatures
(
options
)
{
const
{
wx
,
wxs
,
rpx
,
nvue
,
i18nEn
,
i18nEs
,
i18nFr
,
i18nZhHans
,
i18nZhHant
,
vueOptionsApi
,
vueProdDevTools
,
pages
,
tabBar
,
tabBarMidButton
,
promise
,
longpress
,
routerMode
,
topWindow
,
leftWindow
,
rightWindow
,
navigationBar
,
pullDownRefresh
,
navigationBarButtons
,
navigationBarSearchInput
,
navigationBarTransparent
,
}
=
shared_1
.
extend
(
initManifestFeature
(
options
),
initPagesFeature
(
options
),
initProjectFeature
(
options
));
const
features
=
{
// vue
__VUE_OPTIONS_API__
:
vueOptionsApi
,
__VUE_PROD_DEVTOOLS__
:
vueProdDevTools
,
// uni
__UNI_FEATURE_WX__
:
wx
,
__UNI_FEATURE_WXS__
:
wxs
,
__UNI_FEATURE_RPX__
:
rpx
,
__UNI_FEATURE_PROMISE__
:
promise
,
__UNI_FEATURE_LONGPRESS__
:
longpress
,
__UNI_FEATURE_I18N_EN__
:
i18nEn
,
__UNI_FEATURE_I18N_ES__
:
i18nEs
,
__UNI_FEATURE_I18N_FR__
:
i18nFr
,
__UNI_FEATURE_I18N_ZH_HANS__
:
i18nZhHans
,
__UNI_FEATURE_I18N_ZH_HANT__
:
i18nZhHant
,
// 以下特性,编译器已自动识别是否需要启用
__UNI_FEATURE_NVUE__
:
nvue
,
__UNI_FEATURE_ROUTER_MODE__
:
routerMode
,
__UNI_FEATURE_PAGES__
:
pages
,
__UNI_FEATURE_TABBAR__
:
tabBar
,
__UNI_FEATURE_TABBAR_MIDBUTTON__
:
tabBarMidButton
,
__UNI_FEATURE_TOPWINDOW__
:
topWindow
,
__UNI_FEATURE_LEFTWINDOW__
:
leftWindow
,
__UNI_FEATURE_RIGHTWINDOW__
:
rightWindow
,
__UNI_FEATURE_RESPONSIVE__
:
topWindow
||
leftWindow
||
rightWindow
,
__UNI_FEATURE_NAVIGATIONBAR__
:
navigationBar
,
__UNI_FEATURE_PULL_DOWN_REFRESH__
:
pullDownRefresh
,
__UNI_FEATURE_NAVIGATIONBAR_BUTTONS__
:
navigationBarButtons
,
__UNI_FEATURE_NAVIGATIONBAR_SEARCHINPUT__
:
navigationBarSearchInput
,
__UNI_FEATURE_NAVIGATIONBAR_TRANSPARENT__
:
navigationBarTransparent
,
};
// ssr nodejs features
if
(
options
.
ssr
)
{
Object
.
keys
(
features
).
forEach
((
name
)
=>
{
const
value
=
features
[
name
];
shared_1
.
extend
(
globalThis
,
{
[
name
]:
shared_1
.
isString
(
value
)
?
JSON
.
parse
(
value
)
:
value
,
});
});
}
return
features
;
}
exports
.
initFeatures
=
initFeatures
;
function
createDefine
(
command
,
config
)
{
const
platform
=
process
.
env
.
UNI_PLATFORM
;
const
inputDir
=
process
.
env
.
UNI_INPUT_DIR
;
return
initFeatures
({
inputDir
,
command
,
platform
,
pagesJson
:
uni_cli_shared_1
.
parsePagesJsonOnce
(
inputDir
,
platform
),
manifestJson
:
uni_cli_shared_1
.
parseManifestJsonOnce
(
inputDir
),
ssr
:
ssr_1
.
isSsr
(
command
,
config
)
||
ssr_1
.
isSsrManifest
(
command
,
config
),
});
}
exports
.
createDefine
=
createDefine
;
packages/uni-h5-vite/dist/utils/index.js
浏览文件 @
3f7548b8
...
...
@@ -11,3 +11,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
};
Object
.
defineProperty
(
exports
,
"
__esModule
"
,
{
value
:
true
});
__exportStar
(
require
(
"
./ssr
"
),
exports
);
__exportStar
(
require
(
"
./features
"
),
exports
);
packages/
vite-plugin-uni
/lib/ssr/define.js
→
packages/
uni-h5-vite
/lib/ssr/define.js
浏览文件 @
3f7548b8
文件已移动
packages/
vite-plugin-uni
/lib/ssr/entry-server.js
→
packages/
uni-h5-vite
/lib/ssr/entry-server.js
浏览文件 @
3f7548b8
文件已移动
packages/uni-h5-vite/package.json
浏览文件 @
3f7548b8
...
...
@@ -6,7 +6,8 @@
"types"
:
"dist/index.d.ts"
,
"files"
:
[
"dist/**/*.js"
,
"dist/**/*.d.ts"
"dist/**/*.d.ts"
,
"lib"
],
"repository"
:
{
"type"
:
"git"
,
...
...
packages/
vite-plugin-uni
/src/handleHotUpdate/index.ts
→
packages/
uni-h5-vite
/src/handleHotUpdate/index.ts
浏览文件 @
3f7548b8
...
...
@@ -3,10 +3,13 @@ import debug from 'debug'
import
slash
from
'
slash
'
import
{
ModuleGraph
,
Plugin
}
from
'
vite
'
import
{
extend
}
from
'
@vue/shared
'
import
{
parseManifestJson
,
parsePagesJson
}
from
'
@dcloudio/uni-cli-shared
'
import
{
initEasycomsOnce
,
parseManifestJson
,
parsePagesJson
,
}
from
'
@dcloudio/uni-cli-shared
'
import
{
VitePluginUniResolvedOptions
}
from
'
..
'
import
{
initEasycomsOnce
,
initFeatures
}
from
'
../utils
'
import
{
initFeatures
}
from
'
../utils
'
const
debugHmr
=
debug
(
'
vite:uni:hmr
'
)
...
...
@@ -20,14 +23,14 @@ async function invalidate(file: string, moduleGraph: ModuleGraph) {
}
}
let
invalidateFiles
:
string
[]
export
function
createHandleHotUpdate
(
options
:
VitePluginUniResolvedOptions
):
Plugin
[
'
handleHotUpdate
'
]
{
export
function
createHandleHotUpdate
():
Plugin
[
'
handleHotUpdate
'
]
{
return
async
function
({
file
,
server
})
{
const
inputDir
=
process
.
env
.
UNI_INPUT_DIR
const
platform
=
process
.
env
.
UNI_PLATFORM
if
(
!
invalidateFiles
)
{
invalidateFiles
=
[
path
.
resolve
(
options
.
inputDir
,
'
pages.json.js
'
),
path
.
resolve
(
options
.
inputDir
,
'
manifest.json.js
'
),
path
.
resolve
(
inputDir
,
'
pages.json.js
'
),
path
.
resolve
(
inputDir
,
'
manifest.json.js
'
),
require
.
resolve
(
'
@dcloudio/uni-h5/dist/uni-h5.es.js
'
),
require
.
resolve
(
'
vite/dist/client/env.js
'
),
]
...
...
@@ -44,7 +47,6 @@ export function createHandleHotUpdate(
event
:
'
invalidate
'
,
data
:
{},
})
const
{
inputDir
,
command
,
platform
}
=
options
const
pagesJson
=
parsePagesJson
(
inputDir
,
platform
)
// 更新define
const
{
...
...
@@ -55,7 +57,7 @@ export function createHandleHotUpdate(
define
,
initFeatures
({
inputDir
,
command
,
command
:
'
serve
'
,
platform
,
pagesJson
,
manifestJson
:
parseManifestJson
(
inputDir
),
...
...
packages/uni-h5-vite/src/index.ts
浏览文件 @
3f7548b8
...
...
@@ -7,6 +7,11 @@ import { uniMainJsPlugin } from './plugins/mainJs'
import
{
uniManifestJsonPlugin
}
from
'
./plugins/manifestJson
'
import
{
uniPagesJsonPlugin
}
from
'
./plugins/pagesJson
'
import
{
uniResolveIdPlugin
}
from
'
./plugins/resolveId
'
import
{
uniSetupPlugin
}
from
'
./plugins/setup
'
import
{
uniSSRPlugin
}
from
'
./plugins/ssr
'
import
{
createDefine
}
from
'
./utils
'
import
{
createHandleHotUpdate
}
from
'
./handleHotUpdate
'
function
initLogger
({
logger
,
command
}:
ResolvedConfig
)
{
if
(
command
!==
'
serve
'
)
{
...
...
@@ -29,9 +34,18 @@ const UniH5Plugin: UniVitePlugin = {
tap
:
'
click
'
,
},
},
config
(
config
,
env
)
{
return
{
optimizeDeps
:
{
exclude
:
[
'
@dcloudio/uni-h5
'
,
'
@dcloudio/uni-h5-vue
'
],
},
define
:
createDefine
(
env
.
command
,
config
),
}
},
configResolved
(
config
)
{
initLogger
(
config
)
},
handleHotUpdate
:
createHandleHotUpdate
(),
}
export
default
[
...
...
@@ -42,5 +56,7 @@ export default [
uniPagesJsonPlugin
(),
uniInjectPlugin
(),
uniCssPlugin
(),
uniSSRPlugin
(),
uniSetupPlugin
(),
UniH5Plugin
,
]
packages/uni-h5-vite/src/plugins/pagesJson.ts
浏览文件 @
3f7548b8
...
...
@@ -2,12 +2,13 @@ import fs from 'fs'
import
path
from
'
path
'
import
slash
from
'
slash
'
import
{
Plugin
,
ResolvedConfig
}
from
'
vite
'
import
{
extend
,
camelize
,
capitalize
}
from
'
@vue/shared
'
import
{
extend
}
from
'
@vue/shared
'
import
{
API_DEPS_CSS
,
FEATURE_DEFINES
,
H5_FRAMEWORK_STYLE_PATH
,
BASE_COMPONENTS_STYLE_PATH
,
normalizeIdentifier
,
normalizePagesJson
,
defineUniPagesJsonPlugin
,
}
from
'
@dcloudio/uni-cli-shared
'
...
...
@@ -107,10 +108,6 @@ ${name}.UniServiceJSBridge = UniServiceJSBridge
`
}
function
normalizePageIdentifier
(
path
:
string
)
{
return
capitalize
(
camelize
(
path
.
replace
(
/
\/
/g
,
'
-
'
)))
}
function
generateCssCode
(
config
:
ResolvedConfig
)
{
const
define
=
config
.
define
!
as
FEATURE_DEFINES
const
cssFiles
=
[
H5_FRAMEWORK_STYLE_PATH
+
'
base.css
'
]
...
...
@@ -175,7 +172,7 @@ function generateLayoutComponentsCode(
}
function
generatePageDefineCode
(
pageOptions
:
UniApp
.
PagesJsonPageOptions
)
{
const
pageIdent
=
normalize
Page
Identifier
(
pageOptions
.
path
)
const
pageIdent
=
normalizeIdentifier
(
pageOptions
.
path
)
return
`const
${
pageIdent
}
Loader = ()=>import('./
${
pageOptions
.
path
}
?mpType=page')
const
${
pageIdent
}
= defineAsyncComponent(extend({loader:
${
pageIdent
}
Loader},AsyncComponentOptions))`
}
...
...
@@ -202,7 +199,7 @@ function normalizePagesRoute(pagesJson: UniApp.PagesJson): PageRouteOptions[] {
const
tabBarList
=
(
pagesJson
.
tabBar
&&
pagesJson
.
tabBar
.
list
)
||
[]
return
pagesJson
.
pages
.
map
((
pageOptions
)
=>
{
const
pagePath
=
pageOptions
.
path
const
name
=
normalize
Page
Identifier
(
pagePath
)
const
name
=
normalizeIdentifier
(
pagePath
)
const
isEntry
=
firstPagePath
===
pagePath
?
true
:
undefined
const
tabBarIndex
=
tabBarList
.
findIndex
(
(
tabBarPage
:
{
pagePath
:
string
})
=>
tabBarPage
.
pagePath
===
pagePath
...
...
@@ -241,7 +238,7 @@ function generatePageRoute(
return
`{
path:'/
${
isEntry
?
''
:
path
}
',
${
alias
}
component:{setup(){return ()=>renderPage(
${
name
}
)}},
loader:
${
normalize
Page
Identifier
(
path
)}
Loader,
loader:
${
normalizeIdentifier
(
path
)}
Loader,
meta:
${
JSON
.
stringify
(
meta
)}
}`
}
...
...
packages/
vite-plugin-uni/src/configResolved/plugins/pageVue
.ts
→
packages/
uni-h5-vite/src/plugins/setup
.ts
浏览文件 @
3f7548b8
import
fs
from
'
fs
'
import
path
from
'
path
'
import
slash
from
'
slash
'
import
debug
from
'
debug
'
import
{
Plugin
}
from
'
vite
'
import
{
parseVueRequest
}
from
'
@dcloudio/uni-cli-shared
'
import
{
VitePluginUniResolvedOptions
}
from
'
../..
'
const
debug
PageVue
=
debug
(
'
vite:uni:page-vue
'
)
const
debug
Setup
=
debug
(
'
vite:uni:setup
'
)
export
function
uniPageVuePlugin
(
options
:
VitePluginUniResolvedOptions
):
Plugin
{
const
appVuePath
=
slash
(
path
.
resolve
(
options
.
inputDir
,
'
App.vue
'
))
export
function
uniSetupPlugin
():
Plugin
{
let
appVuePath
:
string
return
{
name
:
'
vite:uni-page-vue
'
,
load
(
id
)
{
if
(
options
.
command
===
'
build
'
)
{
const
{
filename
,
query
}
=
parseVueRequest
(
id
)
if
(
query
.
mpType
===
'
page
'
)
{
return
fs
.
readFileSync
(
filename
,
'
utf8
'
)
}
}
name
:
'
vite:uni-setup
'
,
configResolved
()
{
appVuePath
=
slash
(
path
.
resolve
(
process
.
env
.
UNI_INPUT_DIR
,
'
App.vue
'
))
},
transform
(
code
,
id
)
{
const
{
filename
,
query
}
=
parseVueRequest
(
id
)
if
(
filename
===
appVuePath
&&
!
query
.
vue
)
{
debug
PageVue
(
filename
)
debug
Setup
(
filename
)
return
(
code
+
`;import {
setupApp
} from '@dcloudio/uni-h5';setupApp(_sfc_main);`
`;import {
setupApp
} from '@dcloudio/uni-h5';setupApp(_sfc_main);`
)
}
if
(
query
.
mpType
===
'
page
'
)
{
debug
PageVue
(
filename
)
debug
Setup
(
filename
)
return
(
code
+
`;import {
setupPage
} from '@dcloudio/uni-h5';setupPage(_sfc_main);`
`;import {
setupPage
} from '@dcloudio/uni-h5';setupPage(_sfc_main);`
)
}
},
...
...
packages/uni-h5-vite/src/plugins/ssr.ts
0 → 100644
浏览文件 @
3f7548b8
import
path
from
'
path
'
import
{
Plugin
,
ResolvedConfig
}
from
'
vite
'
import
{
OutputChunk
}
from
'
rollup
'
import
{
parseCompatConfigOnce
,
parseRpx2UnitOnce
,
}
from
'
@dcloudio/uni-cli-shared
'
import
{
isSsr
,
initSsrDefine
,
rewriteSsrVue
,
rewriteSsrResolve
,
rewriteSsrNativeTag
,
rewriteSsrRenderStyle
,
generateSsrDefineCode
,
generateSsrEntryServerCode
,
}
from
'
../utils
'
const
ENTRY_SERVER_JS
=
'
entry-server.js
'
export
function
uniSSRPlugin
():
Plugin
{
let
entryServerJs
:
string
let
resolvedConfig
:
ResolvedConfig
const
entryServerJsCode
=
generateSsrEntryServerCode
()
return
{
name
:
'
vite:uni-h5-ssr
'
,
configResolved
(
config
:
ResolvedConfig
)
{
resolvedConfig
=
config
entryServerJs
=
path
.
join
(
process
.
env
.
UNI_INPUT_DIR
,
ENTRY_SERVER_JS
)
if
(
isSsr
(
resolvedConfig
.
command
,
resolvedConfig
))
{
const
{
MODE
}
=
parseCompatConfigOnce
(
process
.
env
.
UNI_INPUT_DIR
)
initSsrDefine
(
resolvedConfig
)
rewriteSsrVue
(
MODE
)
rewriteSsrResolve
(
MODE
)
rewriteSsrNativeTag
()
rewriteSsrRenderStyle
(
process
.
env
.
UNI_INPUT_DIR
)
}
},
resolveId
(
id
)
{
if
(
id
.
endsWith
(
ENTRY_SERVER_JS
))
{
return
entryServerJs
}
},
load
(
id
)
{
if
(
id
.
endsWith
(
ENTRY_SERVER_JS
))
{
return
entryServerJsCode
}
},
generateBundle
(
_options
,
bundle
)
{
const
chunk
=
bundle
[
'
entry-server.js
'
]
as
OutputChunk
if
(
chunk
)
{
chunk
.
code
=
generateSsrDefineCode
(
resolvedConfig
,
parseRpx2UnitOnce
(
process
.
env
.
UNI_INPUT_DIR
)
)
+
'
\n
'
+
chunk
.
code
}
},
}
}
packages/
vite-plugin-uni
/src/utils/features.ts
→
packages/
uni-h5-vite
/src/utils/features.ts
浏览文件 @
3f7548b8
import
fs
from
'
fs
'
import
path
from
'
path
'
import
{
ConfigEnv
}
from
'
vite
'
import
{
ConfigEnv
,
UserConfig
}
from
'
vite
'
import
{
extend
,
isArray
,
isString
}
from
'
@vue/shared
'
import
{
parsePagesJsonOnce
,
parseManifestJsonOnce
,
}
from
'
@dcloudio/uni-cli-shared
'
import
{
isSsr
,
isSsrManifest
}
from
'
./ssr
'
interface
ProjectFeatures
{}
interface
PagesFeatures
{
...
...
@@ -287,3 +292,19 @@ export function initFeatures(options: InitFeaturesOptions) {
}
return
features
}
export
function
createDefine
(
command
:
ConfigEnv
[
'
command
'
],
config
:
UserConfig
):
UserConfig
[
'
define
'
]
{
const
platform
=
process
.
env
.
UNI_PLATFORM
const
inputDir
=
process
.
env
.
UNI_INPUT_DIR
return
initFeatures
({
inputDir
,
command
,
platform
,
pagesJson
:
parsePagesJsonOnce
(
inputDir
,
platform
),
manifestJson
:
parseManifestJsonOnce
(
inputDir
),
ssr
:
isSsr
(
command
,
config
)
||
isSsrManifest
(
command
,
config
),
})
}
packages/uni-h5-vite/src/utils/index.ts
浏览文件 @
3f7548b8
export
*
from
'
./ssr
'
export
*
from
'
./features
'
packages/uni-h5/dist/uni-h5.cjs.js
浏览文件 @
3f7548b8
...
...
@@ -1246,7 +1246,7 @@ function invokeSuccess(id, name, res) {
return
invokeCallback
(
id
,
shared
.
extend
(
res
||
{},
{
errMsg
:
name
+
"
:ok
"
}));
}
function
invokeFail
(
id
,
name
,
errMsg
,
errRes
)
{
return
invokeCallback
(
id
,
Object
.
assign
({
errMsg
:
name
+
"
:fail
"
+
(
errMsg
?
"
"
+
errMsg
:
""
)
},
errRes
));
return
invokeCallback
(
id
,
shared
.
extend
({
errMsg
:
name
+
"
:fail
"
+
(
errMsg
?
"
"
+
errMsg
:
""
)
},
errRes
));
}
function
beforeInvokeApi
(
name
,
args
,
protocol
,
options
)
{
if
(
process
.
env
.
NODE_ENV
!==
"
production
"
)
{
...
...
packages/uni-h5/dist/uni-h5.es.js
浏览文件 @
3f7548b8
...
...
@@ -694,7 +694,7 @@ var safeAreaInsets = {
onChange,
offChange
};
var
D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_
out = safeAreaInsets;
var out = safeAreaInsets;
const onEventPrevent = /* @__PURE__ */ withModifiers(() => {
}, ["prevent"]);
const onEventStop = /* @__PURE__ */ withModifiers(() => {
...
...
@@ -706,10 +706,10 @@ function getWindowOffset() {
const left = parseInt(style.getPropertyValue("--window-left"));
const right = parseInt(style.getPropertyValue("--window-right"));
return {
top: top ? top +
D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_
out.top : 0,
bottom: bottom ? bottom +
D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_
out.bottom : 0,
left: left ? left +
D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_
out.left : 0,
right: right ? right +
D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_
out.right : 0
top: top ? top + out.top : 0,
bottom: bottom ? bottom + out.bottom : 0,
left: left ? left + out.left : 0,
right: right ? right + out.right : 0
};
}
function updateCssVar(cssVars) {
...
...
@@ -2351,7 +2351,7 @@ function invokeSuccess(id2, name, res) {
return invokeCallback(id2, extend(res || {}, { errMsg: name + ":ok" }));
}
function invokeFail(id2, name, errMsg, errRes) {
return invokeCallback(id2,
Object.assign
({ errMsg: name + ":fail" + (errMsg ? " " + errMsg : "") }, errRes));
return invokeCallback(id2,
extend
({ errMsg: name + ":fail" + (errMsg ? " " + errMsg : "") }, errRes));
}
function beforeInvokeApi(name, args, protocol, options) {
if (process.env.NODE_ENV !== "production") {
...
...
@@ -4858,7 +4858,8 @@ const API_SHOW_TOAST = "showToast";
const SHOW_TOAST_ICON = [
"success",
"loading",
"none"
"none",
"error"
];
const ShowToastProtocol = {
title: String,
...
...
@@ -13014,7 +13015,7 @@ function normalizePageMeta(pageMeta) {
let offset = rpx2px(refreshOptions.offset);
const { type } = navigationBar;
if (type !== "transparent" && type !== "none") {
offset += NAVBAR_HEIGHT +
D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_
out.top;
offset += NAVBAR_HEIGHT + out.top;
}
refreshOptions.offset = offset;
refreshOptions.height = rpx2px(refreshOptions.height);
...
...
@@ -15207,7 +15208,7 @@ const getSystemInfoSync = /* @__PURE__ */ defineSyncApi("getSystemInfoSync", ()
const windowWidth = getWindowWidth(screenWidth);
let windowHeight = window.innerHeight;
const language = navigator.language;
const statusBarHeight =
D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_
out.top;
const statusBarHeight = out.top;
let osname;
let osversion;
let model;
...
...
@@ -15320,12 +15321,12 @@ const getSystemInfoSync = /* @__PURE__ */ defineSyncApi("getSystemInfoSync", ()
const system = `${osname} ${osversion}`;
const platform = osname.toLocaleLowerCase();
const safeArea = {
left:
D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_
out.left,
right: windowWidth -
D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_
out.right,
top:
D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_
out.top,
bottom: windowHeight -
D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_
out.bottom,
width: windowWidth -
D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_out.left - D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_
out.right,
height: windowHeight -
D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_out.top - D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_
out.bottom
left: out.left,
right: windowWidth - out.right,
top: out.top,
bottom: windowHeight - out.bottom,
width: windowWidth -
out.left -
out.right,
height: windowHeight -
out.top -
out.bottom
};
const { top: windowTop, bottom: windowBottom } = getWindowOffset();
windowHeight -= windowTop;
...
...
@@ -15345,10 +15346,10 @@ const getSystemInfoSync = /* @__PURE__ */ defineSyncApi("getSystemInfoSync", ()
model,
safeArea,
safeAreaInsets: {
top:
D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_
out.top,
right:
D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_
out.right,
bottom:
D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_
out.bottom,
left:
D__DCloud_local_git_uniAppNext_node_modules_safeAreaInsets_
out.left
top: out.top,
right: out.right,
bottom: out.bottom,
left: out.left
}
};
});
...
...
@@ -17445,11 +17446,24 @@ var Toast = /* @__PURE__ */ defineComponent({
}
});
function useToastIcon(props2) {
const Icon = computed(() => props2.icon === "success" ? createVNode(createSvgIconVNode(ICON_PATH_SUCCESS_NO_CIRCLE, "#fff", 38), {
class: ToastIconClassName
}) : props2.icon === "loading" ? createVNode("i", {
"class": [ToastIconClassName, "uni-loading"]
}, null, 2) : null);
const Icon = computed(() => {
switch (props2.icon) {
case "success":
return createVNode(createSvgIconVNode(ICON_PATH_SUCCESS_NO_CIRCLE, "#fff", 38), {
class: ToastIconClassName
});
case "error":
return createVNode(createSvgIconVNode(ICON_PATH_WARN, "#fff", 38), {
class: ToastIconClassName
});
case "loading":
return createVNode("i", {
"class": [ToastIconClassName, "uni-loading"]
}, null, 2);
default:
return null;
}
});
return {
Icon
};
...
...
packages/uni-shared/dist/uni-shared.cjs.js
浏览文件 @
3f7548b8
...
...
@@ -212,6 +212,12 @@ function isCustomElement(tag) {
function
isNativeTag
(
tag
)
{
return
(
shared
.
isHTMLTag
(
tag
)
||
shared
.
isSVGTag
(
tag
))
&&
!
isBuiltInComponent
(
tag
);
}
function
isServiceNativeTag
(
tag
)
{
return
shared
.
isHTMLTag
(
tag
)
||
shared
.
isSVGTag
(
tag
)
||
isBuiltInComponent
(
tag
);
}
function
isServiceCustomElement
(
_tag
)
{
return
false
;
}
const
COMPONENT_SELECTOR_PREFIX
=
'
uni-
'
;
const
COMPONENT_PREFIX
=
'
v-
'
+
COMPONENT_SELECTOR_PREFIX
;
...
...
@@ -927,6 +933,8 @@ exports.invokeArrayFns = invokeArrayFns;
exports
.
isBuiltInComponent
=
isBuiltInComponent
;
exports
.
isCustomElement
=
isCustomElement
;
exports
.
isNativeTag
=
isNativeTag
;
exports
.
isServiceCustomElement
=
isServiceCustomElement
;
exports
.
isServiceNativeTag
=
isServiceNativeTag
;
exports
.
normalizeDataset
=
normalizeDataset
;
exports
.
normalizeTarget
=
normalizeTarget
;
exports
.
once
=
once
;
...
...
packages/uni-shared/dist/uni-shared.d.ts
浏览文件 @
3f7548b8
...
...
@@ -78,6 +78,10 @@ export declare function isCustomElement(tag: string): boolean;
export
declare
function
isNativeTag
(
tag
:
string
):
boolean
;
export
declare
function
isServiceCustomElement
(
_tag
:
string
):
boolean
;
export
declare
function
isServiceNativeTag
(
tag
:
string
):
boolean
;
export
declare
interface
IUniPageNode
{
pageId
:
number
;
pageNode
:
IUniPageNode
|
null
;
...
...
packages/uni-shared/dist/uni-shared.es.js
浏览文件 @
3f7548b8
...
...
@@ -208,6 +208,12 @@ function isCustomElement(tag) {
function
isNativeTag
(
tag
)
{
return
(
isHTMLTag
(
tag
)
||
isSVGTag
(
tag
))
&&
!
isBuiltInComponent
(
tag
);
}
function
isServiceNativeTag
(
tag
)
{
return
isHTMLTag
(
tag
)
||
isSVGTag
(
tag
)
||
isBuiltInComponent
(
tag
);
}
function
isServiceCustomElement
(
_tag
)
{
return
false
;
}
const
COMPONENT_SELECTOR_PREFIX
=
'
uni-
'
;
const
COMPONENT_PREFIX
=
'
v-
'
+
COMPONENT_SELECTOR_PREFIX
;
...
...
@@ -871,4 +877,4 @@ function getEnvLocale() {
return
(
lang
&&
lang
.
replace
(
/
[
.:
]
.*/
,
''
))
||
'
en
'
;
}
export
{
BUILT_IN_TAGS
,
COMPONENT_NAME_PREFIX
,
COMPONENT_PREFIX
,
COMPONENT_SELECTOR_PREFIX
,
DATA_RE
,
NAVBAR_HEIGHT
,
NODE_TYPE_COMMENT
,
NODE_TYPE_ELEMENT
,
NODE_TYPE_PAGE
,
NODE_TYPE_TEXT
,
ON_REACH_BOTTOM_DISTANCE
,
PLUS_RE
,
PRIMARY_COLOR
,
RESPONSIVE_MIN_WIDTH
,
SCHEME_RE
,
TABBAR_HEIGHT
,
TAGS
,
UNI_SSR
,
UNI_SSR_DATA
,
UNI_SSR_GLOBAL_DATA
,
UNI_SSR_STORE
,
UNI_SSR_TITLE
,
UniBaseNode
,
UniCommentNode
,
UniElement
,
UniEvent
,
UniInputElement
,
UniNode
,
UniTextAreaElement
,
UniTextNode
,
WEB_INVOKE_APPSERVICE
,
addFont
,
cacheStringFunction
,
callOptions
,
createRpx2Unit
,
debounce
,
decode
,
decodeAttr
,
decodeTag
,
decodedQuery
,
defaultRpx2Unit
,
encodeAttr
,
encodeTag
,
formatDateTime
,
getCustomDataset
,
getEnvLocale
,
getLen
,
initCustomDataset
,
invokeArrayFns
,
isBuiltInComponent
,
isCustomElement
,
isNativeTag
,
normalizeDataset
,
normalizeTarget
,
once
,
parseQuery
,
passive
,
plusReady
,
removeLeadingSlash
,
sanitise
,
scrollTo
,
stringifyQuery
,
updateElementStyle
};
export
{
BUILT_IN_TAGS
,
COMPONENT_NAME_PREFIX
,
COMPONENT_PREFIX
,
COMPONENT_SELECTOR_PREFIX
,
DATA_RE
,
NAVBAR_HEIGHT
,
NODE_TYPE_COMMENT
,
NODE_TYPE_ELEMENT
,
NODE_TYPE_PAGE
,
NODE_TYPE_TEXT
,
ON_REACH_BOTTOM_DISTANCE
,
PLUS_RE
,
PRIMARY_COLOR
,
RESPONSIVE_MIN_WIDTH
,
SCHEME_RE
,
TABBAR_HEIGHT
,
TAGS
,
UNI_SSR
,
UNI_SSR_DATA
,
UNI_SSR_GLOBAL_DATA
,
UNI_SSR_STORE
,
UNI_SSR_TITLE
,
UniBaseNode
,
UniCommentNode
,
UniElement
,
UniEvent
,
UniInputElement
,
UniNode
,
UniTextAreaElement
,
UniTextNode
,
WEB_INVOKE_APPSERVICE
,
addFont
,
cacheStringFunction
,
callOptions
,
createRpx2Unit
,
debounce
,
decode
,
decodeAttr
,
decodeTag
,
decodedQuery
,
defaultRpx2Unit
,
encodeAttr
,
encodeTag
,
formatDateTime
,
getCustomDataset
,
getEnvLocale
,
getLen
,
initCustomDataset
,
invokeArrayFns
,
isBuiltInComponent
,
isCustomElement
,
isNativeTag
,
isServiceCustomElement
,
isServiceNativeTag
,
normalizeDataset
,
normalizeTarget
,
once
,
parseQuery
,
passive
,
plusReady
,
removeLeadingSlash
,
sanitise
,
scrollTo
,
stringifyQuery
,
updateElementStyle
};
packages/uni-shared/src/tags.ts
浏览文件 @
3f7548b8
...
...
@@ -77,6 +77,14 @@ export function isNativeTag(tag: string) {
return
(
isHTMLTag
(
tag
)
||
isSVGTag
(
tag
))
&&
!
isBuiltInComponent
(
tag
)
}
export
function
isServiceNativeTag
(
tag
:
string
)
{
return
isHTMLTag
(
tag
)
||
isSVGTag
(
tag
)
||
isBuiltInComponent
(
tag
)
}
export
function
isServiceCustomElement
(
_tag
:
string
)
{
return
false
}
export
const
COMPONENT_SELECTOR_PREFIX
=
'
uni-
'
export
const
COMPONENT_PREFIX
=
'
v-
'
+
COMPONENT_SELECTOR_PREFIX
packages/vite-plugin-uni/package.json
浏览文件 @
3f7548b8
...
...
@@ -9,8 +9,7 @@
"types"
:
"dist/index.d.ts"
,
"files"
:
[
"dist/**/*.js"
,
"dist/**/*.d.ts"
,
"lib"
"dist/**/*.d.ts"
],
"repository"
:
{
"type"
:
"git"
,
...
...
packages/vite-plugin-uni/src/config/build.ts
浏览文件 @
3f7548b8
import
path
from
'
path
'
import
slash
from
'
slash
'
import
{
UserConfig
}
from
'
vite
'
import
{
initEasycomsOnce
}
from
'
@dcloudio/uni-cli-shared
'
import
{
VitePluginUniResolvedOptions
}
from
'
..
'
import
{
initEasycomsOnce
}
from
'
../utils
'
export
function
createBuild
(
options
:
VitePluginUniResolvedOptions
...
...
packages/vite-plugin-uni/src/config/define.ts
浏览文件 @
3f7548b8
import
{
extend
}
from
'
@vue/shared
'
import
{
ConfigEnv
,
UserConfig
}
from
'
vite
'
import
{
UserConfig
}
from
'
vite
'
import
{
VitePluginUniResolvedOptions
}
from
'
..
'
import
{
parsePagesJsonOnce
,
parseManifestJsonOnce
,
}
from
'
@dcloudio/uni-cli-shared
'
import
{
initFeatures
,
isSsr
,
isSsrManifest
}
from
'
../utils
'
export
function
createDefine
(
{
inputDir
,
platform
}:
VitePluginUniResolvedOptions
,
config
:
UserConfig
,
{
command
}:
ConfigEnv
):
UserConfig
[
'
define
'
]
{
return
extend
(
{
'
process.env.UNI_PLATFORM
'
:
JSON
.
stringify
(
platform
)
},
initFeatures
({
inputDir
,
command
,
platform
,
pagesJson
:
parsePagesJsonOnce
(
inputDir
,
platform
),
manifestJson
:
parseManifestJsonOnce
(
inputDir
),
ssr
:
isSsr
(
command
,
config
)
||
isSsrManifest
(
command
,
config
),
})
)
export
function
createDefine
({
platform
,
}:
VitePluginUniResolvedOptions
):
UserConfig
[
'
define
'
]
{
return
{
'
process.env.UNI_PLATFORM
'
:
JSON
.
stringify
(
platform
),
}
}
packages/vite-plugin-uni/src/config/index.ts
浏览文件 @
3f7548b8
...
...
@@ -45,12 +45,10 @@ export function createConfig(
options
.
vueJsxOptions
=
initPluginVueJsxOptions
(
options
)
options
.
viteLegacyOptions
=
initPluginViteLegacyOptions
(
options
)
const
define
=
createDefine
(
options
,
config
,
env
)
return
{
base
,
publicDir
:
config
.
publicDir
||
false
,
define
,
define
:
createDefine
(
options
)
,
resolve
:
createResolve
(
options
,
config
),
optimizeDeps
:
createOptimizeDeps
(
options
),
server
:
createServer
(
options
),
...
...
packages/vite-plugin-uni/src/config/optimizeDeps.ts
浏览文件 @
3f7548b8
...
...
@@ -11,8 +11,6 @@ export function createOptimizeDeps(
'
vue-router
'
,
'
@dcloudio/uni-app
'
,
'
@dcloudio/uni-components
'
,
'
@dcloudio/uni-h5
'
,
'
@dcloudio/uni-h5-vue
'
,
'
@dcloudio/uni-i18n
'
,
'
@dcloudio/uni-shared
'
,
],
...
...
packages/vite-plugin-uni/src/configResolved/config.ts
已删除
100644 → 0
浏览文件 @
d9cedce2
import
{
ResolvedConfig
}
from
'
vite
'
import
{
parseCompatConfigOnce
}
from
'
../../../uni-cli-shared/dist
'
import
{
isSsr
,
initSsrDefine
,
rewriteSsrVue
,
rewriteSsrResolve
,
rewriteSsrNativeTag
,
rewriteSsrRenderStyle
,
}
from
'
../utils
'
// import alias from 'module-alias'
export
function
initConfig
(
config
:
ResolvedConfig
)
{
if
(
isSsr
(
config
.
command
,
config
))
{
const
{
MODE
}
=
parseCompatConfigOnce
(
process
.
env
.
UNI_INPUT_DIR
)
initSsrDefine
(
config
)
rewriteSsrVue
(
MODE
)
rewriteSsrResolve
(
MODE
)
rewriteSsrNativeTag
()
rewriteSsrRenderStyle
(
process
.
env
.
UNI_INPUT_DIR
)
}
// let ssr = (config as any).ssr as SSROptions
// if (!ssr) {
// ssr = {}
// }
// if (ssr.external) {
// const index = ssr.external.findIndex((name) => name === 'vue')
// if (index !== -1) {
// ssr.external.splice(index, 1)
// }
// }
// if (!ssr.noExternal) {
// ssr.noExternal = ['vue']
// } else if (!ssr.noExternal.includes('vue')) {
// ssr.noExternal.push('vue')
// }
}
packages/vite-plugin-uni/src/configResolved/index.ts
浏览文件 @
3f7548b8
...
...
@@ -3,14 +3,12 @@ import { Plugin } from 'vite'
import
{
VitePluginUniResolvedOptions
}
from
'
..
'
import
{
initEnv
}
from
'
./env
'
import
{
initConfig
}
from
'
./config
'
import
{
initOptions
}
from
'
./options
'
import
{
initPlugins
}
from
'
./plugins
'
export
function
createConfigResolved
(
options
:
VitePluginUniResolvedOptions
)
{
return
((
config
)
=>
{
initEnv
(
config
)
initConfig
(
config
)
initOptions
(
options
,
config
)
initPlugins
(
config
,
options
)
})
as
Plugin
[
'
configResolved
'
]
...
...
packages/vite-plugin-uni/src/configResolved/plugins/easycom.ts
浏览文件 @
3f7548b8
...
...
@@ -12,10 +12,10 @@ import {
parseVueRequest
,
buildInCssSet
,
isCombineBuiltInCss
,
matchEasycom
,
}
from
'
@dcloudio/uni-cli-shared
'
import
{
UniPluginFilterOptions
}
from
'
.
'
import
{
debugEasycom
,
matchEasycom
}
from
'
../../utils
'
const
H5_COMPONENTS_PATH
=
'
@dcloudio/uni-h5
'
...
...
@@ -72,7 +72,6 @@ export function uniEasycomPlugin(
)
{
return
}
debugEasycom
(
id
)
let
i
=
0
const
importDeclarations
:
string
[]
=
[]
code
=
code
.
replace
(
...
...
packages/vite-plugin-uni/src/configResolved/plugins/index.ts
浏览文件 @
3f7548b8
...
...
@@ -12,7 +12,6 @@ import { uniJsonPlugin } from './json'
import
{
uniPreCssPlugin
}
from
'
./preCss
'
import
{
uniEasycomPlugin
}
from
'
./easycom
'
import
{
uniPageVuePlugin
}
from
'
./pageVue
'
import
{
uniCopyPlugin
}
from
'
./copy
'
import
{
uniStaticPlugin
}
from
'
./static
'
import
{
uniRenderjsPlugin
}
from
'
./renderjs
'
...
...
@@ -78,7 +77,6 @@ export function initPlugins(
uniEasycomPlugin
(
extend
(
uniEasycomPluginOptions
,
options
),
config
),
'
vite:vue
'
)
addPlugin
(
plugins
,
uniPageVuePlugin
(
options
),
'
vite:vue
'
)
addPlugin
(
plugins
,
uniJsonPlugin
(
options
),
'
vite:json
'
,
'
pre
'
)
addPlugin
(
plugins
,
uniStaticPlugin
(
options
,
config
),
'
vite:asset
'
,
'
pre
'
)
...
...
packages/vite-plugin-uni/src/configResolved/plugins/resolveId.ts
浏览文件 @
3f7548b8
import
fs
from
'
fs
'
import
path
from
'
path
'
import
debug
from
'
debug
'
import
{
Plugin
}
from
'
vite
'
import
{
resolveBuiltIn
}
from
'
@dcloudio/uni-cli-shared
'
import
{
parseVueRequest
,
resolveBuiltIn
}
from
'
@dcloudio/uni-cli-shared
'
import
{
VitePluginUniResolvedOptions
}
from
'
../..
'
...
...
@@ -20,7 +21,7 @@ const BUILT_IN_MODULES = {
export
type
BuiltInModulesKey
=
keyof
typeof
BUILT_IN_MODULES
export
function
uniResolveIdPlugin
(
_
options
:
VitePluginUniResolvedOptions
options
:
VitePluginUniResolvedOptions
):
Plugin
{
const
resolveCache
:
Record
<
string
,
string
>
=
{}
return
{
...
...
@@ -37,5 +38,13 @@ export function uniResolveIdPlugin(
))
}
},
load
(
id
)
{
if
(
options
.
command
===
'
build
'
)
{
const
{
filename
,
query
}
=
parseVueRequest
(
id
)
if
(
query
.
mpType
===
'
page
'
)
{
return
fs
.
readFileSync
(
filename
,
'
utf8
'
)
}
}
},
}
}
packages/vite-plugin-uni/src/configResolved/plugins/ssr.ts
浏览文件 @
3f7548b8
import
path
from
'
path
'
import
debug
from
'
debug
'
import
crypto
from
'
crypto
'
import
{
Plugin
,
ResolvedConfig
}
from
'
vite
'
import
{
walk
}
from
'
estree-walker
'
import
{
CallExpression
}
from
'
estree
'
import
{
OutputChunk
}
from
'
rollup
'
import
{
createFilter
}
from
'
@rollup/pluginutils
'
import
{
MagicString
}
from
'
@vue/compiler-sfc
'
import
{
parseRpx2UnitOnce
}
from
'
@dcloudio/uni-cli-shared
'
import
{
UniPluginFilterOptions
}
from
'
.
'
import
{
isIdentifier
,
isCallExpression
,
isMemberExpression
,
generateSsrDefineCode
,
generateSsrEntryServerCode
,
}
from
'
../../utils
'
import
{
isIdentifier
,
isCallExpression
,
isMemberExpression
}
from
'
../../utils
'
const
debugSSR
=
debug
(
'
vite:uni:ssr
'
)
const
KEYED_FUNC_RE
=
/
(
ssrRef|shallowSsrRef
)
/
const
ENTRY_SERVER_JS
=
'
entry-server.js
'
export
function
uniSSRPlugin
(
config
:
ResolvedConfig
,
_
config
:
ResolvedConfig
,
options
:
UniPluginFilterOptions
):
Plugin
{
const
filter
=
createFilter
(
options
.
include
,
options
.
exclude
)
const
entryServerJs
=
path
.
join
(
options
.
inputDir
,
ENTRY_SERVER_JS
)
const
entryServerJsCode
=
generateSsrEntryServerCode
()
return
{
name
:
'
vite:uni-ssr
'
,
resolveId
(
id
)
{
if
(
id
.
endsWith
(
ENTRY_SERVER_JS
))
{
return
entryServerJs
}
},
load
(
id
)
{
if
(
id
.
endsWith
(
ENTRY_SERVER_JS
))
{
return
entryServerJsCode
}
},
transform
(
code
,
id
)
{
if
(
!
filter
(
id
))
return
null
if
(
!
KEYED_FUNC_RE
.
test
(
code
))
{
...
...
@@ -81,15 +58,6 @@ export function uniSSRPlugin(
map
:
s
.
generateMap
().
toString
(),
}
},
generateBundle
(
_options
,
bundle
)
{
const
chunk
=
bundle
[
'
entry-server.js
'
]
as
OutputChunk
if
(
chunk
)
{
chunk
.
code
=
generateSsrDefineCode
(
config
,
parseRpx2UnitOnce
(
options
.
inputDir
))
+
'
\n
'
+
chunk
.
code
}
},
}
}
...
...
packages/vite-plugin-uni/src/configureServer/easycom.ts
浏览文件 @
3f7548b8
import
debug
from
'
debug
'
import
{
ViteDevServer
}
from
'
vite
'
import
{
debounce
}
from
'
@dcloudio/uni-shared
'
import
{
initEasycomsOnce
}
from
'
@dcloudio/uni-cli-shared
'
import
{
VitePluginUniResolvedOptions
}
from
'
..
'
import
{
debugEasycom
,
initEasycomsOnce
}
from
'
../utils
'
const
debugEasycom
=
debug
(
'
vite:uni:easycom
'
)
export
const
serveEasycom
=
(
server
:
ViteDevServer
,
options
:
VitePluginUniResolvedOptions
...
...
packages/vite-plugin-uni/src/index.ts
浏览文件 @
3f7548b8
...
...
@@ -9,7 +9,6 @@ import ViteLegacyPlugin from '@vitejs/plugin-legacy'
import
{
createConfig
}
from
'
./config
'
import
{
createConfigResolved
}
from
'
./configResolved
'
import
{
createConfigureServer
}
from
'
./configureServer
'
import
{
createHandleHotUpdate
}
from
'
./handleHotUpdate
'
import
{
initExtraPlugins
}
from
'
./utils
'
import
{
createTransformIndexHtml
}
from
'
./transformIndexHtml
'
...
...
@@ -79,7 +78,6 @@ export default function uniPlugin(
config
:
createConfig
(
options
,
uniPlugins
),
configResolved
:
createConfigResolved
(
options
),
configureServer
:
createConfigureServer
(
options
),
handleHotUpdate
:
createHandleHotUpdate
(
options
),
transformIndexHtml
:
createTransformIndexHtml
(
options
),
})
plugins
.
push
(...
uniPlugins
)
...
...
packages/vite-plugin-uni/src/utils/index.ts
浏览文件 @
3f7548b8
export
*
from
'
./ast
'
export
*
from
'
./ssr
'
export
*
from
'
./filter
'
export
*
from
'
./plugin
'
export
*
from
'
./features
'
export
*
from
'
./easycom
'
export
*
from
'
./postcss
'
packages/vite-plugin-uni/src/utils/ssr.ts
已删除
100644 → 0
浏览文件 @
d9cedce2
import
path
from
'
path
'
import
fs
from
'
fs-extra
'
import
{
extend
,
isArray
,
isString
,
NormalizedStyle
}
from
'
@vue/shared
'
import
{
isNativeTag
,
createRpx2Unit
,
Rpx2UnitOptions
,
}
from
'
@dcloudio/uni-shared
'
import
{
parseRpx2UnitOnce
,
resolveBuiltIn
}
from
'
@dcloudio/uni-cli-shared
'
import
{
ConfigEnv
,
ResolvedConfig
,
UserConfig
}
from
'
vite
'
import
resolve
from
'
resolve
'
export
function
isSsr
(
command
:
ConfigEnv
[
'
command
'
],
config
:
UserConfig
|
ResolvedConfig
)
{
if
(
command
===
'
serve
'
)
{
return
!!
(
config
.
server
&&
config
.
server
.
middlewareMode
)
}
if
(
command
===
'
build
'
)
{
return
!!
(
config
.
build
&&
config
.
build
.
ssr
)
}
return
false
}
export
function
isSsrManifest
(
command
:
ConfigEnv
[
'
command
'
],
config
:
UserConfig
|
ResolvedConfig
)
{
if
(
command
===
'
build
'
)
{
return
!!
(
config
.
build
&&
config
.
build
.
ssrManifest
)
}
return
false
}
export
function
initSsrDefine
(
config
:
ResolvedConfig
)
{
return
extend
(
globalThis
,
{
__IMPORT_META_ENV_BASE_URL__
:
config
.
env
.
BASE_URL
,
})
}
function
serializeDefine
(
define
:
Record
<
string
,
any
>
):
string
{
let
res
=
`{`
for
(
const
key
in
define
)
{
const
val
=
define
[
key
]
res
+=
`
${
JSON
.
stringify
(
key
)}
:
${
typeof
val
===
'
string
'
?
`(
${
val
}
)`
:
JSON
.
stringify
(
val
)
}
, `
}
return
res
+
`}`
}
function
normalizeSsrDefine
(
config
:
ResolvedConfig
)
{
const
defines
=
extend
(
{
__IMPORT_META_ENV_BASE_URL__
:
JSON
.
stringify
(
config
.
env
.
BASE_URL
),
},
config
.
define
!
)
delete
defines
[
'
import.meta.env.LEGACY
'
]
return
defines
}
export
function
generateSsrDefineCode
(
config
:
ResolvedConfig
,
{
unit
,
unitRatio
,
unitPrecision
}:
Rpx2UnitOptions
):
string
{
return
fs
.
readFileSync
(
path
.
join
(
__dirname
,
'
../../lib/ssr/define.js
'
),
'
utf8
'
)
.
replace
(
'
__DEFINES__
'
,
serializeDefine
(
normalizeSsrDefine
(
config
)))
.
replace
(
'
__UNIT__
'
,
JSON
.
stringify
(
unit
))
.
replace
(
'
__UNIT_RATIO__
'
,
JSON
.
stringify
(
unitRatio
))
.
replace
(
'
__UNIT_PRECISION__
'
,
JSON
.
stringify
(
unitPrecision
))
}
export
function
generateSsrEntryServerCode
()
{
return
fs
.
readFileSync
(
path
.
join
(
__dirname
,
'
../../lib/ssr/entry-server.js
'
),
'
utf8
'
)
}
export
function
rewriteSsrVue
(
mode
?:
2
|
3
)
{
// 解决 @vue/server-renderer 中引入 vue 的映射
let
vuePath
:
string
if
(
mode
===
2
)
{
vuePath
=
resolveBuiltIn
(
'
@dcloudio/uni-h5-vue/dist/vue.runtime.compat.cjs.js
'
)
}
else
{
vuePath
=
resolveBuiltIn
(
'
@dcloudio/uni-h5-vue/dist/vue.runtime.cjs.js
'
)
}
require
(
'
module-alias
'
).
addAlias
(
'
vue
'
,
vuePath
)
}
function
initResolveSyncOpts
(
opts
?:
resolve
.
SyncOpts
)
{
if
(
!
opts
)
{
opts
=
{}
}
if
(
!
opts
.
paths
)
{
opts
.
paths
=
[]
}
if
(
isString
(
opts
.
paths
))
{
opts
.
paths
=
[
opts
.
paths
]
}
if
(
isArray
(
opts
.
paths
))
{
opts
.
paths
.
push
(
path
.
join
(
process
.
env
.
UNI_CLI_CONTEXT
,
'
node_modules
'
))
}
return
opts
}
export
function
rewriteSsrResolve
(
mode
?:
2
|
3
)
{
// 解决 ssr 时 __vite_ssr_import__("vue") 的映射
const
resolve
=
require
(
'
resolve
'
)
const
oldSync
=
resolve
.
sync
resolve
.
sync
=
(
id
:
string
,
opts
?:
resolve
.
SyncOpts
)
=>
{
if
(
id
===
'
vue
'
)
{
return
resolveBuiltIn
(
`@dcloudio/uni-h5-vue/dist/vue.runtime.
${
mode
===
2
?
'
compat.
'
:
''
}
cjs.js`
)
}
return
oldSync
(
id
,
initResolveSyncOpts
(
opts
))
}
}
export
function
rewriteSsrNativeTag
()
{
const
{
parserOptions
}
=
require
(
'
@vue/compiler-dom
'
)
// TODO compiler-ssr时,传入的 isNativeTag 会被 @vue/compiler-dom 的 isNativeTag 覆盖
// https://github.com/vuejs/vue-next/blob/master/packages/compiler-ssr/src/index.ts#L36
parserOptions
.
isNativeTag
=
isNativeTag
}
export
function
rewriteSsrRenderStyle
(
inputDir
:
string
)
{
const
{
unit
,
unitRatio
,
unitPrecision
}
=
parseRpx2UnitOnce
(
inputDir
)
const
rpx2unit
=
createRpx2Unit
(
unit
,
unitRatio
,
unitPrecision
)
const
shared
=
require
(
'
@vue/shared
'
)
const
oldStringifyStyle
=
shared
.
stringifyStyle
shared
.
stringifyStyle
=
(
styles
:
NormalizedStyle
|
undefined
)
=>
rpx2unit
(
oldStringifyStyle
(
styles
))
const
serverRender
=
require
(
'
@vue/server-renderer
'
)
const
oldSsrRenderStyle
=
serverRender
.
ssrRenderStyle
// 仅对字符串类型做转换,非字符串类型,通过 stringifyStyle 转换
serverRender
.
ssrRenderStyle
=
(
raw
:
unknown
)
=>
isString
(
raw
)
?
rpx2unit
(
oldSsrRenderStyle
(
raw
))
:
oldSsrRenderStyle
(
raw
)
}
packages/vite-plugin-uni/src/vue/options.ts
浏览文件 @
3f7548b8
import
{
Plugin
}
from
'
vite
'
import
{
extend
,
hasOwn
,
isArray
}
from
'
@vue/shared
'
import
{
ParserOptions
}
from
'
@vue/compiler-core
'
import
{
SFCTemplateCompileOptions
}
from
'
@vue/compiler-sfc
'
import
{
isCustomElement
,
isNativeTag
}
from
'
@dcloudio/uni-shared
'
import
{
EXTNAME_VUE_RE
,
parseCompatConfigOnce
}
from
'
@dcloudio/uni-cli-shared
'
import
{
EXTNAME_VUE_RE
,
parseCompatConfigOnce
,
UniVitePlugin
,
}
from
'
@dcloudio/uni-cli-shared
'
import
{
VitePluginUniResolvedOptions
}
from
'
..
'
import
{
transformMatchMedia
}
from
'
./transforms/transformMatchMedia
'
...
...
@@ -33,15 +37,9 @@ function createUniVueTransformAssetUrls(
}
}
interface
UniPlugin
extends
Plugin
{
uni
?:
{
transformEvent
?:
Record
<
string
,
string
>
}
}
export
function
initPluginVueOptions
(
options
:
VitePluginUniResolvedOptions
,
uniPlugins
:
Uni
Plugin
[]
UniVitePlugins
:
UniVite
Plugin
[]
)
{
const
vueOptions
=
options
.
vueOptions
||
(
options
.
vueOptions
=
{})
if
(
!
vueOptions
.
include
)
{
...
...
@@ -58,9 +56,21 @@ export function initPluginVueOptions(
options
.
base
)
let
isCompilerNativeTag
:
ParserOptions
[
'
isNativeTag
'
]
=
isNativeTag
let
isCompilerCustomElement
:
ParserOptions
[
'
isCustomElement
'
]
=
isCustomElement
UniVitePlugins
.
forEach
((
plugin
)
=>
{
if
(
plugin
.
uni
?.
compilerOptions
?.
isNativeTag
)
{
isCompilerNativeTag
=
plugin
.
uni
.
compilerOptions
.
isNativeTag
}
if
(
plugin
.
uni
?.
compilerOptions
?.
isCustomElement
)
{
isCompilerCustomElement
=
plugin
.
uni
.
compilerOptions
.
isCustomElement
}
})
const
compilerOptions
=
templateOptions
.
compilerOptions
||
(
templateOptions
.
compilerOptions
=
{})
compilerOptions
.
isNativeTag
=
isNativeTag
compilerOptions
.
isNativeTag
=
is
Compiler
NativeTag
if
(
!
compilerOptions
.
nodeTransforms
)
{
compilerOptions
.
nodeTransforms
=
[]
}
...
...
@@ -72,11 +82,11 @@ export function initPluginVueOptions(
compatConfig
)
compilerOptions
.
isCustomElement
=
isCustomElement
compilerOptions
.
isCustomElement
=
isC
ompilerC
ustomElement
const
eventOpts
=
uni
Plugins
.
reduce
<
Record
<
string
,
string
>>
(
(
eventOpts
,
uni
Plugin
)
=>
{
return
extend
(
eventOpts
,
uni
Plugin
.
uni
?.
transformEvent
)
const
eventOpts
=
UniVite
Plugins
.
reduce
<
Record
<
string
,
string
>>
(
(
eventOpts
,
UniVite
Plugin
)
=>
{
return
extend
(
eventOpts
,
UniVite
Plugin
.
uni
?.
transformEvent
)
},
{}
)
...
...
yarn.lock
浏览文件 @
3f7548b8
...
...
@@ -5622,6 +5622,11 @@ merge2@^1.2.3, merge2@^1.3.0:
version "1.4.1"
resolved "https://registry.yarnpkg.com/merge2/-/merge2-1.4.1.tgz#4368892f885e907455a6fd7dc55c0c9d404990ae"
merge@^2.1.1:
version "2.1.1"
resolved "https://registry.yarnpkg.com/merge/-/merge-2.1.1.tgz#59ef4bf7e0b3e879186436e8481c06a6c162ca98"
integrity sha512-jz+Cfrg9GWOZbQAnDQ4hlVnQky+341Yk5ru8bZSe6sIDTCIg8n9i/u7hSQGSVOF3C7lH6mGtqjkiT9G4wFLL0w==
methods@~1.1.2:
version "1.1.2"
resolved "https://registry.yarnpkg.com/methods/-/methods-1.1.2.tgz#5529a4d67654134edcc5266656835b0f851afcee"
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录