Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
MuGuiLin
uni-app
提交
c87b1289
U
uni-app
项目概览
MuGuiLin
/
uni-app
与 Fork 源项目一致
Fork自
DCloud / uni-app
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
c87b1289
编写于
1月 12, 2022
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
wip(app): nvue
上级
cf107fa8
变更
16
隐藏空白更改
内联
并排
Showing
16 changed file
with
218 addition
and
87 deletion
+218
-87
packages/uni-app-vite/src/nvue/index.ts
packages/uni-app-vite/src/nvue/index.ts
+8
-1
packages/uni-app-vite/src/nvue/plugin/index.ts
packages/uni-app-vite/src/nvue/plugin/index.ts
+51
-2
packages/uni-app-vite/src/nvue/plugins/entry.ts
packages/uni-app-vite/src/nvue/plugins/entry.ts
+0
-50
packages/uni-app-vite/src/nvue/plugins/mainJs.ts
packages/uni-app-vite/src/nvue/plugins/mainJs.ts
+41
-0
packages/uni-app-vite/src/nvue/plugins/pagesJson.ts
packages/uni-app-vite/src/nvue/plugins/pagesJson.ts
+59
-0
packages/uni-app-vite/src/plugin/build.ts
packages/uni-app-vite/src/plugin/build.ts
+9
-1
packages/uni-app-vite/src/utils.ts
packages/uni-app-vite/src/utils.ts
+3
-0
packages/uni-app-vite/src/vue/plugin/index.ts
packages/uni-app-vite/src/vue/plugin/index.ts
+0
-3
packages/uni-app-vite/src/vue/plugins/mainJs.ts
packages/uni-app-vite/src/vue/plugins/mainJs.ts
+2
-2
packages/uni-app-vite/src/vue/plugins/pagesJson.ts
packages/uni-app-vite/src/vue/plugins/pagesJson.ts
+7
-12
packages/uni-app-vite/src/vue/plugins/renderjs.ts
packages/uni-app-vite/src/vue/plugins/renderjs.ts
+2
-2
packages/uni-cli-shared/src/json/app/pages/definePage.ts
packages/uni-cli-shared/src/json/app/pages/definePage.ts
+16
-0
packages/uni-cli-shared/src/json/app/pages/index.ts
packages/uni-cli-shared/src/json/app/pages/index.ts
+5
-1
packages/uni-cli-shared/src/vite/plugins/dynamicImportPolyfill.ts
.../uni-cli-shared/src/vite/plugins/dynamicImportPolyfill.ts
+12
-0
packages/uni-cli-shared/src/vite/plugins/index.ts
packages/uni-cli-shared/src/vite/plugins/index.ts
+1
-0
packages/uni-mp-vite/src/plugin/build.ts
packages/uni-mp-vite/src/plugin/build.ts
+2
-13
未找到文件。
packages/uni-app-vite/src/nvue/index.ts
浏览文件 @
c87b1289
...
...
@@ -4,13 +4,20 @@ import {
uniViteInjectPlugin
,
UNI_EASYCOM_EXCLUDE
,
}
from
'
@dcloudio/uni-cli-shared
'
import
{
uniAppNVuePlugin
}
from
'
./plugin
'
import
{
uniEasycomPlugin
}
from
'
../plugins/easycom
'
import
{
uniManifestJsonPlugin
}
from
'
../plugins/manifestJson
'
import
{
uniAppNVuePlugin
}
from
'
./plugin
'
import
{
uniMainJsPlugin
}
from
'
./plugins/mainJs
'
import
{
uniPagesJsonPlugin
}
from
'
./plugins/pagesJson
'
export
function
initNVuePlugins
()
{
return
[
uniEasycomPlugin
({
exclude
:
UNI_EASYCOM_EXCLUDE
}),
uniHBuilderXConsolePlugin
(),
uniMainJsPlugin
(),
...(
process
.
env
.
UNI_RENDERER
===
'
native
'
?
[
uniManifestJsonPlugin
()]
:
[]),
uniPagesJsonPlugin
(),
uniViteInjectPlugin
(
'
uni:app-inject
'
,
initAppProvide
()),
uniAppNVuePlugin
(),
]
...
...
packages/uni-app-vite/src/nvue/plugin/index.ts
浏览文件 @
c87b1289
import
path
from
'
path
'
import
{
dynamicImportPolyfill
,
normalizePath
,
parseVueRequest
,
removeExt
,
resolveMainPathOnce
,
}
from
'
@dcloudio/uni-cli-shared
'
import
{
PreRenderedChunk
}
from
'
rollup
'
import
{
Plugin
}
from
'
vite
'
import
{
nvueOutDir
}
from
'
../../utils
'
export
function
uniAppNVuePlugin
():
Plugin
{
return
{
name
:
'
uni:app-nvue
'
,
config
()
{
const
inputDir
=
process
.
env
.
UNI_INPUT_DIR
const
mainPath
=
resolveMainPathOnce
(
inputDir
)
return
{
lib
:
{
// 必须使用 lib 模式,否则会生成 preload 等代码
fileName
:
'
main.js
'
,
entry
:
mainPath
,
formats
:
[
'
esm
'
],
},
build
:
{
outDir
:
path
.
join
(
process
.
env
.
UNI_OUTPUT_DIR
,
'
../.nvue
'
),
rollupOptions
:
{},
outDir
:
nvueOutDir
(),
rollupOptions
:
{
input
:
{
main
:
mainPath
,
},
output
:
{
entryFileNames
(
chunk
)
{
if
(
chunk
.
name
===
'
main
'
)
{
return
'
app.js
'
}
return
chunk
.
name
+
'
.js
'
},
format
:
'
esm
'
,
assetFileNames
:
'
[name][extname]
'
,
chunkFileNames
:
createChunkFileNames
(
inputDir
),
plugins
:
[
dynamicImportPolyfill
()],
},
},
},
}
},
}
}
function
createChunkFileNames
(
inputDir
:
string
):
(
chunkInfo
:
PreRenderedChunk
)
=>
string
{
return
function
chunkFileNames
(
chunk
)
{
if
(
chunk
.
isDynamicEntry
&&
chunk
.
facadeModuleId
)
{
const
{
filename
}
=
parseVueRequest
(
chunk
.
facadeModuleId
)
if
(
filename
.
endsWith
(
'
.nvue
'
))
{
return
(
removeExt
(
normalizePath
(
path
.
relative
(
inputDir
,
filename
)))
+
'
.js
'
)
}
}
return
'
[name].js
'
}
}
packages/uni-app-vite/src/nvue/plugins/entry.ts
已删除
100644 → 0
浏览文件 @
cf107fa8
import
path
from
'
path
'
import
type
{
Plugin
}
from
'
vite
'
import
{
decodeBase64Url
,
encodeBase64Url
,
normalizePath
,
polyfillCode
,
}
from
'
@dcloudio/uni-cli-shared
'
const
uniNVuePagePrefix
=
'
uniNVuePage://
'
function
isUniNVuePageUrl
(
id
:
string
)
{
return
id
.
startsWith
(
uniNVuePagePrefix
)
}
export
function
createUniNVuePagePath
(
pagePath
:
string
)
{
return
uniNVuePagePrefix
+
encodeBase64Url
(
pagePath
+
'
.nvue
'
)
}
function
parseUniNvuePagePath
(
uniNVuePageUrl
:
string
)
{
return
decodeBase64Url
(
uniNVuePageUrl
.
replace
(
uniNVuePagePrefix
,
''
))
}
export
function
uniNVueEntryPlugin
():
Plugin
{
const
inputDir
=
process
.
env
.
UNI_INPUT_DIR
return
{
name
:
'
uni:app-nvue-entry
'
,
enforce
:
'
pre
'
,
resolveId
(
id
)
{
if
(
isUniNVuePageUrl
(
id
))
{
return
id
}
},
load
(
id
)
{
if
(
isUniNVuePageUrl
(
id
))
{
const
filepath
=
normalizePath
(
path
.
resolve
(
inputDir
,
parseUniNvuePagePath
(
id
))
)
this
.
addWatchFile
(
filepath
)
return
{
code
:
`import { createApp } from 'vue'
import App from '
${
filepath
}
'
${
polyfillCode
}
createApp(App).mount('#app')
`
,
}
}
},
}
}
packages/uni-app-vite/src/nvue/plugins/mainJs.ts
0 → 100644
浏览文件 @
c87b1289
import
{
defineUniMainJsPlugin
}
from
'
@dcloudio/uni-cli-shared
'
export
function
uniMainJsPlugin
()
{
return
defineUniMainJsPlugin
((
opts
)
=>
{
return
{
name
:
'
uni:app-nvue-main-js
'
,
enforce
:
'
pre
'
,
transform
(
code
,
id
)
{
if
(
opts
.
filter
(
id
))
{
if
(
process
.
env
.
UNI_RENDERER
===
'
native
'
)
{
code
=
code
.
includes
(
'
createSSRApp
'
)
?
createApp
(
code
)
:
createLegacyApp
(
code
)
return
{
code
:
`import './pages.json.js';`
+
code
,
map
:
{
mappings
:
''
},
}
}
return
{
code
:
`import './pages.json.js'`
,
map
:
{
mappings
:
''
},
}
}
},
}
})
}
function
createApp
(
code
:
string
)
{
return
`
${
code
.
replace
(
'
createSSRApp
'
,
'
createVueApp as createSSRApp
'
)}
;const __app__=createApp().app;__app__._component.mpType='app';__app__._component.render=()=>{};__app__.use(uni.__vuePlugin).mount("#app");`
}
function
createLegacyApp
(
code
:
string
)
{
return
`function createApp(rootComponent,rootProps){rootComponent.mpTye='app';rootComponent.render=()=>{};const app=createVueApp(rootComponent,rootProps).use(uni.__vuePlugin);const oldMount=app.mount;app.mount=(container)=>{const appVm=oldMount.call(app,container);return appVm;};return app;};
${
code
.
replace
(
'
createApp
'
,
'
createVueApp
'
)}
`
}
packages/uni-app-vite/src/nvue/plugins/pagesJson.ts
0 → 100644
浏览文件 @
c87b1289
import
path
from
'
path
'
import
{
Plugin
}
from
'
vite
'
import
{
defineUniPagesJsonPlugin
,
normalizeAppConfigService
,
normalizePagesJson
,
parseManifestJsonOnce
,
getLocaleFiles
,
normalizeAppNVuePagesJson
,
}
from
'
@dcloudio/uni-cli-shared
'
export
function
uniPagesJsonPlugin
():
Plugin
{
return
defineUniPagesJsonPlugin
((
opts
)
=>
{
return
{
name
:
'
uni:app-nvue-pages-json
'
,
enforce
:
'
pre
'
,
transform
(
code
,
id
)
{
if
(
!
opts
.
filter
(
id
))
{
return
}
this
.
addWatchFile
(
path
.
resolve
(
process
.
env
.
UNI_INPUT_DIR
,
'
pages.json
'
))
getLocaleFiles
(
path
.
resolve
(
process
.
env
.
UNI_INPUT_DIR
,
'
locale
'
)
).
forEach
((
filepath
)
=>
{
this
.
addWatchFile
(
filepath
)
})
const
pagesJson
=
normalizePagesJson
(
code
,
process
.
env
.
UNI_PLATFORM
)
pagesJson
.
pages
.
forEach
((
page
)
=>
{
if
(
page
.
style
.
isNVue
)
{
this
.
addWatchFile
(
path
.
resolve
(
process
.
env
.
UNI_INPUT_DIR
,
page
.
path
+
'
.nvue
'
)
)
}
})
if
(
process
.
env
.
UNI_RENDERER
===
'
native
'
)
{
this
.
emitFile
({
fileName
:
`app-config-service.js`
,
type
:
'
asset
'
,
source
:
normalizeAppConfigService
(
pagesJson
,
parseManifestJsonOnce
(
process
.
env
.
UNI_INPUT_DIR
)
),
})
return
{
code
:
`import './manifest.json.js'\n`
+
normalizeAppNVuePagesJson
(
pagesJson
),
map
:
{
mappings
:
''
},
}
}
return
{
code
:
normalizeAppNVuePagesJson
(
pagesJson
),
map
:
{
mappings
:
''
},
}
},
}
})
}
packages/uni-app-vite/src/plugin/build.ts
浏览文件 @
c87b1289
...
...
@@ -6,7 +6,9 @@ import {
emptyDir
,
isInHybridNVue
,
normalizePath
,
resolveMainPathOnce
,
}
from
'
@dcloudio/uni-cli-shared
'
import
{
nvueOutDir
}
from
'
../utils
'
export
function
buildOptions
(
userConfig
:
UserConfig
,
...
...
@@ -15,7 +17,12 @@ export function buildOptions(
const
inputDir
=
process
.
env
.
UNI_INPUT_DIR
const
outputDir
=
process
.
env
.
UNI_OUTPUT_DIR
// 开始编译时,清空输出目录
if
(
!
isInHybridNVue
(
userConfig
))
{
if
(
isInHybridNVue
(
userConfig
))
{
const
nvueOutputDir
=
nvueOutDir
()
if
(
fs
.
existsSync
(
nvueOutputDir
))
{
emptyDir
(
nvueOutputDir
)
}
}
else
{
if
(
fs
.
existsSync
(
outputDir
))
{
emptyDir
(
outputDir
)
}
...
...
@@ -27,6 +34,7 @@ export function buildOptions(
assetsInlineLimit
:
0
,
rollupOptions
:
{
external
:
[
'
vue
'
],
input
:
resolveMainPathOnce
(
inputDir
),
output
:
{
sourcemapPathTransform
(
relativeSourcePath
,
sourcemapPath
)
{
const
sourcePath
=
normalizePath
(
...
...
packages/uni-app-vite/src/utils.ts
浏览文件 @
c87b1289
import
path
from
'
path
'
export
const
templateDir
=
path
.
resolve
(
__dirname
,
'
../lib/template/
'
)
export
function
nvueOutDir
()
{
return
path
.
join
(
process
.
env
.
UNI_OUTPUT_DIR
,
'
../.nvue
'
)
}
packages/uni-app-vite/src/vue/plugin/index.ts
浏览文件 @
c87b1289
...
...
@@ -2,7 +2,6 @@ import path from 'path'
import
fs
from
'
fs-extra
'
import
{
APP_SERVICE_FILENAME
,
resolveMainPathOnce
,
parsePagesJsonOnce
,
UniVitePlugin
,
}
from
'
@dcloudio/uni-cli-shared
'
...
...
@@ -13,14 +12,12 @@ import { configResolved } from './configResolved'
import
{
templateDir
}
from
'
../../utils
'
export
function
uniAppVuePlugin
():
UniVitePlugin
{
const
inputDir
=
process
.
env
.
UNI_INPUT_DIR
return
{
name
:
'
uni:app-vue
'
,
config
()
{
return
{
build
:
{
rollupOptions
:
{
input
:
resolveMainPathOnce
(
inputDir
),
output
:
{
name
:
'
AppService
'
,
format
:
process
.
env
.
UNI_APP_CODE_SPLITING
?
'
amd
'
:
'
iife
'
,
...
...
packages/uni-app-vite/src/vue/plugins/mainJs.ts
浏览文件 @
c87b1289
...
...
@@ -3,7 +3,7 @@ import { defineUniMainJsPlugin } from '@dcloudio/uni-cli-shared'
export
function
uniMainJsPlugin
()
{
return
defineUniMainJsPlugin
((
opts
)
=>
{
return
{
name
:
'
uni:app-main-js
'
,
name
:
'
uni:app-
vue-
main-js
'
,
enforce
:
'
pre
'
,
transform
(
code
,
id
)
{
if
(
opts
.
filter
(
id
))
{
...
...
@@ -12,7 +12,7 @@ export function uniMainJsPlugin() {
:
createLegacyApp
(
code
)
return
{
code
:
`import './pages.json.js';`
+
code
,
map
:
this
.
getCombinedSourcemap
()
,
map
:
{
mappings
:
''
}
,
}
}
},
...
...
packages/uni-app-vite/src/vue/plugins/pagesJson.ts
浏览文件 @
c87b1289
...
...
@@ -9,12 +9,11 @@ import {
parseManifestJsonOnce
,
getLocaleFiles
,
}
from
'
@dcloudio/uni-cli-shared
'
import
{
initWebpackNVueEntry
}
from
'
@dcloudio/uni-cli-nvue
'
export
function
uniPagesJsonPlugin
():
Plugin
{
return
defineUniPagesJsonPlugin
((
opts
)
=>
{
return
{
name
:
'
uni:app-pages-json
'
,
name
:
'
uni:app-
vue-
pages-json
'
,
enforce
:
'
pre
'
,
transform
(
code
,
id
)
{
if
(
!
opts
.
filter
(
id
))
{
...
...
@@ -27,16 +26,12 @@ export function uniPagesJsonPlugin(): Plugin {
this
.
addWatchFile
(
filepath
)
})
const
pagesJson
=
normalizePagesJson
(
code
,
process
.
env
.
UNI_PLATFORM
)
if
(
process
.
env
.
UNI_NVUE_COMPILER
!==
'
vue
'
)
{
initWebpackNVueEntry
(
pagesJson
.
pages
)
}
// TODO subpackages
pagesJson
.
pages
.
forEach
((
page
)
=>
{
this
.
addWatchFile
(
path
.
resolve
(
process
.
env
.
UNI_INPUT_DIR
,
page
.
path
+
'
.vue
'
)
)
if
(
!
page
.
style
.
isNVue
)
{
this
.
addWatchFile
(
path
.
resolve
(
process
.
env
.
UNI_INPUT_DIR
,
page
.
path
+
'
.vue
'
)
)
}
})
this
.
emitFile
({
fileName
:
`app-config-service.js`
,
...
...
@@ -49,7 +44,7 @@ export function uniPagesJsonPlugin(): Plugin {
return
{
code
:
`import './manifest.json.js'\n`
+
normalizeAppPagesJson
(
pagesJson
),
map
:
this
.
getCombinedSourcemap
()
,
map
:
{
mappings
:
''
}
,
}
},
}
...
...
packages/uni-app-vite/src/vue/plugins/renderjs.ts
浏览文件 @
c87b1289
...
...
@@ -24,7 +24,7 @@ export function uniRenderjsPlugin(): Plugin {
let
resolvedConfig
:
ResolvedConfig
let
changed
:
boolean
=
false
return
{
name
:
'
uni:app-renderjs
'
,
name
:
'
uni:app-
vue-
renderjs
'
,
configResolved
(
config
)
{
resolvedConfig
=
config
wxsModulesCache
.
set
(
resolvedConfig
,
new
Map
<
string
,
string
>
())
...
...
@@ -78,7 +78,7 @@ export function uniRenderjsPlugin(): Plugin {
;(Comp.$
${
type
}
|| (Comp.$
${
type
}
= [])).push('
${
name
}
')
;(Comp.$
${
globalName
}
|| (Comp.$
${
globalName
}
= {}))['
${
name
}
'] = '
${
moduleHashId
}
'
}`
,
map
:
null
,
map
:
{
mappings
:
''
}
,
}
},
generateBundle
()
{
...
...
packages/uni-cli-shared/src/json/app/pages/definePage.ts
浏览文件 @
c87b1289
...
...
@@ -26,3 +26,19 @@ export function definePageCode(pagesJson: Record<string, any>) {
})
return
importPagesCode
.
join
(
'
\n
'
)
+
'
\n
'
+
definePagesCode
.
join
(
'
\n
'
)
}
export
function
defineNVuePageCode
(
pagesJson
:
Record
<
string
,
any
>
)
{
const
importNVuePagesCode
:
string
[]
=
[]
pagesJson
.
pages
.
forEach
((
page
:
UniApp
.
PagesJsonPageOptions
)
=>
{
if
(
!
page
.
style
.
isNVue
)
{
return
}
const
pagePathWithExtname
=
normalizePagePath
(
page
.
path
,
'
app
'
)
if
(
pagePathWithExtname
)
{
importNVuePagesCode
.
push
(
`import('./
${
pagePathWithExtname
}
').then(()=>{})`
)
}
})
return
importNVuePagesCode
.
join
(
'
\n
'
)
}
packages/uni-cli-shared/src/json/app/pages/index.ts
浏览文件 @
c87b1289
import
{
globalCode
,
polyfillCode
,
restoreGlobalCode
}
from
'
./code
'
import
{
definePageCode
}
from
'
./definePage
'
import
{
definePageCode
,
defineNVuePageCode
}
from
'
./definePage
'
import
{
normalizeAppUniConfig
}
from
'
./uniConfig
'
import
{
normalizeAppUniRoutes
}
from
'
./uniRoutes
'
...
...
@@ -7,6 +7,10 @@ export function normalizeAppPagesJson(pagesJson: Record<string, any>) {
return
polyfillCode
+
restoreGlobalCode
+
definePageCode
(
pagesJson
)
}
export
function
normalizeAppNVuePagesJson
(
pagesJson
:
Record
<
string
,
any
>
)
{
return
defineNVuePageCode
(
pagesJson
)
}
export
function
normalizeAppConfigService
(
pagesJson
:
UniApp
.
PagesJson
,
manifestJson
:
Record
<
string
,
any
>
...
...
packages/uni-cli-shared/src/vite/plugins/dynamicImportPolyfill.ts
0 → 100644
浏览文件 @
c87b1289
import
type
{
Plugin
}
from
'
vite
'
export
function
dynamicImportPolyfill
():
Plugin
{
return
{
name
:
'
dynamic-import-polyfill
'
,
renderDynamicImport
()
{
return
{
left
:
'
(
'
,
right
:
'
)
'
,
}
},
}
}
packages/uni-cli-shared/src/vite/plugins/index.ts
浏览文件 @
c87b1289
...
...
@@ -4,6 +4,7 @@ export * from './inject'
export
*
from
'
./mainJs
'
export
*
from
'
./jsonJs
'
export
*
from
'
./console
'
export
*
from
'
./dynamicImportPolyfill
'
export
{
assetPlugin
,
getAssetHash
}
from
'
./vitejs/plugins/asset
'
export
{
...
...
packages/uni-mp-vite/src/plugin/build.ts
浏览文件 @
c87b1289
...
...
@@ -14,8 +14,9 @@ import {
isCSSRequest
,
parseManifestJsonOnce
,
M
,
dynamicImportPolyfill
,
}
from
'
@dcloudio/uni-cli-shared
'
import
{
GetManualChunk
,
GetModuleInfo
,
P
lugin
,
P
reRenderedChunk
}
from
'
rollup
'
import
{
GetManualChunk
,
GetModuleInfo
,
PreRenderedChunk
}
from
'
rollup
'
import
{
isUniComponentUrl
,
isUniPageUrl
,
...
...
@@ -191,18 +192,6 @@ function createChunkFileNames(
}
}
function
dynamicImportPolyfill
():
Plugin
{
return
{
name
:
'
dynamic-import-polyfill
'
,
renderDynamicImport
()
{
return
{
left
:
'
(
'
,
right
:
'
)
'
,
}
},
}
}
export
function
notFound
(
filename
:
string
):
never
{
console
.
log
()
console
.
error
(
M
[
'
file.notfound
'
].
replace
(
'
{file}
'
,
filename
))
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录