Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
uni-app
提交
ad8e5058
U
uni-app
项目概览
DCloud
/
uni-app
6 个月 前同步成功
通知
751
Star
38709
Fork
3642
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
8
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
8
Issue
8
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
ad8e5058
编写于
12月 13, 2023
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
wip(uvue): iOS平台支持css解析
上级
d3e0c6f8
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
138 addition
and
89 deletion
+138
-89
packages/uni-app-uts/src/plugins/android/css.ts
packages/uni-app-uts/src/plugins/android/css.ts
+1
-1
packages/uni-app-uts/src/plugins/android/plugin.ts
packages/uni-app-uts/src/plugins/android/plugin.ts
+2
-40
packages/uni-app-uts/src/plugins/ios/css.ts
packages/uni-app-uts/src/plugins/ios/css.ts
+65
-0
packages/uni-app-uts/src/plugins/ios/plugin.ts
packages/uni-app-uts/src/plugins/ios/plugin.ts
+7
-37
packages/uni-app-uts/src/plugins/utils.ts
packages/uni-app-uts/src/plugins/utils.ts
+51
-0
packages/uni-cli-shared/src/vite/plugins/vitejs/plugins/asset.ts
...s/uni-cli-shared/src/vite/plugins/vitejs/plugins/asset.ts
+3
-3
packages/uni-cli-shared/src/vite/plugins/vitejs/plugins/css.ts
...ges/uni-cli-shared/src/vite/plugins/vitejs/plugins/css.ts
+3
-3
packages/uni-cli-shared/src/vite/utils/plugin.ts
packages/uni-cli-shared/src/vite/utils/plugin.ts
+1
-1
packages/vite-plugin-uni/src/configResolved/plugins/ssr.ts
packages/vite-plugin-uni/src/configResolved/plugins/ssr.ts
+1
-1
packages/vite-plugin-uni/src/vue/options.ts
packages/vite-plugin-uni/src/vue/options.ts
+4
-3
未找到文件。
packages/uni-app-uts/src/plugins/android/css.ts
浏览文件 @
ad8e5058
...
@@ -84,7 +84,7 @@ export function uniAppCssPlugin(): Plugin {
...
@@ -84,7 +84,7 @@ export function uniAppCssPlugin(): Plugin {
// 增加 css plugins
// 增加 css plugins
insertBeforePlugin
(
insertBeforePlugin
(
cssPlugin
(
config
,
{
cssPlugin
(
config
,
{
isA
pp
X
:
true
,
isA
ndroid
X
:
true
,
getDescriptor
:
(
filename
)
=>
{
getDescriptor
:
(
filename
)
=>
{
return
getDescriptor
(
filename
,
descriptorOptions
,
false
)
return
getDescriptor
(
filename
,
descriptorOptions
,
false
)
},
},
...
...
packages/uni-app-uts/src/plugins/android/plugin.ts
浏览文件 @
ad8e5058
...
@@ -10,10 +10,8 @@ import {
...
@@ -10,10 +10,8 @@ import {
resolveMainPathOnce
,
resolveMainPathOnce
,
resolveUTSCompiler
,
resolveUTSCompiler
,
utsPlugins
,
utsPlugins
,
injectAssetPlugin
,
AutoImportOptions
,
AutoImportOptions
,
}
from
'
@dcloudio/uni-cli-shared
'
}
from
'
@dcloudio/uni-cli-shared
'
import
type
{
Plugin
}
from
'
vite
'
import
{
import
{
DEFAULT_APPID
,
DEFAULT_APPID
,
parseImports
,
parseImports
,
...
@@ -28,36 +26,10 @@ import {
...
@@ -28,36 +26,10 @@ import {
createTryResolve
,
createTryResolve
,
}
from
'
./utils
'
}
from
'
./utils
'
import
{
getOutputManifestJson
}
from
'
./manifestJson
'
import
{
getOutputManifestJson
}
from
'
./manifestJson
'
import
{
createUniOptions
}
from
'
../utils
'
import
{
c
onfigResolved
,
c
reateUniOptions
}
from
'
../utils
'
const
uniCloudSpaceList
=
getUniCloudSpaceList
()
const
uniCloudSpaceList
=
getUniCloudSpaceList
()
const
REMOVED_PLUGINS
=
[
'
vite:build-metadata
'
,
'
vite:modulepreload-polyfill
'
,
'
vite:css
'
,
'
vite:esbuild
'
,
'
vite:wasm-helper
'
,
'
vite:worker
'
,
// 'vite:asset', // replace
'
vite:wasm-fallback
'
,
'
vite:define
'
,
'
vite:css-post
'
,
'
vite:build-html
'
,
'
vite:html-inline-proxy
'
,
'
vite:worker-import-meta-url
'
,
'
vite:asset-import-meta-url
'
,
'
vite:force-systemjs-wrap-complete
'
,
'
vite:watch-package-data
'
,
'
commonjs
'
,
'
vite:data-uri
'
,
'
vite:dynamic-import-vars
'
,
'
vite:import-glob
'
,
'
vite:build-import-analysis
'
,
'
vite:esbuild-transpile
'
,
'
vite:terser
'
,
'
vite:reporter
'
,
]
let
isFirst
=
true
let
isFirst
=
true
export
function
uniAppPlugin
(
options
:
{
export
function
uniAppPlugin
(
options
:
{
autoImportOptions
?:
AutoImportOptions
autoImportOptions
?:
AutoImportOptions
...
@@ -134,17 +106,7 @@ export function uniAppPlugin(options: {
...
@@ -134,17 +106,7 @@ export function uniAppPlugin(options: {
}
}
},
},
configResolved
(
config
)
{
configResolved
(
config
)
{
const
plugins
=
config
.
plugins
as
Plugin
[]
configResolved
(
config
,
true
)
const
len
=
plugins
.
length
for
(
let
i
=
len
-
1
;
i
>=
0
;
i
--
)
{
const
plugin
=
plugins
[
i
]
if
(
REMOVED_PLUGINS
.
includes
(
plugin
.
name
))
{
plugins
.
splice
(
i
,
1
)
}
}
// 强制不inline
config
.
build
.
assetsInlineLimit
=
0
injectAssetPlugin
(
config
,
{
isAppX
:
true
})
},
},
async
transform
(
code
,
id
)
{
async
transform
(
code
,
id
)
{
if
(
process
.
env
.
UNI_APP_X_TSC
===
'
true
'
)
{
if
(
process
.
env
.
UNI_APP_X_TSC
===
'
true
'
)
{
...
...
packages/uni-app-uts/src/plugins/ios/css.ts
0 → 100644
浏览文件 @
ad8e5058
import
type
{
Plugin
,
ResolvedConfig
}
from
'
vite
'
import
colors
from
'
picocolors
'
import
{
commonjsProxyRE
,
cssLangRE
,
formatAtFilename
,
generateCodeFrame
,
parseAssets
,
preUVueCss
,
}
from
'
@dcloudio/uni-cli-shared
'
import
{
parse
}
from
'
@dcloudio/uni-nvue-styler
'
export
function
uniAppCssPlugin
():
Plugin
{
let
resolvedConfig
:
ResolvedConfig
return
{
name
:
'
vite:css-post
'
,
configResolved
(
config
)
{
resolvedConfig
=
config
},
buildStart
()
{
// 用于覆盖原始插件方法
// noop
},
async
transform
(
source
,
filename
)
{
if
(
!
cssLangRE
.
test
(
filename
)
||
commonjsProxyRE
.
test
(
filename
))
{
return
}
if
(
source
.
includes
(
'
#endif
'
))
{
source
=
preUVueCss
(
source
)
}
source
=
parseAssets
(
resolvedConfig
,
source
)
// 仅做校验使用
const
{
messages
,
code
}
=
await
parse
(
source
,
{
filename
,
logLevel
:
'
WARNING
'
,
type
:
'
uvue
'
,
platform
:
process
.
env
.
UNI_UTS_PLATFORM
,
})
messages
.
forEach
((
message
)
=>
{
if
(
message
.
type
===
'
warning
'
)
{
// 拆分成多行,第一行输出信息(有颜色),后续输出错误代码+文件行号
resolvedConfig
.
logger
.
warn
(
colors
.
yellow
(
`[plugin:uni:app-uvue-css]
${
message
.
text
}
`
)
)
let
msg
=
''
if
(
message
.
line
&&
message
.
column
)
{
msg
+=
`\n
${
generateCodeFrame
(
source
,
{
line
:
message
.
line
,
column
:
message
.
column
,
}).
replace
(
/
\t
/g
,
'
'
)}
\n`
}
msg
+=
`
${
formatAtFilename
(
filename
)}
`
resolvedConfig
.
logger
.
warn
(
msg
)
}
})
return
{
code
:
`export default
${
code
}
`
,
map
:
{
mappings
:
''
}
}
},
generateBundle
()
{
// 用于覆盖原始插件方法
// noop
},
}
}
packages/uni-app-uts/src/plugins/ios/plugin.ts
浏览文件 @
ad8e5058
...
@@ -3,37 +3,12 @@ import {
...
@@ -3,37 +3,12 @@ import {
APP_SERVICE_FILENAME
,
APP_SERVICE_FILENAME
,
UniVitePlugin
,
UniVitePlugin
,
emptyDir
,
emptyDir
,
injectCssPlugin
,
injectCssPostPlugin
,
resolveMainPathOnce
,
resolveMainPathOnce
,
}
from
'
@dcloudio/uni-cli-shared
'
}
from
'
@dcloudio/uni-cli-shared
'
import
{
createUniOptions
}
from
'
../utils
'
import
{
configResolved
,
createUniOptions
}
from
'
../utils
'
import
type
{
Plugin
}
from
'
vite
'
import
{
uniAppCssPlugin
}
from
'
./css
'
const
REMOVED_PLUGINS
=
[
'
vite:build-metadata
'
,
'
vite:modulepreload-polyfill
'
,
'
vite:css
'
,
'
vite:esbuild
'
,
'
vite:wasm-helper
'
,
'
vite:worker
'
,
// 'vite:asset', // replace
'
vite:wasm-fallback
'
,
'
vite:define
'
,
'
vite:css-post
'
,
'
vite:build-html
'
,
'
vite:html-inline-proxy
'
,
'
vite:worker-import-meta-url
'
,
'
vite:asset-import-meta-url
'
,
'
vite:force-systemjs-wrap-complete
'
,
'
vite:watch-package-data
'
,
'
commonjs
'
,
'
vite:data-uri
'
,
'
vite:dynamic-import-vars
'
,
'
vite:import-glob
'
,
'
vite:build-import-analysis
'
,
'
vite:esbuild-transpile
'
,
'
vite:terser
'
,
'
vite:reporter
'
,
]
export
function
uniAppIOSPlugin
():
UniVitePlugin
{
export
function
uniAppIOSPlugin
():
UniVitePlugin
{
const
inputDir
=
process
.
env
.
UNI_INPUT_DIR
const
inputDir
=
process
.
env
.
UNI_INPUT_DIR
...
@@ -74,14 +49,9 @@ export function uniAppIOSPlugin(): UniVitePlugin {
...
@@ -74,14 +49,9 @@ export function uniAppIOSPlugin(): UniVitePlugin {
}
}
},
},
configResolved
(
config
)
{
configResolved
(
config
)
{
const
plugins
=
config
.
plugins
as
Plugin
[]
configResolved
(
config
)
const
len
=
plugins
.
length
injectCssPlugin
(
config
)
for
(
let
i
=
len
-
1
;
i
>=
0
;
i
--
)
{
injectCssPostPlugin
(
config
,
uniAppCssPlugin
())
const
plugin
=
plugins
[
i
]
if
(
REMOVED_PLUGINS
.
includes
(
plugin
.
name
))
{
plugins
.
splice
(
i
,
1
)
}
}
},
},
}
}
}
}
packages/uni-app-uts/src/plugins/utils.ts
浏览文件 @
ad8e5058
...
@@ -4,8 +4,10 @@ import {
...
@@ -4,8 +4,10 @@ import {
UniViteCopyPluginOptions
,
UniViteCopyPluginOptions
,
UniVitePlugin
,
UniVitePlugin
,
initI18nOptions
,
initI18nOptions
,
injectAssetPlugin
,
}
from
'
@dcloudio/uni-cli-shared
'
}
from
'
@dcloudio/uni-cli-shared
'
import
{
compileI18nJsonStr
}
from
'
@dcloudio/uni-i18n
'
import
{
compileI18nJsonStr
}
from
'
@dcloudio/uni-i18n
'
import
{
Plugin
,
ResolvedConfig
}
from
'
vite
'
export
function
createUniOptions
():
UniVitePlugin
[
'
uni
'
]
{
export
function
createUniOptions
():
UniVitePlugin
[
'
uni
'
]
{
return
{
return
{
...
@@ -45,3 +47,52 @@ export function isManifest(id: string) {
...
@@ -45,3 +47,52 @@ export function isManifest(id: string) {
export
function
isPages
(
id
:
string
)
{
export
function
isPages
(
id
:
string
)
{
return
id
.
endsWith
(
PAGES_JSON_UTS
)
return
id
.
endsWith
(
PAGES_JSON_UTS
)
}
}
// TODO vite 升级需要考虑调整以下列表
const
REMOVED_PLUGINS
=
[
'
vite:build-metadata
'
,
'
vite:modulepreload-polyfill
'
,
// 'vite:css', // iOS replace
'
vite:esbuild
'
,
'
vite:wasm-helper
'
,
'
vite:worker
'
,
'
vite:json
'
,
// 'vite:asset', // replace
'
vite:wasm-fallback
'
,
'
vite:define
'
,
// 'vite:css-post', // iOS replace
'
vite:build-html
'
,
'
vite:html-inline-proxy
'
,
'
vite:worker-import-meta-url
'
,
'
vite:asset-import-meta-url
'
,
'
vite:force-systemjs-wrap-complete
'
,
'
vite:watch-package-data
'
,
'
commonjs
'
,
'
vite:data-uri
'
,
'
vite:dynamic-import-vars
'
,
'
vite:import-glob
'
,
'
vite:build-import-analysis
'
,
'
vite:esbuild-transpile
'
,
'
vite:terser
'
,
'
vite:reporter
'
,
]
export
function
configResolved
(
config
:
ResolvedConfig
,
isAndroidX
=
false
)
{
const
plugins
=
config
.
plugins
as
Plugin
[]
const
len
=
plugins
.
length
const
removedPlugins
=
REMOVED_PLUGINS
.
slice
(
0
)
if
(
isAndroidX
)
{
removedPlugins
.
push
(
'
vite:css
'
)
removedPlugins
.
push
(
'
vite:css-post
'
)
}
for
(
let
i
=
len
-
1
;
i
>=
0
;
i
--
)
{
const
plugin
=
plugins
[
i
]
if
(
removedPlugins
.
includes
(
plugin
.
name
))
{
plugins
.
splice
(
i
,
1
)
}
}
// console.log(plugins.map((p) => p.name))
// 强制不inline
config
.
build
.
assetsInlineLimit
=
0
injectAssetPlugin
(
config
,
{
isAndroidX
})
}
packages/uni-cli-shared/src/vite/plugins/vitejs/plugins/asset.ts
浏览文件 @
ad8e5058
...
@@ -38,7 +38,7 @@ const emittedHashMap = new WeakMap<ResolvedConfig, Set<string>>()
...
@@ -38,7 +38,7 @@ const emittedHashMap = new WeakMap<ResolvedConfig, Set<string>>()
*/
*/
export
function
assetPlugin
(
export
function
assetPlugin
(
config
:
ResolvedConfig
,
config
:
ResolvedConfig
,
options
?:
{
isA
pp
X
:
boolean
}
options
?:
{
isA
ndroid
X
:
boolean
}
):
Plugin
{
):
Plugin
{
// assetHashToFilenameMap initialization in buildStart causes getAssetFilename to return undefined
// assetHashToFilenameMap initialization in buildStart causes getAssetFilename to return undefined
assetHashToFilenameMap
.
set
(
config
,
new
Map
())
assetHashToFilenameMap
.
set
(
config
,
new
Map
())
...
@@ -86,7 +86,7 @@ export function assetPlugin(
...
@@ -86,7 +86,7 @@ export function assetPlugin(
const
url
=
await
fileToUrl
(
const
url
=
await
fileToUrl
(
id
,
id
,
config
,
config
,
options
?.
isA
pp
X
options
?.
isA
ndroid
X
?
({
?
({
emitFile
(
emittedFile
:
EmittedAsset
)
{
emitFile
(
emittedFile
:
EmittedAsset
)
{
// 直接写入目标目录
// 直接写入目标目录
...
@@ -101,7 +101,7 @@ export function assetPlugin(
...
@@ -101,7 +101,7 @@ export function assetPlugin(
}
as
PluginContext
)
}
as
PluginContext
)
:
this
:
this
)
)
if
(
options
?.
isA
pp
X
)
{
if
(
options
?.
isA
ndroid
X
)
{
this
.
emitFile
({
this
.
emitFile
({
type
:
'
asset
'
,
type
:
'
asset
'
,
fileName
:
normalizeNodeModules
(
fileName
:
normalizeNodeModules
(
...
...
packages/uni-cli-shared/src/vite/plugins/vitejs/plugins/css.ts
浏览文件 @
ad8e5058
...
@@ -184,9 +184,9 @@ function wrapResolve(
...
@@ -184,9 +184,9 @@ function wrapResolve(
export
function
cssPlugin
(
export
function
cssPlugin
(
config
:
ResolvedConfig
,
config
:
ResolvedConfig
,
options
:
{
options
:
{
isA
pp
X
:
boolean
isA
ndroid
X
:
boolean
getDescriptor
?(
filename
:
string
):
SFCDescriptor
|
undefined
getDescriptor
?(
filename
:
string
):
SFCDescriptor
|
undefined
}
=
{
isA
pp
X
:
false
}
}
=
{
isA
ndroid
X
:
false
}
):
Plugin
{
):
Plugin
{
let
server
:
ViteDevServer
let
server
:
ViteDevServer
let
moduleCache
:
Map
<
string
,
Record
<
string
,
string
>>
let
moduleCache
:
Map
<
string
,
Record
<
string
,
string
>>
...
@@ -231,7 +231,7 @@ export function cssPlugin(
...
@@ -231,7 +231,7 @@ export function cssPlugin(
return
fileToUrl
(
return
fileToUrl
(
resolved
,
resolved
,
config
,
config
,
options
?.
isA
pp
X
options
?.
isA
ndroid
X
?
({
?
({
emitFile
(
emittedFile
:
EmittedAsset
)
{
emitFile
(
emittedFile
:
EmittedAsset
)
{
// 直接写入目标目录
// 直接写入目标目录
...
...
packages/uni-cli-shared/src/vite/utils/plugin.ts
浏览文件 @
ad8e5058
...
@@ -13,7 +13,7 @@ export interface UniViteFilterPluginOptions {
...
@@ -13,7 +13,7 @@ export interface UniViteFilterPluginOptions {
export
function
injectAssetPlugin
(
export
function
injectAssetPlugin
(
config
:
ResolvedConfig
,
config
:
ResolvedConfig
,
options
?:
{
isA
pp
X
:
boolean
}
options
?:
{
isA
ndroid
X
:
boolean
}
)
{
)
{
replacePlugins
([
assetPlugin
(
config
,
options
)],
config
)
replacePlugins
([
assetPlugin
(
config
,
options
)],
config
)
}
}
...
...
packages/vite-plugin-uni/src/configResolved/plugins/ssr.ts
浏览文件 @
ad8e5058
...
@@ -25,7 +25,7 @@ export function uniSSRPlugin(
...
@@ -25,7 +25,7 @@ export function uniSSRPlugin(
):
Plugin
{
):
Plugin
{
const
filter
=
createFilter
(
options
.
include
,
options
.
exclude
)
const
filter
=
createFilter
(
options
.
include
,
options
.
exclude
)
return
{
return
{
name
:
'
uni:ssr
'
,
name
:
'
uni:ssr
:ref
'
,
transform
(
code
,
id
)
{
transform
(
code
,
id
)
{
if
(
!
filter
(
id
))
return
null
if
(
!
filter
(
id
))
return
null
if
(
!
KEYED_FUNC_RE
.
test
(
code
))
{
if
(
!
KEYED_FUNC_RE
.
test
(
code
))
{
...
...
packages/vite-plugin-uni/src/vue/options.ts
浏览文件 @
ad8e5058
...
@@ -148,10 +148,11 @@ export function initPluginVueOptions(
...
@@ -148,10 +148,11 @@ export function initPluginVueOptions(
compilerOptions
.
hoistStatic
=
false
compilerOptions
.
hoistStatic
=
false
// 小程序使用了
// 小程序使用了
;(
compilerOptions
as
any
).
root
=
process
.
env
.
UNI_INPUT_DIR
;(
compilerOptions
as
any
).
root
=
process
.
env
.
UNI_INPUT_DIR
// app-nvue 需要启用 customElement 机制来内联 styles
const
isX
=
process
.
env
.
UNI_APP_X
===
'
true
'
if
(
process
.
env
.
UNI_COMPILER
===
'
nvue
'
)
{
// app-nvue | app-uvue 需要启用 customElement 机制来内联 styles
if
(
process
.
env
.
UNI_COMPILER
===
'
nvue
'
||
isX
)
{
vueOptions
.
customElement
=
true
vueOptions
.
customElement
=
true
if
(
process
.
env
.
UNI_RENDERER_NATIVE
!==
'
appService
'
)
{
if
(
process
.
env
.
UNI_RENDERER_NATIVE
!==
'
appService
'
||
isX
)
{
// nvue 需要使用自己的 compiler,来移除 scoped
// nvue 需要使用自己的 compiler,来移除 scoped
vueOptions
.
compiler
=
createNVueCompiler
()
vueOptions
.
compiler
=
createNVueCompiler
()
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录