Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Velpro187
uni-app
提交
efea3e80
U
uni-app
项目概览
Velpro187
/
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,发现更多精彩内容 >>
提交
efea3e80
编写于
10月 22, 2021
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
wip(mp): assets inline
上级
fbd8c553
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
37 addition
and
27 deletion
+37
-27
packages/uni-app-vite/src/plugin/configResolved.ts
packages/uni-app-vite/src/plugin/configResolved.ts
+2
-0
packages/uni-cli-shared/src/vite/plugins/vitejs/plugins/asset.ts
...s/uni-cli-shared/src/vite/plugins/vitejs/plugins/asset.ts
+33
-25
packages/uni-cli-shared/src/vite/plugins/vitejs/plugins/css.ts
...ges/uni-cli-shared/src/vite/plugins/vitejs/plugins/css.ts
+1
-1
packages/uni-mp-vite/src/plugin/build.ts
packages/uni-mp-vite/src/plugin/build.ts
+1
-1
未找到文件。
packages/uni-app-vite/src/plugin/configResolved.ts
浏览文件 @
efea3e80
...
...
@@ -45,5 +45,7 @@ export const configResolved: Plugin['configResolved'] = (config) => {
return
cssCode
},
})
// 强制不inline
config
.
build
.
assetsInlineLimit
=
0
injectAssetPlugin
(
config
)
}
packages/uni-cli-shared/src/vite/plugins/vitejs/plugins/asset.ts
浏览文件 @
efea3e80
import
path
from
'
path
'
import
{
parse
as
parseUrl
}
from
'
url
'
import
mime
from
'
mime/lite
'
import
fs
,
{
promises
as
fsp
}
from
'
fs
'
import
{
Plugin
}
from
'
../plugin
'
import
{
ResolvedConfig
}
from
'
../config
'
...
...
@@ -137,9 +138,10 @@ export function checkPublicFile(
export
function
fileToUrl
(
id
:
string
,
config
:
ResolvedConfig
,
ctx
:
PluginContext
ctx
:
PluginContext
,
canInline
:
boolean
=
false
):
string
{
return
fileToBuiltUrl
(
id
,
config
,
ctx
)
return
fileToBuiltUrl
(
id
,
config
,
ctx
,
false
,
canInline
)
}
export
function
getAssetFilename
(
...
...
@@ -156,7 +158,8 @@ function fileToBuiltUrl(
id
:
string
,
config
:
ResolvedConfig
,
pluginContext
:
PluginContext
,
skipPublicCheck
=
false
skipPublicCheck
=
false
,
canInline
=
false
):
string
{
if
(
!
skipPublicCheck
&&
checkPublicFile
(
id
,
config
))
{
return
config
.
base
+
id
.
slice
(
1
)
...
...
@@ -172,31 +175,36 @@ function fileToBuiltUrl(
let
url
:
string
const
map
=
assetHashToFilenameMap
.
get
(
config
)
!
const
contentHash
=
getAssetHash
(
content
)
const
{
search
,
hash
}
=
parseUrl
(
id
)
const
postfix
=
(
search
||
''
)
+
(
hash
||
''
)
const
fileName
=
normalizePath
(
path
.
posix
.
relative
(
process
.
env
.
UNI_INPUT_DIR
,
file
)
)
if
(
!
map
.
has
(
contentHash
))
{
map
.
set
(
contentHash
,
fileName
)
}
if
(
canInline
&&
content
.
length
<
Number
(
config
.
build
.
assetsInlineLimit
))
{
// base64 inlined as a string
url
=
`data:
${
mime
.
getType
(
file
)}
;base64,
${
content
.
toString
(
'
base64
'
)}
`
}
else
{
const
map
=
assetHashToFilenameMap
.
get
(
config
)
!
const
contentHash
=
getAssetHash
(
content
)
const
{
search
,
hash
}
=
parseUrl
(
id
)
const
postfix
=
(
search
||
''
)
+
(
hash
||
''
)
const
fileName
=
normalizePath
(
path
.
posix
.
relative
(
process
.
env
.
UNI_INPUT_DIR
,
file
)
)
if
(
!
map
.
has
(
contentHash
))
{
map
.
set
(
contentHash
,
fileName
)
}
if
(
!
fileName
.
includes
(
'
/static/
'
))
{
const
emittedSet
=
emittedHashMap
.
get
(
config
)
!
if
(
!
emittedSet
.
has
(
contentHash
))
{
pluginContext
.
emitFile
({
name
:
fileName
,
fileName
,
type
:
'
asset
'
,
source
:
content
,
})
emittedSet
.
add
(
contentHash
)
if
(
!
fileName
.
includes
(
'
/static/
'
))
{
const
emittedSet
=
emittedHashMap
.
get
(
config
)
!
if
(
!
emittedSet
.
has
(
contentHash
))
{
pluginContext
.
emitFile
({
name
:
fileName
,
fileName
,
type
:
'
asset
'
,
source
:
content
,
})
emittedSet
.
add
(
contentHash
)
}
}
}
url
=
`__VITE_ASSET__
${
contentHash
}
__
${
postfix
?
`$_
${
postfix
}
__`
:
``
}
`
url
=
`__VITE_ASSET__
${
contentHash
}
__
${
postfix
?
`$_
${
postfix
}
__`
:
``
}
`
}
cache
.
set
(
id
,
url
)
return
url
}
...
...
packages/uni-cli-shared/src/vite/plugins/vitejs/plugins/css.ts
浏览文件 @
efea3e80
...
...
@@ -138,7 +138,7 @@ export function cssPlugin(config: ResolvedConfig): Plugin {
}
const
resolved
=
await
resolveUrl
(
url
,
importer
)
if
(
resolved
)
{
return
fileToUrl
(
resolved
,
config
,
this
)
return
fileToUrl
(
resolved
,
config
,
this
,
true
)
}
return
url
}
...
...
packages/uni-mp-vite/src/plugin/build.ts
浏览文件 @
efea3e80
...
...
@@ -33,7 +33,7 @@ export function buildOptions(): UserConfig['build'] {
// sourcemap: 'inline', // TODO
target
:
[
'
chrome53
'
],
emptyOutDir
:
false
,
// 不清空输出目录,否则会影响自定义的一些文件输出,比如wxml
assetsInlineLimit
:
0
,
// TODO
assetsInlineLimit
:
40
*
1024
,
// 40kb
lib
:
{
entry
:
resolveMainPathOnce
(
inputDir
),
formats
:
[
'
cjs
'
],
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录