Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lzb_79
uni-app
提交
9d004089
U
uni-app
项目概览
lzb_79
/
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,体验更适合开发者的 AI 搜索 >>
提交
9d004089
编写于
10月 09, 2021
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
wip(mp): pages.json
上级
5485f47f
变更
23
隐藏空白更改
内联
并排
Showing
23 changed file
with
377 addition
and
230 deletion
+377
-230
packages/uni-app-vite/src/plugin/configResolved.ts
packages/uni-app-vite/src/plugin/configResolved.ts
+7
-1
packages/uni-cli-shared/src/checkUpdate.ts
packages/uni-cli-shared/src/checkUpdate.ts
+56
-37
packages/uni-cli-shared/src/vite/index.ts
packages/uni-cli-shared/src/vite/index.ts
+2
-1
packages/uni-cli-shared/src/vite/plugins/css.ts
packages/uni-cli-shared/src/vite/plugins/css.ts
+0
-114
packages/uni-cli-shared/src/vite/plugins/index.ts
packages/uni-cli-shared/src/vite/plugins/index.ts
+1
-2
packages/uni-cli-shared/src/vite/plugins/vitejs/plugins/css.ts
...ges/uni-cli-shared/src/vite/plugins/vitejs/plugins/css.ts
+5
-6
packages/uni-cli-shared/src/vite/utils/plugin.ts
packages/uni-cli-shared/src/vite/utils/plugin.ts
+5
-2
packages/uni-mp-compiler/src/codegen.ts
packages/uni-mp-compiler/src/codegen.ts
+1
-1
packages/uni-mp-vite/package.json
packages/uni-mp-vite/package.json
+0
-5
packages/uni-mp-vite/src/index.ts
packages/uni-mp-vite/src/index.ts
+11
-7
packages/uni-mp-vite/src/plugin/build.ts
packages/uni-mp-vite/src/plugin/build.ts
+82
-8
packages/uni-mp-vite/src/plugin/configResolved.ts
packages/uni-mp-vite/src/plugin/configResolved.ts
+3
-1
packages/uni-mp-vite/src/plugin/index.ts
packages/uni-mp-vite/src/plugin/index.ts
+24
-13
packages/uni-mp-vite/src/plugin/uni/index.ts
packages/uni-mp-vite/src/plugin/uni/index.ts
+4
-0
packages/uni-mp-vite/src/plugins/mainJs.ts
packages/uni-mp-vite/src/plugins/mainJs.ts
+3
-1
packages/uni-mp-vite/src/plugins/pagesJson.ts
packages/uni-mp-vite/src/plugins/pagesJson.ts
+18
-4
packages/uni-mp-vite/src/plugins/virtual.ts
packages/uni-mp-vite/src/plugins/virtual.ts
+72
-0
packages/uni-mp-weixin/build.json
packages/uni-mp-weixin/build.json
+35
-24
packages/uni-mp-weixin/dist/uni.compiler.js
packages/uni-mp-weixin/dist/uni.compiler.js
+17
-0
packages/uni-mp-weixin/package.json
packages/uni-mp-weixin/package.json
+3
-1
packages/uni-mp-weixin/src/plugin/index.ts
packages/uni-mp-weixin/src/plugin/index.ts
+11
-0
packages/vite-plugin-uni/src/utils/plugin.ts
packages/vite-plugin-uni/src/utils/plugin.ts
+7
-0
packages/vite-plugin-uni/src/vue/options.ts
packages/vite-plugin-uni/src/vue/options.ts
+10
-2
未找到文件。
packages/uni-app-vite/src/plugin/configResolved.ts
浏览文件 @
9d004089
import
fs
from
'
fs
'
import
{
Plugin
}
from
'
vite
'
import
{
...
...
@@ -10,6 +11,11 @@ import {
export
const
configResolved
:
Plugin
[
'
configResolved
'
]
=
(
config
)
=>
{
removePlugins
(
'
vite:import-analysis
'
,
config
)
injectCssPlugin
(
config
)
injectCssPostPlugin
(
config
)
injectCssPostPlugin
(
config
,
{
appCss
:
fs
.
readFileSync
(
require
.
resolve
(
'
@dcloudio/uni-app-plus/dist/style.css
'
),
'
utf8
'
),
})
injectAssetPlugin
(
config
)
}
packages/uni-cli-shared/src/checkUpdate.ts
浏览文件 @
9d004089
import
fs
from
'
fs
'
import
fs
from
'
fs
-extra
'
import
os
from
'
os
'
import
path
from
'
path
'
import
debug
from
'
debug
'
...
...
@@ -10,7 +10,7 @@ import { hasOwn, isString, isPlainObject } from '@vue/shared'
import
{
parseManifestJsonOnce
}
from
'
./json
'
import
{
isInHBuilderX
}
from
'
./hbx
'
const
debugCheckUpdate
=
debug
(
'
uni:check-update
'
)
const
debugCheckUpdate
=
debug
(
'
vite:
uni:check-update
'
)
interface
CheckUpdateOptions
{
inputDir
:
string
...
...
@@ -63,6 +63,7 @@ export async function checkUpdate(options: CheckUpdateOptions) {
}
const
{
inputDir
,
compilerVersion
}
=
options
const
updateCache
=
readCheckUpdateCache
(
inputDir
)
debugCheckUpdate
(
'
read.cache
'
,
updateCache
)
const
res
=
checkLocalCache
(
updateCache
,
compilerVersion
)
if
(
res
)
{
if
(
isString
(
res
))
{
...
...
@@ -104,10 +105,12 @@ function normalizeUpdateCache(
}
function
statUpdateCache
(
updateCache
:
CheckUpdateCache
)
{
debugCheckUpdate
(
'
stat.before
'
,
updateCache
)
const
platform
=
process
.
env
.
UNI_PLATFORM
const
type
=
process
.
env
.
NODE_ENV
===
'
production
'
?
'
build
'
:
'
dev
'
const
platformOptions
=
updateCache
[
platform
]
as
CheckUpdatePlatform
platformOptions
[
type
]
=
(
platformOptions
[
type
]
||
0
)
+
1
debugCheckUpdate
(
'
stat.after
'
,
updateCache
)
return
updateCache
}
...
...
@@ -140,7 +143,9 @@ function readCheckUpdateCache(inputDir: string) {
if
(
fs
.
existsSync
(
updateFilepath
))
{
try
{
return
require
(
updateFilepath
)
as
CheckUpdateCache
}
catch
(
e
)
{}
}
catch
(
e
)
{
debugCheckUpdate
(
'
read.error
'
,
e
)
}
}
return
createCheckUpdateCache
()
}
...
...
@@ -182,8 +187,10 @@ function writeCheckUpdateCache(
const
filepath
=
getCheckUpdateFilepath
(
inputDir
)
debugCheckUpdate
(
'
write:
'
,
filepath
,
updateCache
)
try
{
fs
.
writeFileSync
(
filepath
,
JSON
.
stringify
(
updateCache
))
}
catch
(
e
)
{}
fs
.
outputFileSync
(
filepath
,
JSON
.
stringify
(
updateCache
))
}
catch
(
e
:
any
)
{
debugCheckUpdate
(
'
write.error
'
,
e
)
}
}
export
function
md5
(
str
:
string
)
{
...
...
@@ -265,37 +272,49 @@ function checkVersion(
options
:
CheckUpdateOptions
,
updateCache
:
CheckUpdateCache
)
{
const
postData
=
createPostData
(
options
,
parseManifestJsonOnce
(
options
.
inputDir
),
updateCache
)
let
responseData
=
''
const
req
=
request
(
{
hostname
:
HOSTNAME
,
path
:
PATH
,
port
:
443
,
method
:
'
POST
'
,
headers
:
{
'
Content-Type
'
:
'
application/json
'
,
'
Content-Length
'
:
postData
.
length
,
return
new
Promise
((
resolve
)
=>
{
const
postData
=
JSON
.
stringify
({
id
:
createPostData
(
options
,
parseManifestJsonOnce
(
options
.
inputDir
),
updateCache
),
})
let
responseData
=
''
const
req
=
request
(
{
hostname
:
HOSTNAME
,
path
:
PATH
,
port
:
443
,
method
:
'
POST
'
,
headers
:
{
'
Content-Type
'
:
'
application/json
'
,
'
Content-Length
'
:
postData
.
length
,
},
},
},
(
res
)
=>
{
res
.
setEncoding
(
'
utf8
'
)
res
.
on
(
'
data
'
,
(
chunk
)
=>
{
responseData
+=
chunk
})
res
.
on
(
'
end
'
,
()
=>
{
debugCheckUpdate
(
'
response:
'
,
responseData
)
try
{
handleCheckVersion
(
JSON
.
parse
(
responseData
),
updateCache
)
}
catch
(
e
)
{}
})
}
)
debugCheckUpdate
(
'
request:
'
,
postData
)
req
.
write
(
postData
)
req
.
end
()
(
res
)
=>
{
res
.
setEncoding
(
'
utf8
'
)
res
.
on
(
'
data
'
,
(
chunk
)
=>
{
responseData
+=
chunk
})
res
.
on
(
'
end
'
,
()
=>
{
debugCheckUpdate
(
'
response:
'
,
responseData
)
try
{
handleCheckVersion
(
JSON
.
parse
(
responseData
),
updateCache
)
}
catch
(
e
)
{}
resolve
(
true
)
})
res
.
on
(
'
error
'
,
(
e
)
=>
{
debugCheckUpdate
(
'
response.error:
'
,
e
)
resolve
(
false
)
})
}
).
on
(
'
error
'
,
(
e
)
=>
{
debugCheckUpdate
(
'
request.error:
'
,
e
)
resolve
(
false
)
})
debugCheckUpdate
(
'
request:
'
,
postData
)
req
.
write
(
postData
)
req
.
end
()
})
}
packages/uni-cli-shared/src/vite/index.ts
浏览文件 @
9d004089
import
type
{
Plugin
}
from
'
vite
'
import
type
{
ParserOptions
}
from
'
@vue/compiler-core
'
import
type
{
CompilerOptions
}
from
'
@vue/compiler-sfc
'
import
type
{
CompilerOptions
,
TemplateCompiler
}
from
'
@vue/compiler-sfc
'
import
{
UniViteCopyPluginOptions
}
from
'
./plugins/copy
'
export
interface
CopyOptions
{
/**
...
...
@@ -11,6 +11,7 @@ export interface CopyOptions {
}
interface
UniVitePluginUniOptions
{
compiler
?:
TemplateCompiler
compilerOptions
?:
{
isNativeTag
:
ParserOptions
[
'
isNativeTag
'
]
isCustomElement
:
ParserOptions
[
'
isCustomElement
'
]
...
...
packages/uni-cli-shared/src/vite/plugins/css.ts
已删除
100644 → 0
浏览文件 @
5485f47f
import
path
from
'
path
'
import
debug
from
'
debug
'
import
{
Plugin
}
from
'
vite
'
import
{
normalizePath
,
resolveMainPathOnce
}
from
'
../../utils
'
import
{
EXTNAME_VUE_RE
}
from
'
../../constants
'
const
cssLangs
=
`\\.(css|less|sass|scss|styl|stylus|pcss|postcss)($|\\?)`
const
cssLangRE
=
new
RegExp
(
cssLangs
)
// const cssModuleRE = new RegExp(`\\.module${cssLangs}`)
// const directRequestRE = /(\?|&)direct\b/
const
commonjsProxyRE
=
/
\?
commonjs-proxy/
const
debugCss
=
debug
(
'
vite:uni:css
'
)
// const isCSSRequest = (request: string): boolean =>
// cssLangRE.test(request) && !directRequestRE.test(request)
const
isCss
=
(
id
:
string
):
boolean
=>
cssLangRE
.
test
(
id
)
&&
!
commonjsProxyRE
.
test
(
id
)
function
normalizeCssChunkFilename
(
id
:
string
)
{
return
normalizePath
(
path
.
relative
(
process
.
env
.
UNI_INPUT_DIR
,
id
.
split
(
'
?
'
)[
0
].
replace
(
EXTNAME_VUE_RE
,
'
.css
'
)
)
)
}
interface
UniCssPluginOptions
{
/**
* 额外的全局样式
*/
app
:
string
}
export
function
uniCssPlugin
({
app
}:
UniCssPluginOptions
):
Plugin
{
const
styles
:
Map
<
string
,
string
>
=
new
Map
<
string
,
string
>
()
let
cssChunks
:
Map
<
string
,
Set
<
string
>>
return
{
name
:
'
vite:uni-app-css
'
,
buildStart
()
{
cssChunks
=
new
Map
<
string
,
Set
<
string
>>
()
},
transform
(
css
,
id
)
{
if
(
!
isCss
(
id
))
{
return
}
debugCss
(
id
)
styles
.
set
(
id
,
css
)
return
{
code
:
''
,
map
:
{
mappings
:
''
},
moduleSideEffects
:
'
no-treeshake
'
,
}
},
async
generateBundle
()
{
const
findCssModuleIds
=
(
moduleId
:
string
,
cssModuleIds
?:
Set
<
string
>
)
=>
{
if
(
!
cssModuleIds
)
{
cssModuleIds
=
new
Set
<
string
>
()
}
const
moduleInfo
=
this
.
getModuleInfo
(
moduleId
)
if
(
moduleInfo
)
{
moduleInfo
.
importedIds
.
forEach
((
id
)
=>
{
if
(
id
.
includes
(
'
pages.json.js
'
))
{
// 查询main.js时,需要忽略pages.json.js,否则会把所有页面样式加进来
return
}
if
(
isCss
(
id
))
{
cssModuleIds
!
.
add
(
id
)
}
else
{
findCssModuleIds
(
id
,
cssModuleIds
)
}
})
}
return
cssModuleIds
}
const
moduleIds
=
Array
.
from
(
this
.
getModuleIds
())
const
mainPath
=
resolveMainPathOnce
(
process
.
env
.
UNI_INPUT_DIR
)
moduleIds
.
forEach
((
id
)
=>
{
if
(
id
===
mainPath
)
{
// 全局样式
cssChunks
.
set
(
'
app.css
'
,
findCssModuleIds
(
id
))
}
else
if
(
id
.
includes
(
'
mpType=page
'
))
{
// 页面样式
cssChunks
.
set
(
normalizeCssChunkFilename
(
id
),
findCssModuleIds
(
id
))
}
})
if
(
!
cssChunks
.
size
)
{
return
}
const
genCssCode
=
(
fileName
:
string
)
=>
{
return
[...
cssChunks
.
get
(
fileName
)
!
]
.
map
((
id
)
=>
styles
.
get
(
id
)
||
''
)
.
join
(
'
\n
'
)
}
for
(
const
fileName
of
cssChunks
.
keys
())
{
let
source
=
(
fileName
===
'
app.css
'
?
app
+
'
\n
'
:
''
)
+
genCssCode
(
fileName
)
// if (resolvedConfig.build.minify) {
// source = await minifyCSS(source, resolvedConfig)
// }
this
.
emitFile
({
fileName
,
type
:
'
asset
'
,
source
,
})
}
},
}
}
packages/uni-cli-shared/src/vite/plugins/index.ts
浏览文件 @
9d004089
export
*
from
'
./css
'
export
*
from
'
./cssScoped
'
export
*
from
'
./copy
'
export
*
from
'
./inject
'
...
...
@@ -7,4 +6,4 @@ export * from './jsonJs'
export
*
from
'
./console
'
export
{
assetPlugin
}
from
'
./vitejs/plugins/asset
'
export
{
cssPlugin
,
cssPostPlugin
}
from
'
./vitejs/plugins/css
'
export
{
isCSSRequest
,
cssPlugin
,
cssPostPlugin
}
from
'
./vitejs/plugins/css
'
packages/uni-cli-shared/src/vite/plugins/vitejs/plugins/css.ts
浏览文件 @
9d004089
...
...
@@ -226,14 +226,13 @@ function findCssModuleIds(
/**
* Plugin applied after user plugins
*/
export
function
cssPostPlugin
(
config
:
ResolvedConfig
):
Plugin
{
export
function
cssPostPlugin
(
config
:
ResolvedConfig
,
{
appCss
}:
{
appCss
?:
string
}
):
Plugin
{
// styles initialization in buildStart causes a styling loss in watch
const
styles
:
Map
<
string
,
string
>
=
new
Map
<
string
,
string
>
()
let
cssChunks
:
Map
<
string
,
Set
<
string
>>
const
viewCssCode
=
fs
.
readFileSync
(
require
.
resolve
(
'
@dcloudio/uni-app-plus/dist/style.css
'
),
'
utf8
'
)
return
{
name
:
'
vite:css-post
'
,
buildStart
()
{
...
...
@@ -305,7 +304,7 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin {
}
for
(
const
filename
of
cssChunks
.
keys
())
{
let
source
=
await
processChunkCSS
(
(
filename
===
'
app.css
'
?
viewCssCode
+
'
\n
'
:
''
)
+
(
filename
===
'
app.css
'
?
(
appCss
||
''
)
+
'
\n
'
:
''
)
+
genCssCode
(
filename
),
{
dirname
:
path
.
dirname
(
filename
),
inlined
:
false
,
minify
:
true
}
)
...
...
packages/uni-cli-shared/src/vite/utils/plugin.ts
浏览文件 @
9d004089
...
...
@@ -17,8 +17,11 @@ export function injectCssPlugin(config: ResolvedConfig) {
replacePlugins
([
cssPlugin
(
config
)],
config
)
}
export
function
injectCssPostPlugin
(
config
:
ResolvedConfig
)
{
replacePlugins
([
cssPostPlugin
(
config
)],
config
)
export
function
injectCssPostPlugin
(
config
:
ResolvedConfig
,
{
appCss
}:
{
appCss
?:
string
}
)
{
replacePlugins
([
cssPostPlugin
(
config
,
{
appCss
})],
config
)
}
export
function
replacePlugins
(
plugins
:
Plugin
[],
config
:
ResolvedConfig
)
{
...
...
packages/uni-mp-compiler/src/codegen.ts
浏览文件 @
9d004089
...
...
@@ -32,7 +32,7 @@ export function generate(
if
(
isSetupInlined
)
{
codes
.
push
(
`(
${
signature
}
) => {`
)
}
else
{
codes
.
push
(
`function
${
functionName
}
(
${
signature
}
) {`
)
codes
.
push
(
`
\nexport
function
${
functionName
}
(
${
signature
}
) {`
)
}
codes
.
push
(
`return `
+
...
...
packages/uni-mp-vite/package.json
浏览文件 @
9d004089
...
...
@@ -17,11 +17,6 @@
"scripts"
:
{
"test"
:
"echo
\"
Error: no test specified
\"
&& exit 1"
},
"uni-app"
:
{
"name"
:
"uni-mp"
,
"apply"
:
"^mp-"
,
"main"
:
"dist/index.js"
},
"license"
:
"Apache-2.0"
,
"gitHead"
:
"453a3e6ead807864087692f4339ea3d667045fe7"
}
packages/uni-mp-vite/src/index.ts
浏览文件 @
9d004089
import
{
UniMpPlugin
}
from
'
./plugin
'
import
{
uniMiniProgramPlugin
,
UniMiniProgramPluginOptions
}
from
'
./plugin
'
import
{
uniMainJsPlugin
}
from
'
./plugins/mainJs
'
import
{
uniManifestJsonPlugin
}
from
'
./plugins/manifestJson
'
import
{
uniPagesJsonPlugin
}
from
'
./plugins/pagesJson
'
export
default
[
uniMainJsPlugin
(),
uniManifestJsonPlugin
(),
uniPagesJsonPlugin
(),
UniMpPlugin
,
]
import
{
uniVirtualPlugin
}
from
'
./plugins/virtual
'
export
default
(
options
:
UniMiniProgramPluginOptions
)
=>
{
return
[
uniMainJsPlugin
(),
uniManifestJsonPlugin
(),
uniPagesJsonPlugin
(),
uniVirtualPlugin
(
options
),
uniMiniProgramPlugin
(
options
),
]
}
packages/uni-mp-vite/src/plugin/build.ts
浏览文件 @
9d004089
import
path
from
'
path
'
import
{
UserConfig
}
from
'
vite
'
import
{
normalizePath
,
resolveMainPathOnce
}
from
'
@dcloudio/uni-cli-shared
'
import
{
isCSSRequest
,
normalizePath
,
resolveMainPathOnce
,
}
from
'
@dcloudio/uni-cli-shared
'
import
{
GetManualChunk
,
GetModuleInfo
}
from
'
rollup
'
import
{
isUniComponentUrl
,
isUniPageUrl
,
parseVirtualComponentPath
,
parseVirtualPagePath
,
}
from
'
../plugins/virtual
'
export
function
buildOptions
():
UserConfig
[
'
build
'
]
{
const
inputDir
=
process
.
env
.
UNI_INPUT_DIR
return
{
// sourcemap: 'inline', // TODO
assetsInlineLimit
:
0
,
// TODO
lib
:
{
entry
:
resolveMainPathOnce
(
inputDir
),
formats
:
[
'
cjs
'
],
},
rollupOptions
:
{
input
:
resolveMainPathOnce
(
process
.
env
.
UNI_INPUT_DIR
),
output
:
{
format
:
'
c
js
'
,
entryFileNames
:
'
main.js
'
,
entryFileNames
:
'
app.
js
'
,
manualChunks
:
createMoveToVendorChunkFn
()
,
chunkFileNames
(
chunk
)
{
if
(
chunk
.
isDynamicEntry
&&
chunk
.
facadeModuleId
)
{
const
filepath
=
path
.
relative
(
process
.
env
.
UNI_INPUT_DIR
,
chunk
.
facadeModuleId
)
let
id
=
chunk
.
facadeModuleId
if
(
isUniPageUrl
(
id
))
{
id
=
path
.
resolve
(
process
.
env
.
UNI_INPUT_DIR
,
parseVirtualPagePath
(
id
)
)
}
else
if
(
isUniComponentUrl
(
id
))
{
id
=
path
.
resolve
(
process
.
env
.
UNI_INPUT_DIR
,
parseVirtualComponentPath
(
id
)
)
}
const
filepath
=
path
.
relative
(
inputDir
,
id
)
return
normalizePath
(
filepath
.
replace
(
path
.
extname
(
filepath
),
'
.js
'
)
)
...
...
@@ -29,3 +53,53 @@ export function buildOptions(): UserConfig['build'] {
},
}
}
function
createMoveToVendorChunkFn
():
GetManualChunk
{
const
cache
=
new
Map
<
string
,
boolean
>
()
return
(
id
,
{
getModuleInfo
})
=>
{
if
(
(
id
.
includes
(
'
node_modules
'
)
||
id
.
includes
(
'
plugin-vue:export-helper
'
))
&&
!
isCSSRequest
(
id
)
&&
staticImportedByEntry
(
id
,
getModuleInfo
,
cache
)
)
{
return
'
vendor
'
}
}
}
function
staticImportedByEntry
(
id
:
string
,
getModuleInfo
:
GetModuleInfo
,
cache
:
Map
<
string
,
boolean
>
,
importStack
:
string
[]
=
[]
):
boolean
{
if
(
cache
.
has
(
id
))
{
return
cache
.
get
(
id
)
as
boolean
}
if
(
importStack
.
includes
(
id
))
{
// circular deps!
cache
.
set
(
id
,
false
)
return
false
}
const
mod
=
getModuleInfo
(
id
)
if
(
!
mod
)
{
cache
.
set
(
id
,
false
)
return
false
}
if
(
mod
.
isEntry
)
{
cache
.
set
(
id
,
true
)
return
true
}
const
someImporterIs
=
mod
.
importers
.
some
((
importer
)
=>
staticImportedByEntry
(
importer
,
getModuleInfo
,
cache
,
importStack
.
concat
(
id
)
)
)
cache
.
set
(
id
,
someImporterIs
)
return
someImporterIs
}
packages/uni-mp-vite/src/plugin/configResolved.ts
浏览文件 @
9d004089
...
...
@@ -10,6 +10,8 @@ import {
export
const
configResolved
:
Plugin
[
'
configResolved
'
]
=
(
config
)
=>
{
removePlugins
(
'
vite:import-analysis
'
,
config
)
injectCssPlugin
(
config
)
injectCssPostPlugin
(
config
)
injectCssPostPlugin
(
config
,
{
appCss
:
''
,
})
injectAssetPlugin
(
config
)
}
packages/uni-mp-vite/src/plugin/index.ts
浏览文件 @
9d004089
import
{
AliasOptions
}
from
'
vite
'
import
{
resolveBuiltIn
,
UniVitePlugin
}
from
'
@dcloudio/uni-cli-shared
'
import
{
uniOptions
}
from
'
./uni
'
import
{
buildOptions
}
from
'
./build
'
import
{
configResolved
}
from
'
./configResolved
'
export
const
UniMpPlugin
:
UniVitePlugin
=
{
name
:
'
vite:uni-mp
'
,
uni
:
uniOptions
(),
config
()
{
return
{
resolve
:
{
alias
:
{
vue
:
resolveBuiltIn
(
'
@dcloudio/uni-mp-vue
'
),
export
interface
UniMiniProgramPluginOptions
{
global
:
string
alias
?:
AliasOptions
}
export
function
uniMiniProgramPlugin
({
alias
,
}:
UniMiniProgramPluginOptions
):
UniVitePlugin
{
return
{
name
:
'
vite:uni-mp
'
,
uni
:
uniOptions
(),
config
()
{
return
{
resolve
:
{
alias
:
{
vue
:
resolveBuiltIn
(
'
@dcloudio/uni-mp-vue
'
),
...
alias
,
},
},
}
,
build
:
buildOptions
(),
}
}
,
configResolved
,
build
:
buildOptions
()
,
}
}
,
configResolved
,
}
}
packages/uni-mp-vite/src/plugin/uni/index.ts
浏览文件 @
9d004089
...
...
@@ -3,9 +3,13 @@ import {
isServiceCustomElement
,
}
from
'
@dcloudio/uni-shared
'
import
{
UniVitePlugin
}
from
'
@dcloudio/uni-cli-shared
'
import
{
TemplateCompiler
}
from
'
@vue/compiler-sfc
'
import
*
as
compiler
from
'
@dcloudio/uni-mp-compiler
'
export
function
uniOptions
():
UniVitePlugin
[
'
uni
'
]
{
return
{
compiler
:
compiler
as
TemplateCompiler
,
compilerOptions
:
{
isNativeTag
:
isServiceNativeTag
,
isCustomElement
:
isServiceCustomElement
,
...
...
packages/uni-mp-vite/src/plugins/mainJs.ts
浏览文件 @
9d004089
...
...
@@ -11,7 +11,9 @@ export function uniMainJsPlugin() {
?
createApp
(
code
)
:
createLegacyApp
(
code
)
return
{
code
:
`import './pages.json.js';`
+
code
,
code
:
`import 'plugin-vue:export-helper';import 'uni-mp-runtime';import './pages.json.js';`
+
code
,
map
:
this
.
getCombinedSourcemap
(),
}
}
...
...
packages/uni-mp-vite/src/plugins/pagesJson.ts
浏览文件 @
9d004089
...
...
@@ -3,12 +3,11 @@ import { Plugin } from 'vite'
import
{
defineUniPagesJsonPlugin
,
normalizeAppPagesJson
,
// normalizeAppConfigService,
normalizePagesJson
,
// parseManifestJsonOnce,
getLocaleFiles
,
normalizePagePath
,
}
from
'
@dcloudio/uni-cli-shared
'
import
{
virtualPagePath
}
from
'
./virtual
'
export
function
uniPagesJsonPlugin
():
Plugin
{
let
pagesJson
:
UniApp
.
PagesJson
...
...
@@ -35,7 +34,8 @@ export function uniPagesJsonPlugin(): Plugin {
})
return
{
code
:
`import './manifest.json.js'\n`
+
normalizeAppPagesJson
(
pagesJson
),
`import './manifest.json.js'\n`
+
normalizeMiniProgramPagesJson
(
pagesJson
),
map
:
this
.
getCombinedSourcemap
(),
}
},
...
...
@@ -52,3 +52,17 @@ export function uniPagesJsonPlugin(): Plugin {
}
})
}
function
normalizeMiniProgramPagesJson
(
pagesJson
:
Record
<
string
,
any
>
)
{
const
importPagesCode
:
string
[]
=
[]
pagesJson
.
pages
.
forEach
((
page
:
UniApp
.
PagesJsonPageOptions
)
=>
{
const
pagePath
=
page
.
path
const
pagePathWithExtname
=
normalizePagePath
(
pagePath
,
'
app
'
)
if
(
pagePathWithExtname
)
{
importPagesCode
.
push
(
`import('
${
virtualPagePath
(
pagePathWithExtname
)}
')`
)
}
})
return
`if(!Math){
${
importPagesCode
.
join
(
'
\n
'
)}
}`
}
packages/uni-mp-vite/src/plugins/virtual.ts
0 → 100644
浏览文件 @
9d004089
import
path
from
'
path
'
import
{
normalizePath
}
from
'
@dcloudio/uni-cli-shared
'
import
{
Plugin
}
from
'
vite
'
import
{
UniMiniProgramPluginOptions
}
from
'
../plugin
'
function
encode
(
str
:
string
)
{
return
Buffer
.
from
(
str
).
toString
(
'
base64url
'
)
}
function
decode
(
str
:
string
)
{
return
Buffer
.
from
(
str
,
'
base64url
'
).
toString
()
}
const
uniPagePrefix
=
'
uniPage://
'
const
uniComponentPrefix
=
'
uniComponent://
'
export
function
virtualPagePath
(
filepath
:
string
)
{
return
uniPagePrefix
+
encode
(
filepath
)
}
export
function
virtualComponentPath
(
filepath
:
string
)
{
return
uniComponentPrefix
+
encode
(
filepath
)
}
export
function
parseVirtualPagePath
(
uniPageUrl
:
string
)
{
return
decode
(
uniPageUrl
.
replace
(
uniPagePrefix
,
''
))
}
export
function
parseVirtualComponentPath
(
uniComponentUrl
:
string
)
{
return
decode
(
uniComponentUrl
.
replace
(
uniComponentPrefix
,
''
))
}
export
function
isUniPageUrl
(
id
:
string
)
{
return
id
.
startsWith
(
uniPagePrefix
)
}
export
function
isUniComponentUrl
(
id
:
string
)
{
return
id
.
startsWith
(
uniComponentPrefix
)
}
export
function
uniVirtualPlugin
({
global
,
}:
UniMiniProgramPluginOptions
):
Plugin
{
const
inputDir
=
process
.
env
.
UNI_INPUT_DIR
return
{
name
:
'
vite:uni-virtual
'
,
enforce
:
'
pre
'
,
resolveId
(
id
)
{
if
(
isUniPageUrl
(
id
)
||
isUniComponentUrl
(
id
))
{
return
id
}
},
load
(
id
)
{
if
(
isUniPageUrl
(
id
))
{
const
filepath
=
normalizePath
(
path
.
resolve
(
inputDir
,
parseVirtualPagePath
(
id
))
)
return
{
code
:
`import Page from '
${
filepath
}
?mpType=page'
${
global
}
.createPage(Page)`
,
}
}
else
if
(
isUniComponentUrl
(
id
))
{
const
filepath
=
normalizePath
(
path
.
resolve
(
inputDir
,
parseVirtualComponentPath
(
id
))
)
return
{
code
:
`import Component from '
${
filepath
}
'
${
global
}
.createComponent(Component)`
,
}
}
},
}
}
packages/uni-mp-weixin/build.json
浏览文件 @
9d004089
{
"input"
:
{
"src/runtime/index.ts"
:
"dist/uni.mp.esm.js"
,
"src/api/index.ts"
:
"dist/uni.api.esm.js"
[
{
"input"
:
{
"src/plugin/index.ts"
:
"dist/uni.compiler.js"
},
"output"
:
{
"format"
:
"cjs"
},
"external"
:
[
"@dcloudio/uni-cli-shared"
,
"@dcloudio/uni-mp-vite"
]
},
"alias"
:
{
"entries"
:
[
{
"find"
:
"@dcloudio/uni-platform"
,
"replacement"
:
"packages/uni-mp-weixin/src/platform/index.ts"
},
{
"find"
:
"@dcloudio/uni-mp-platform"
,
"replacement"
:
"packages/uni-mp-core/src/platform/index.ts"
}
]
},
"replacements"
:
{
"global"
:
"global"
,
"__GLOBAL__"
:
"wx"
,
"__PLATFORM__"
:
"
\"
mp-weixin
\"
"
,
"__PLATFORM_TITLE__"
:
"微信小程序"
},
"external"
:
[
"@dcloudio/uni-i18n"
,
"@vue/shared"
,
"vue"
]
}
{
"input"
:
{
"src/runtime/index.ts"
:
"dist/uni.mp.esm.js"
,
"src/api/index.ts"
:
"dist/uni.api.esm.js"
},
"alias"
:
{
"entries"
:
[
{
"find"
:
"@dcloudio/uni-platform"
,
"replacement"
:
"packages/uni-mp-weixin/src/platform/index.ts"
},
{
"find"
:
"@dcloudio/uni-mp-platform"
,
"replacement"
:
"packages/uni-mp-core/src/platform/index.ts"
}
]
},
"replacements"
:
{
"global"
:
"global"
,
"__GLOBAL__"
:
"wx"
,
"__PLATFORM__"
:
"
\"
mp-weixin
\"
"
,
"__PLATFORM_TITLE__"
:
"微信小程序"
},
"external"
:
[
"@dcloudio/uni-i18n"
,
"@vue/shared"
,
"vue"
]
}
]
packages/uni-mp-weixin/dist/uni.compiler.js
0 → 100644
浏览文件 @
9d004089
'
use strict
'
;
var
uniCliShared
=
require
(
'
@dcloudio/uni-cli-shared
'
);
var
initMiniProgramPlugin
=
require
(
'
@dcloudio/uni-mp-vite
'
);
function
_interopDefaultLegacy
(
e
)
{
return
e
&&
typeof
e
===
'
object
'
&&
'
default
'
in
e
?
e
:
{
'
default
'
:
e
};
}
var
initMiniProgramPlugin__default
=
/*#__PURE__*/
_interopDefaultLegacy
(
initMiniProgramPlugin
);
var
index
=
initMiniProgramPlugin__default
[
"
default
"
]({
global
:
'
wx
'
,
alias
:
{
'
uni-mp-runtime
'
:
uniCliShared
.
resolveBuiltIn
(
'
@dcloudio/uni-mp-weixin/dist/uni.mp.esm.js
'
),
},
});
module
.
exports
=
index
;
packages/uni-mp-weixin/package.json
浏览文件 @
9d004089
...
...
@@ -18,7 +18,9 @@
"license"
:
"Apache-2.0"
,
"uni-app"
:
{
"name"
:
"mp-weixin"
,
"title"
:
"微信小程序"
"title"
:
"微信小程序"
,
"apply"
:
"mp-weixin"
,
"main"
:
"dist/uni.compiler.js"
},
"gitHead"
:
"453a3e6ead807864087692f4339ea3d667045fe7"
}
packages/uni-mp-weixin/src/plugin/index.ts
0 → 100644
浏览文件 @
9d004089
import
{
resolveBuiltIn
}
from
'
@dcloudio/uni-cli-shared
'
import
initMiniProgramPlugin
from
'
@dcloudio/uni-mp-vite
'
export
default
initMiniProgramPlugin
({
global
:
'
wx
'
,
alias
:
{
'
uni-mp-runtime
'
:
resolveBuiltIn
(
'
@dcloudio/uni-mp-weixin/dist/uni.mp.esm.js
'
),
},
})
packages/vite-plugin-uni/src/utils/plugin.ts
浏览文件 @
9d004089
...
...
@@ -7,6 +7,7 @@ import type {
UniViteCopyPluginTarget
,
UniVitePlugin
,
}
from
'
@dcloudio/uni-cli-shared
'
import
{
TemplateCompiler
}
from
'
@vue/compiler-sfc
'
interface
PluginConfig
{
id
:
string
...
...
@@ -26,12 +27,17 @@ export function initPluginUniOptions(UniVitePlugins: UniVitePlugin[]) {
isNativeTag
,
isCustomElement
,
}
let
compiler
:
TemplateCompiler
|
undefined
UniVitePlugins
.
forEach
((
plugin
)
=>
{
const
{
compiler
:
pluginTemplateCompiler
,
copyOptions
:
pluginCopyOptions
,
compilerOptions
:
pluginCompilerOptions
,
transformEvent
:
pluginTransformEvent
,
}
=
plugin
.
uni
||
{}
if
(
pluginTemplateCompiler
)
{
compiler
=
pluginTemplateCompiler
}
if
(
pluginCompilerOptions
)
{
if
(
pluginCompilerOptions
.
isNativeTag
)
{
compilerOptions
.
isNativeTag
=
pluginCompilerOptions
.
isNativeTag
...
...
@@ -61,6 +67,7 @@ export function initPluginUniOptions(UniVitePlugins: UniVitePlugin[]) {
}
})
return
{
compiler
,
copyOptions
:
{
assets
,
targets
,
...
...
packages/vite-plugin-uni/src/vue/options.ts
浏览文件 @
9d004089
import
{
extend
,
hasOwn
,
isArray
,
isPlainObject
}
from
'
@vue/shared
'
import
{
SFCTemplateCompileOptions
}
from
'
@vue/compiler-sfc
'
import
{
SFCTemplateCompileOptions
,
TemplateCompiler
}
from
'
@vue/compiler-sfc
'
import
{
isCustomElement
}
from
'
@dcloudio/uni-shared
'
import
{
EXTNAME_VUE_RE
,
...
...
@@ -38,7 +38,11 @@ function createUniVueTransformAssetUrls(
export
function
initPluginVueOptions
(
options
:
VitePluginUniResolvedOptions
,
UniVitePlugins
:
UniVitePlugin
[],
uniPluginOptions
:
Required
<
Required
<
UniVitePlugin
>
[
'
uni
'
]
>
uniPluginOptions
:
Required
<
Omit
<
Required
<
UniVitePlugin
>
[
'
uni
'
],
'
compiler
'
>
>
&
{
compiler
?:
TemplateCompiler
}
)
{
const
vueOptions
=
options
.
vueOptions
||
(
options
.
vueOptions
=
{})
if
(
!
vueOptions
.
include
)
{
...
...
@@ -66,6 +70,7 @@ export function initPluginVueOptions(
templateOptions
.
compilerOptions
||
(
templateOptions
.
compilerOptions
=
{})
const
{
compiler
,
compilerOptions
:
{
isNativeTag
,
isCustomElement
,
...
...
@@ -73,6 +78,9 @@ export function initPluginVueOptions(
directiveTransforms
,
},
}
=
uniPluginOptions
if
(
compiler
)
{
templateOptions
.
compiler
=
compiler
}
compilerOptions
.
isNativeTag
=
isNativeTag
compilerOptions
.
isCustomElement
=
isCustomElement
if
(
directiveTransforms
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录