Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
qianlong66
uni-app
提交
d5964629
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,发现更多精彩内容 >>
提交
d5964629
编写于
11月 11, 2021
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix(h5): respect config.build.assetsDir (#2982)
上级
b2e1e8d5
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
128 addition
and
109 deletion
+128
-109
packages/uni-h5-vite/src/index.ts
packages/uni-h5-vite/src/index.ts
+2
-2
packages/uni-h5-vite/src/plugin/config.ts
packages/uni-h5-vite/src/plugin/config.ts
+79
-0
packages/uni-h5-vite/src/plugin/index.ts
packages/uni-h5-vite/src/plugin/index.ts
+23
-72
packages/uni-h5-vite/src/plugin/uni.ts
packages/uni-h5-vite/src/plugin/uni.ts
+24
-0
packages/vite-plugin-uni/src/config/build.ts
packages/vite-plugin-uni/src/config/build.ts
+0
-35
未找到文件。
packages/uni-h5-vite/src/index.ts
浏览文件 @
d5964629
...
@@ -2,7 +2,7 @@ import {
...
@@ -2,7 +2,7 @@ import {
uniCssScopedPlugin
,
uniCssScopedPlugin
,
UNI_EASYCOM_EXCLUDE
,
UNI_EASYCOM_EXCLUDE
,
}
from
'
@dcloudio/uni-cli-shared
'
}
from
'
@dcloudio/uni-cli-shared
'
import
{
UniH5Pl
ugin
}
from
'
./plugin
'
import
{
uniH5PL
ugin
}
from
'
./plugin
'
import
{
uniCssPlugin
}
from
'
./plugins/css
'
import
{
uniCssPlugin
}
from
'
./plugins/css
'
import
{
uniEasycomPlugin
}
from
'
./plugins/easycom
'
import
{
uniEasycomPlugin
}
from
'
./plugins/easycom
'
import
{
uniInjectPlugin
}
from
'
./plugins/inject
'
import
{
uniInjectPlugin
}
from
'
./plugins/inject
'
...
@@ -26,5 +26,5 @@ export default [
...
@@ -26,5 +26,5 @@ export default [
uniSSRPlugin
(),
uniSSRPlugin
(),
uniSetupPlugin
(),
uniSetupPlugin
(),
uniRenderjsPlugin
(),
uniRenderjsPlugin
(),
UniH5Plugin
,
uniH5PLugin
()
,
]
]
packages/uni-h5-vite/src/plugin/config.ts
0 → 100644
浏览文件 @
d5964629
import
fs
from
'
fs
'
import
path
from
'
path
'
import
{
normalizePath
,
Plugin
,
ResolvedConfig
}
from
'
vite
'
import
{
isInHBuilderX
,
resolveMainPathOnce
}
from
'
@dcloudio/uni-cli-shared
'
import
{
createDefine
,
isSsr
}
from
'
../utils
'
import
{
esbuildPrePlugin
}
from
'
./esbuild/esbuildPrePlugin
'
import
{
external
}
from
'
./configureServer/ssr
'
export
function
createConfig
(
options
:
{
resolvedConfig
:
ResolvedConfig
|
null
}):
Plugin
[
'
config
'
]
{
return
function
config
(
config
,
env
)
{
if
(
isInHBuilderX
())
{
if
(
!
fs
.
existsSync
(
path
.
resolve
(
process
.
env
.
UNI_INPUT_DIR
,
'
index.html
'
))
)
{
console
.
error
(
`请确认您的项目模板是否支持vue3:根目录缺少 index.html`
)
process
.
exit
()
}
}
return
{
optimizeDeps
:
{
entries
:
resolveMainPathOnce
(
process
.
env
.
UNI_INPUT_DIR
),
exclude
:
external
,
esbuildOptions
:
{
plugins
:
[
esbuildPrePlugin
()],
},
},
define
:
createDefine
(
env
.
command
,
config
),
server
:
{
host
:
true
,
fs
:
{
strict
:
false
,
},
},
ssr
:
{
external
,
},
build
:
{
rollupOptions
:
{
// resolveSSRExternal 会判定package.json,hbx 工程可能没有,通过 rollup 来配置
external
:
isSsr
(
env
.
command
,
config
)
?
external
:
[],
onwarn
(
warning
,
warn
)
{
if
(
warning
.
code
===
'
UNUSED_EXTERNAL_IMPORT
'
)
{
const
{
message
}
=
warning
// ignore
if
(
message
.
includes
(
'
"vue"
'
)
||
message
.
includes
(
'
"resolveComponent"
'
)
||
message
.
includes
(
'
"@dcloudio/uni-h5"
'
)
)
{
return
}
}
warn
(
warning
)
},
output
:
{
chunkFileNames
(
chunkInfo
)
{
const
{
assetsDir
}
=
options
.
resolvedConfig
!
.
build
if
(
chunkInfo
.
facadeModuleId
)
{
const
dirname
=
path
.
relative
(
process
.
env
.
UNI_INPUT_DIR
,
path
.
dirname
(
chunkInfo
.
facadeModuleId
)
)
if
(
dirname
)
{
return
path
.
posix
.
join
(
assetsDir
,
normalizePath
(
dirname
).
replace
(
/
\/
/g
,
'
-
'
)
+
'
-[name].[hash].js
'
)
}
}
return
path
.
posix
.
join
(
assetsDir
,
'
[name].[hash].js
'
)
},
},
},
},
}
}
}
packages/uni-h5-vite/src/plugin/index.ts
浏览文件 @
d5964629
import
fs
from
'
fs
'
import
{
ResolvedConfig
}
from
'
vite
'
import
path
from
'
path
'
import
{
UniVitePlugin
}
from
'
@dcloudio/uni-cli-shared
'
import
{
isH5CustomElement
,
isH5NativeTag
}
from
'
@dcloudio/uni-shared
'
import
{
isInHBuilderX
,
resolveMainPathOnce
,
transformMatchMedia
,
transformTapToClick
,
UniVitePlugin
,
}
from
'
@dcloudio/uni-cli-shared
'
import
{
createHandleHotUpdate
}
from
'
./handleHotUpdate
'
import
{
createHandleHotUpdate
}
from
'
./handleHotUpdate
'
import
{
createTransformIndexHtml
}
from
'
./transformIndexHtml
'
import
{
createTransformIndexHtml
}
from
'
./transformIndexHtml
'
import
{
transformPageHead
}
from
'
./transforms/transformPageHead
'
import
{
createDefine
}
from
'
../utils/features
'
import
{
isSsr
}
from
'
../utils
'
import
{
esbuildPrePlugin
}
from
'
./esbuild/esbuildPrePlugin
'
import
{
external
}
from
'
./configureServer/ssr
'
import
{
createConfigureServer
}
from
'
./configureServer
'
import
{
createConfigureServer
}
from
'
./configureServer
'
import
{
createUni
}
from
'
./uni
'
export
const
UniH5Plugin
:
UniVitePlugin
=
{
import
{
createConfig
}
from
'
./config
'
name
:
'
vite:uni-h5
'
,
uni
:
{
export
function
uniH5PLugin
():
UniVitePlugin
{
copyOptions
:
{
const
configOptions
:
{
assets
:
[
'
hybrid/html
'
],
resolvedConfig
:
ResolvedConfig
|
null
},
}
=
{
compilerOptions
:
{
resolvedConfig
:
null
,
isNativeTag
:
isH5NativeTag
,
}
isCustomElement
:
isH5CustomElement
,
return
{
nodeTransforms
:
[
name
:
'
vite:uni-h5
'
,
transformTapToClick
,
uni
:
createUni
(),
transformMatchMedia
,
config
:
createConfig
(
configOptions
),
transformPageHead
,
configResolved
(
config
)
{
],
configOptions
.
resolvedConfig
=
config
// TODO 禁止 optimizeDeps
;(
config
as
any
).
cacheDir
=
''
},
},
},
configureServer
:
createConfigureServer
(),
config
(
config
,
env
)
{
handleHotUpdate
:
createHandleHotUpdate
(),
if
(
isInHBuilderX
())
{
transformIndexHtml
:
createTransformIndexHtml
(),
if
(
}
!
fs
.
existsSync
(
path
.
resolve
(
process
.
env
.
UNI_INPUT_DIR
,
'
index.html
'
))
)
{
console
.
error
(
`请确认您的项目模板是否支持vue3:根目录缺少 index.html`
)
process
.
exit
()
}
}
return
{
optimizeDeps
:
{
entries
:
resolveMainPathOnce
(
process
.
env
.
UNI_INPUT_DIR
),
exclude
:
external
,
esbuildOptions
:
{
plugins
:
[
esbuildPrePlugin
()],
},
},
define
:
createDefine
(
env
.
command
,
config
),
server
:
{
host
:
true
,
fs
:
{
strict
:
false
,
},
},
ssr
:
{
external
,
},
build
:
{
rollupOptions
:
{
// resolveSSRExternal 会判定package.json,hbx 工程可能没有,通过 rollup 来配置
external
:
isSsr
(
env
.
command
,
config
)
?
external
:
[],
},
},
}
},
configResolved
(
config
)
{
// TODO 禁止 optimizeDeps
;(
config
as
any
).
cacheDir
=
''
},
configureServer
:
createConfigureServer
(),
handleHotUpdate
:
createHandleHotUpdate
(),
transformIndexHtml
:
createTransformIndexHtml
(),
}
}
packages/uni-h5-vite/src/plugin/uni.ts
0 → 100644
浏览文件 @
d5964629
import
{
transformMatchMedia
,
transformPageHead
,
transformTapToClick
,
UniVitePlugin
,
}
from
'
@dcloudio/uni-cli-shared
'
import
{
isH5NativeTag
,
isH5CustomElement
}
from
'
@dcloudio/uni-shared
'
export
function
createUni
():
UniVitePlugin
[
'
uni
'
]
{
return
{
copyOptions
:
{
assets
:
[
'
hybrid/html
'
],
},
compilerOptions
:
{
isNativeTag
:
isH5NativeTag
,
isCustomElement
:
isH5CustomElement
,
nodeTransforms
:
[
transformTapToClick
,
transformMatchMedia
,
transformPageHead
,
],
},
}
}
packages/vite-plugin-uni/src/config/build.ts
浏览文件 @
d5964629
import
path
from
'
path
'
import
{
UserConfig
}
from
'
vite
'
import
{
UserConfig
}
from
'
vite
'
import
{
import
{
initEasycomsOnce
,
initEasycomsOnce
,
normalizePath
,
resolveComponentsLibPath
,
resolveComponentsLibPath
,
}
from
'
@dcloudio/uni-cli-shared
'
}
from
'
@dcloudio/uni-cli-shared
'
import
{
VitePluginUniResolvedOptions
}
from
'
..
'
import
{
VitePluginUniResolvedOptions
}
from
'
..
'
...
@@ -16,38 +14,5 @@ export function createBuild(
...
@@ -16,38 +14,5 @@ export function createBuild(
})
})
return
{
return
{
chunkSizeWarningLimit
:
100000000
,
chunkSizeWarningLimit
:
100000000
,
rollupOptions
:
{
onwarn
(
warning
,
warn
)
{
if
(
warning
.
code
===
'
UNUSED_EXTERNAL_IMPORT
'
)
{
const
{
message
}
=
warning
// ignore
if
(
message
.
includes
(
'
"vue"
'
)
||
message
.
includes
(
'
"resolveComponent"
'
)
||
message
.
includes
(
'
"@dcloudio/uni-h5"
'
)
)
{
return
}
}
warn
(
warning
)
},
output
:
{
chunkFileNames
(
chunkInfo
)
{
if
(
chunkInfo
.
facadeModuleId
)
{
const
dirname
=
path
.
relative
(
options
.
inputDir
,
path
.
dirname
(
chunkInfo
.
facadeModuleId
)
)
if
(
dirname
)
{
return
`
${
options
.
assetsDir
}
/
${
normalizePath
(
dirname
).
replace
(
/
\/
/g
,
'
-
'
)}
-[name].[hash].js`
}
}
return
'
[name].[hash].js
'
},
},
},
}
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录