Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
uni-app
提交
a3156716
U
uni-app
项目概览
DCloud
/
uni-app
3 个月 前同步成功
通知
725
Star
38705
Fork
3642
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
7
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
7
Issue
7
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
a3156716
编写于
8月 04, 2021
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(app): copy hybrid/html
上级
199f7e66
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
85 addition
and
51 deletion
+85
-51
packages/uni-cli-shared/src/vite/index.ts
packages/uni-cli-shared/src/vite/index.ts
+1
-1
packages/vite-plugin-uni/src/config/index.ts
packages/vite-plugin-uni/src/config/index.ts
+1
-19
packages/vite-plugin-uni/src/configResolved/plugins/copy.ts
packages/vite-plugin-uni/src/configResolved/plugins/copy.ts
+32
-14
packages/vite-plugin-uni/src/index.ts
packages/vite-plugin-uni/src/index.ts
+22
-6
packages/vite-plugin-uni/src/utils/plugin.ts
packages/vite-plugin-uni/src/utils/plugin.ts
+24
-5
packages/vite-plugin-uni/src/vue/options.ts
packages/vite-plugin-uni/src/vue/options.ts
+5
-6
未找到文件。
packages/uni-cli-shared/src/vite/index.ts
浏览文件 @
a3156716
...
...
@@ -2,7 +2,7 @@ import type { Plugin } from 'vite'
import
type
{
ParserOptions
}
from
'
@vue/compiler-core
'
import
type
{
CompilerOptions
}
from
'
@vue/compiler-sfc
'
import
type
{
Target
}
from
'
rollup-plugin-copy
'
interface
CopyOptions
{
export
interface
CopyOptions
{
/**
* 静态资源,配置的目录,在 uni_modules 中同样支持
*/
...
...
packages/vite-plugin-uni/src/config/index.ts
浏览文件 @
a3156716
...
...
@@ -14,23 +14,9 @@ import { createBuild } from './build'
import
{
createOptimizeDeps
}
from
'
./optimizeDeps
'
import
{
createDefine
}
from
'
./define
'
import
{
initPluginViteLegacyOptions
,
initPluginVueJsxOptions
,
initPluginVueOptions
,
}
from
'
../vue
'
// function normalizeRoot(config: UserConfig) {
// return normalizePath(config.root ? path.resolve(config.root) : process.cwd())
// }
// function normalizeInputDir(config: UserConfig) {
// return process.env.UNI_INPUT_DIR || path.resolve(normalizeRoot(config), 'src')
// }
export
function
createConfig
(
options
:
VitePluginUniResolvedOptions
,
uniPlugins
:
Plugin
[]
_
uniPlugins
:
Plugin
[]
):
Plugin
[
'
config
'
]
{
return
(
config
,
env
)
=>
{
options
.
command
=
env
.
command
...
...
@@ -44,10 +30,6 @@ export function createConfig(
base
=
'
/
'
}
options
.
base
=
base
!
// TODO 似乎没必要
options
.
vueOptions
=
initPluginVueOptions
(
options
,
uniPlugins
)
options
.
vueJsxOptions
=
initPluginVueJsxOptions
(
options
)
options
.
viteLegacyOptions
=
initPluginViteLegacyOptions
(
options
)
return
{
base
,
...
...
packages/vite-plugin-uni/src/configResolved/plugins/copy.ts
浏览文件 @
a3156716
...
...
@@ -7,27 +7,45 @@ import {
uniViteCopyPlugin
,
}
from
'
@dcloudio/uni-cli-shared
'
import
{
VitePluginUniResolvedOptions
}
from
'
../..
'
import
type
{
Target
}
from
'
rollup-plugin-copy
'
export
function
uniCopyPlugin
({
inputDir
,
outputDir
,
copyOptions
,
}:
VitePluginUniResolvedOptions
):
Plugin
{
return
uniViteCopyPlugin
({
targets
:
[
{
src
:
normalizePath
(
path
.
resolve
(
inputDir
,
PUBLIC_DIR
)),
dest
:
outputDir
,
const
targets
:
Target
[]
=
[
{
src
:
normalizePath
(
path
.
resolve
(
inputDir
,
PUBLIC_DIR
)),
dest
:
outputDir
,
},
{
src
:
normalizePath
(
path
.
resolve
(
inputDir
,
'
uni_modules/*/
'
+
PUBLIC_DIR
)),
dest
:
outputDir
,
rename
:
(
_name
,
_extension
,
fullPath
)
=>
{
return
path
.
relative
(
inputDir
,
fullPath
)
},
},
]
copyOptions
!
.
assets
.
forEach
((
asset
)
=>
{
targets
.
push
({
src
:
normalizePath
(
path
.
resolve
(
inputDir
,
asset
)),
dest
:
outputDir
,
rename
:
(
_name
,
_extension
,
fullPath
)
=>
{
return
path
.
relative
(
inputDir
,
fullPath
)
},
{
src
:
normalizePath
(
path
.
resolve
(
inputDir
,
'
uni_modules/*/
'
+
PUBLIC_DIR
)
),
dest
:
outputDir
,
rename
:
(
_name
,
_extension
,
fullPath
)
=>
{
return
path
.
relative
(
inputDir
,
fullPath
)
},
})
targets
.
push
({
src
:
normalizePath
(
path
.
resolve
(
inputDir
,
'
uni_modules/*/
'
+
asset
)),
dest
:
outputDir
,
rename
:
(
_name
,
_extension
,
fullPath
)
=>
{
return
path
.
relative
(
inputDir
,
fullPath
)
},
],
})
})
targets
.
push
(...
copyOptions
!
.
targets
)
return
uniViteCopyPlugin
({
targets
,
hook
:
'
writeBundle
'
,
verbose
:
process
.
env
.
DEBUG
?
true
:
false
,
})
...
...
packages/vite-plugin-uni/src/index.ts
浏览文件 @
a3156716
...
...
@@ -7,13 +7,21 @@ import vuePlugin from '@vitejs/plugin-vue'
import
type
VueJsxPlugin
from
'
@vitejs/plugin-vue-jsx
'
import
type
ViteLegacyPlugin
from
'
@vitejs/plugin-legacy
'
import
{
initModuleAlias
,
initPreContext
}
from
'
@dcloudio/uni-cli-shared
'
import
{
CopyOptions
,
initModuleAlias
,
initPreContext
,
}
from
'
@dcloudio/uni-cli-shared
'
import
{
createConfig
}
from
'
./config
'
import
{
createConfigResolved
}
from
'
./configResolved
'
import
{
createConfigureServer
}
from
'
./configureServer
'
import
{
initExtraPlugins
}
from
'
./utils
'
import
{
initPluginVueOptions
}
from
'
./vue
'
import
{
initExtraPlugins
,
initPluginUniOptions
}
from
'
./utils
'
import
{
initPluginViteLegacyOptions
,
initPluginVueJsxOptions
,
initPluginVueOptions
,
}
from
'
./vue
'
// import { createResolveId } from './resolveId'
const
debugUni
=
debug
(
'
vite:uni:plugin
'
)
...
...
@@ -39,6 +47,7 @@ export interface VitePluginUniResolvedOptions extends VitePluginUniOptions {
outputDir
:
string
assetsDir
:
string
devServer
?:
ViteDevServer
copyOptions
?:
Required
<
CopyOptions
>
}
export
{
runDev
,
runBuild
}
from
'
./cli/action
'
...
...
@@ -76,13 +85,13 @@ export default function uniPlugin(
if
(
createViteLegacyPlugin
&&
options
.
viteLegacyOptions
!==
false
)
{
plugins
.
push
(
...(
createViteLegacyPlugin
(
options
.
viteLegacyOptions
initPluginViteLegacyOptions
(
options
)
)
as
unknown
as
Plugin
[])
)
}
if
(
createVueJsxPlugin
&&
options
.
vueJsxOptions
!==
false
)
{
plugins
.
push
(
createVueJsxPlugin
(
options
.
vueJsxOptions
))
plugins
.
push
(
createVueJsxPlugin
(
initPluginVueJsxOptions
(
options
)
))
}
const
uniPlugins
=
initExtraPlugins
(
...
...
@@ -90,6 +99,11 @@ export default function uniPlugin(
(
process
.
env
.
UNI_PLATFORM
as
UniApp
.
PLATFORM
)
||
'
h5
'
)
debugUni
(
uniPlugins
)
const
uniPluginOptions
=
initPluginUniOptions
(
uniPlugins
)
options
.
copyOptions
=
uniPluginOptions
.
copyOptions
plugins
.
push
({
name
:
'
vite:uni
'
,
config
:
createConfig
(
options
,
uniPlugins
),
...
...
@@ -99,7 +113,9 @@ export default function uniPlugin(
})
plugins
.
push
(...
uniPlugins
)
plugins
.
unshift
(
vuePlugin
(
initPluginVueOptions
(
options
,
uniPlugins
)))
plugins
.
unshift
(
vuePlugin
(
initPluginVueOptions
(
options
,
uniPlugins
,
uniPluginOptions
))
)
return
plugins
}
packages/vite-plugin-uni/src/utils/plugin.ts
浏览文件 @
a3156716
import
path
from
'
path
'
import
{
Plugin
}
from
'
vite
'
import
{
extend
,
isArray
,
isString
}
from
'
@vue/shared
'
import
type
{
Plugin
}
from
'
vite
'
import
{
extend
,
isArray
,
isString
,
isFunction
}
from
'
@vue/shared
'
import
{
isCustomElement
,
isNativeTag
}
from
'
@dcloudio/uni-shared
'
import
{
UniVitePlugin
}
from
'
@dcloudio/uni-cli-shared
'
import
{
CompilerOptions
}
from
'
@vue/compiler-sfc
'
import
type
{
CopyOptions
,
UniVitePlugin
}
from
'
@dcloudio/uni-cli-shared
'
import
type
{
Target
}
from
'
rollup-plugin-copy
'
interface
PluginConfig
{
id
:
string
...
...
@@ -16,13 +16,16 @@ interface PluginConfig {
}
export
function
initPluginUniOptions
(
UniVitePlugins
:
UniVitePlugin
[])
{
const
assets
:
string
[]
=
[]
const
targets
:
Target
[]
=
[]
const
transformEvent
:
Record
<
string
,
string
>
=
Object
.
create
(
null
)
const
compilerOptions
:
CompilerOptions
=
{
const
compilerOptions
:
Required
<
UniVitePlugin
>
[
'
uni
'
][
'
compilerOptions
'
]
=
{
isNativeTag
,
isCustomElement
,
}
UniVitePlugins
.
forEach
((
plugin
)
=>
{
const
{
copyOptions
:
pluginCopyOptions
,
compilerOptions
:
pluginCompilerOptions
,
transformEvent
:
pluginTransformEvent
,
}
=
plugin
.
uni
||
{}
...
...
@@ -41,8 +44,24 @@ export function initPluginUniOptions(UniVitePlugins: UniVitePlugin[]) {
if
(
pluginTransformEvent
)
{
extend
(
transformEvent
,
pluginTransformEvent
)
}
if
(
pluginCopyOptions
)
{
let
copyOptions
=
pluginCopyOptions
as
CopyOptions
if
(
isFunction
(
pluginCopyOptions
))
{
copyOptions
=
pluginCopyOptions
()
}
if
(
copyOptions
.
assets
)
{
assets
.
push
(...
copyOptions
.
assets
)
}
if
(
copyOptions
.
targets
)
{
targets
.
push
(...
copyOptions
.
targets
)
}
}
})
return
{
copyOptions
:
{
assets
,
targets
,
},
transformEvent
,
compilerOptions
,
}
...
...
packages/vite-plugin-uni/src/vue/options.ts
浏览文件 @
a3156716
...
...
@@ -10,7 +10,6 @@ import {
import
{
VitePluginUniResolvedOptions
}
from
'
..
'
import
{
transformMatchMedia
}
from
'
./transforms/transformMatchMedia
'
import
{
createTransformEvent
}
from
'
./transforms/transformEvent
'
import
{
initPluginUniOptions
}
from
'
../utils/plugin
'
// import { transformContext } from './transforms/transformContext'
function
createUniVueTransformAssetUrls
(
...
...
@@ -38,7 +37,8 @@ function createUniVueTransformAssetUrls(
export
function
initPluginVueOptions
(
options
:
VitePluginUniResolvedOptions
,
UniVitePlugins
:
UniVitePlugin
[]
UniVitePlugins
:
UniVitePlugin
[],
uniPluginOptions
:
Required
<
Required
<
UniVitePlugin
>
[
'
uni
'
]
>
)
{
const
vueOptions
=
options
.
vueOptions
||
(
options
.
vueOptions
=
{})
if
(
!
vueOptions
.
include
)
{
...
...
@@ -55,13 +55,12 @@ export function initPluginVueOptions(
options
.
base
)
const
{
compilerOptions
:
{
isNativeTag
,
isCustomElement
,
directiveTransforms
},
}
=
initPluginUniOptions
(
UniVitePlugins
)
const
compilerOptions
=
templateOptions
.
compilerOptions
||
(
templateOptions
.
compilerOptions
=
{})
const
{
compilerOptions
:
{
isNativeTag
,
isCustomElement
,
directiveTransforms
},
}
=
uniPluginOptions
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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录