Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
wzj-java
uni-app
提交
f32c4923
U
uni-app
项目概览
wzj-java
/
uni-app
与 Fork 源项目一致
Fork自
DCloud / uni-app
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
f32c4923
编写于
10月 20, 2021
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
wip(mp): wxs
上级
f4cf5761
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
228 addition
and
44 deletion
+228
-44
packages/uni-cli-shared/src/mp/index.ts
packages/uni-cli-shared/src/mp/index.ts
+1
-0
packages/uni-cli-shared/src/mp/template.ts
packages/uni-cli-shared/src/mp/template.ts
+65
-0
packages/uni-mp-vite/src/plugin/index.ts
packages/uni-mp-vite/src/plugin/index.ts
+33
-28
packages/uni-mp-vite/src/plugin/template.ts
packages/uni-mp-vite/src/plugin/template.ts
+80
-0
packages/uni-mp-vite/src/plugins/renderjs.ts
packages/uni-mp-vite/src/plugins/renderjs.ts
+25
-8
packages/uni-mp-weixin/dist/uni.compiler.js
packages/uni-mp-weixin/dist/uni.compiler.js
+12
-4
packages/uni-mp-weixin/src/plugin/index.ts
packages/uni-mp-weixin/src/plugin/index.ts
+12
-4
未找到文件。
packages/uni-cli-shared/src/mp/index.ts
浏览文件 @
f32c4923
export
*
from
'
./nvue
'
export
*
from
'
./event
'
export
*
from
'
./style
'
export
*
from
'
./template
'
export
{
transformVueComponentImports
}
from
'
./transformImports
'
packages/uni-cli-shared/src/mp/template.ts
0 → 100644
浏览文件 @
f32c4923
import
{
LINEFEED
}
from
'
@dcloudio/uni-shared
'
export
interface
MiniProgramFilterOptions
{
id
:
string
type
:
'
wxs
'
name
:
string
src
?:
string
code
:
string
}
type
GenFilterFn
=
(
filter
:
MiniProgramFilterOptions
)
=>
string
|
void
const
templateFilesCache
=
new
Map
<
string
,
string
>
()
const
templateFiltersCache
=
new
Map
<
string
,
Set
<
MiniProgramFilterOptions
>>
()
export
function
findMiniProgramTemplateFiles
(
genFilter
?:
GenFilterFn
)
{
const
files
:
Record
<
string
,
string
>
=
Object
.
create
(
null
)
templateFilesCache
.
forEach
((
code
,
filename
)
=>
{
if
(
!
genFilter
)
{
files
[
filename
]
=
code
}
else
{
const
filters
=
getMiniProgramTemplateFilters
(
filename
)
if
(
filters
.
length
)
{
files
[
filename
]
=
filters
.
map
((
filter
)
=>
genFilter
(
filter
)).
join
(
LINEFEED
)
+
LINEFEED
+
code
}
else
{
files
[
filename
]
=
code
}
}
})
return
files
}
export
function
clearMiniProgramTemplateFiles
()
{
templateFilesCache
.
clear
()
}
export
function
addMiniProgramTemplateFile
(
filename
:
string
,
code
:
string
)
{
templateFilesCache
.
set
(
filename
,
code
)
}
function
getMiniProgramTemplateFilters
(
filename
:
string
)
{
return
[...(
templateFiltersCache
.
get
(
filename
)
||
[])]
}
export
function
clearMiniProgramTemplateFilter
(
filename
:
string
)
{
templateFiltersCache
.
delete
(
filename
)
}
export
function
addMiniProgramTemplateFilter
(
filename
:
string
,
filter
:
MiniProgramFilterOptions
)
{
const
filters
=
templateFiltersCache
.
get
(
filename
)
if
(
filters
)
{
filters
.
add
(
filter
)
}
else
{
templateFiltersCache
.
set
(
filename
,
new
Set
<
MiniProgramFilterOptions
>
([
filter
])
)
}
}
packages/uni-mp-vite/src/plugin/index.ts
浏览文件 @
f32c4923
import
path
from
'
path
'
import
debug
from
'
debug
'
import
fs
from
'
fs-extra
'
import
{
AliasOptions
}
from
'
vite
'
import
{
AliasOptions
,
ResolvedConfig
}
from
'
vite
'
import
{
CopyOptions
,
EXTNAME_VUE_RE
,
normalizeNodeModules
,
resolveBuiltIn
,
UniVitePlugin
,
genNVueCssCode
,
parseManifestJsonOnce
,
findMiniProgramTemplateFiles
,
}
from
'
@dcloudio/uni-cli-shared
'
import
{
uniOptions
}
from
'
./uni
'
import
{
buildOptions
}
from
'
./build
'
import
{
createConfigResolved
}
from
'
./configResolved
'
import
{
EmittedFile
}
from
'
rollup
'
import
{
emitFile
,
getFilterFiles
,
getTemplateFiles
}
from
'
./template
'
const
debugMp
=
debug
(
'
vite:uni:mp
'
)
export
interface
UniMiniProgramPluginOptions
{
vite
:
{
alias
:
AliasOptions
...
...
@@ -42,6 +37,11 @@ export interface UniMiniProgramPluginOptions {
// 是否支持fallback content
fallback
:
boolean
}
filter
?:
{
extname
:
string
tag
:
string
generate
:
Parameters
<
typeof
findMiniProgramTemplateFiles
>
[
0
]
}
}
style
:
{
extname
:
string
...
...
@@ -53,10 +53,6 @@ export interface UniMiniProgramPluginOptions {
'
--window-right
'
:
string
}
}
filter
?:
{
extname
:
string
tag
:
string
}
}
export
function
uniMiniProgramPlugin
(
...
...
@@ -67,22 +63,9 @@ export function uniMiniProgramPlugin(
template
,
style
,
}
=
options
const
emitFile
:
(
emittedFile
:
EmittedFile
)
=>
string
=
(
emittedFile
)
=>
{
if
(
emittedFile
.
type
===
'
asset
'
)
{
const
filename
=
emittedFile
.
fileName
!
const
outputFilename
=
normalizeNodeModules
(
path
.
resolve
(
process
.
env
.
UNI_OUTPUT_DIR
,
path
.
relative
(
process
.
env
.
UNI_INPUT_DIR
,
filename
)
)
).
replace
(
EXTNAME_VUE_RE
,
template
.
extname
)
debugMp
(
outputFilename
)
fs
.
outputFile
(
outputFilename
,
emittedFile
.
source
!
)
return
outputFilename
}
return
''
}
let
isFirst
=
true
let
resolvedConfig
:
ResolvedConfig
return
{
name
:
'
vite:uni-mp
'
,
uni
:
uniOptions
({
...
...
@@ -104,8 +87,30 @@ export function uniMiniProgramPlugin(
build
:
buildOptions
(),
}
},
configResolved
:
createConfigResolved
(
options
),
configResolved
(
config
)
{
resolvedConfig
=
config
return
createConfigResolved
(
options
)
!
(
config
)
},
generateBundle
()
{
if
(
template
.
filter
)
{
const
extname
=
template
.
filter
.
extname
const
filterFiles
=
getFilterFiles
(
resolvedConfig
,
this
.
getModuleInfo
)
Object
.
keys
(
filterFiles
).
forEach
((
filename
)
=>
{
this
.
emitFile
({
type
:
'
asset
'
,
fileName
:
filename
+
extname
,
source
:
filterFiles
[
filename
],
})
})
}
const
templateFiles
=
getTemplateFiles
(
template
)
Object
.
keys
(
templateFiles
).
forEach
((
filename
)
=>
{
this
.
emitFile
({
type
:
'
asset
'
,
fileName
:
filename
+
template
.
extname
,
source
:
templateFiles
[
filename
],
})
})
if
(
isFirst
)
{
// 仅生成一次
isFirst
=
false
...
...
packages/uni-mp-vite/src/plugin/template.ts
0 → 100644
浏览文件 @
f32c4923
import
path
from
'
path
'
import
debug
from
'
debug
'
import
{
EmittedFile
,
GetModuleInfo
}
from
'
rollup
'
import
{
ResolvedConfig
}
from
'
vite
'
import
{
addMiniProgramTemplateFile
,
removeExt
,
normalizeMiniProgramFilename
,
MiniProgramFilterOptions
,
findMiniProgramTemplateFiles
,
addMiniProgramTemplateFilter
,
clearMiniProgramTemplateFiles
,
}
from
'
@dcloudio/uni-cli-shared
'
import
{
getFiltersCache
}
from
'
../plugins/renderjs
'
import
{
UniMiniProgramPluginOptions
}
from
'
.
'
const
debugTemplate
=
debug
(
'
vite:uni:mp-template
'
)
export
function
getFilterFiles
(
resolvedConfig
:
ResolvedConfig
,
getModuleInfo
:
GetModuleInfo
)
{
const
filters
:
Record
<
string
,
string
>
=
Object
.
create
(
null
)
const
filtersCache
=
getFiltersCache
(
resolvedConfig
)
if
(
!
filtersCache
.
length
)
{
return
filters
}
const
inputDir
=
process
.
env
.
UNI_INPUT_DIR
function
addFilter
(
id
:
string
,
filter
:
MiniProgramFilterOptions
)
{
const
templateFilename
=
removeExt
(
normalizeMiniProgramFilename
(
id
,
inputDir
)
)
addMiniProgramTemplateFilter
(
templateFilename
,
filter
)
const
filterFilename
=
removeExt
(
normalizeMiniProgramFilename
(
filter
.
id
,
inputDir
)
)
if
(
templateFilename
!==
filterFilename
)
{
// 外链
filter
.
src
=
filterFilename
filters
[
filterFilename
]
=
filter
.
code
}
}
filtersCache
.
forEach
((
filter
)
=>
{
const
moduleInfo
=
getModuleInfo
(
filter
.
id
)
if
(
!
moduleInfo
)
{
return
}
const
{
importers
}
=
moduleInfo
if
(
!
importers
.
length
)
{
return
}
importers
.
forEach
((
importer
)
=>
addFilter
(
importer
,
filter
))
})
return
filters
}
export
function
getTemplateFiles
(
template
:
UniMiniProgramPluginOptions
[
'
template
'
]
)
{
const
files
=
findMiniProgramTemplateFiles
(
template
.
filter
!
.
generate
)
clearMiniProgramTemplateFiles
()
return
files
}
export
const
emitFile
:
(
emittedFile
:
EmittedFile
)
=>
string
=
(
emittedFile
)
=>
{
if
(
emittedFile
.
type
===
'
asset
'
)
{
const
filename
=
emittedFile
.
fileName
!
addMiniProgramTemplateFile
(
removeExt
(
normalizeMiniProgramFilename
(
path
.
relative
(
process
.
env
.
UNI_INPUT_DIR
,
filename
)
)
),
emittedFile
.
source
!
.
toString
()
)
debugTemplate
(
filename
)
return
filename
}
return
''
}
packages/uni-mp-vite/src/plugins/renderjs.ts
浏览文件 @
f32c4923
import
debug
from
'
debug
'
import
{
Plugin
}
from
'
vite
'
import
{
Plugin
,
ResolvedConfig
}
from
'
vite
'
import
{
missingModuleName
,
parseRenderjs
}
from
'
@dcloudio/uni-cli-shared
'
import
{
MiniProgramFilterOptions
,
missingModuleName
,
parseRenderjs
,
}
from
'
@dcloudio/uni-cli-shared
'
const
debugRenderjs
=
debug
(
'
vite:uni:renderjs
'
)
const
filtersCache
=
new
Map
<
ResolvedConfig
,
MiniProgramFilterOptions
[]
>
()
export
function
getFiltersCache
(
resolvedConfig
:
ResolvedConfig
)
{
return
filtersCache
.
get
(
resolvedConfig
)
||
[]
}
export
function
uniRenderjsPlugin
():
Plugin
{
let
resolvedConfig
:
ResolvedConfig
return
{
name
:
'
vite:uni-mp-renderjs
'
,
configResolved
(
config
)
{
resolvedConfig
=
config
},
buildStart
()
{
filtersCache
.
set
(
resolvedConfig
,
[])
},
transform
(
code
,
id
)
{
const
{
type
,
name
}
=
parseRenderjs
(
id
)
if
(
!
type
)
{
...
...
@@ -18,12 +35,12 @@ export function uniRenderjsPlugin(): Plugin {
this
.
error
(
missingModuleName
(
type
,
code
))
}
if
(
type
===
'
wxs
'
)
{
console
.
log
(
'
wxs
'
,
id
,
code
)
// this.emitFile({
// type: 'asset'
,
// fileName: ''
,
// source:
code,
//
})
filtersCache
.
get
(
resolvedConfig
)
!
.
push
({
id
,
type
,
name
,
code
,
})
}
return
{
code
:
'
export default {}
'
,
...
...
packages/uni-mp-weixin/dist/uni.compiler.js
浏览文件 @
f32c4923
...
...
@@ -107,6 +107,18 @@ const options = {
source
,
},
template
:
{
filter
:
{
extname
:
'
.wxs
'
,
tag
:
'
wxs
'
,
generate
(
filter
)
{
if
(
filter
.
src
)
{
return
`<wxs src="/
${
filter
.
src
}
.wxs" module="
${
filter
.
name
}
"/>`
;
}
return
`<wxs module="
${
filter
.
name
}
">
${
filter
.
code
}
</wxs>`
;
},
},
slot
:
{
fallback
:
false
,
},
...
...
@@ -123,10 +135,6 @@ const options = {
'
--window-right
'
:
'
0px
'
,
},
},
filter
:
{
extname
:
'
.wxs
'
,
tag
:
'
wxs
'
,
},
};
var
index
=
[
uniMiniProgramWeixinPlugin
,
...
initMiniProgramPlugin__default
[
"
default
"
](
options
)];
...
...
packages/uni-mp-weixin/src/plugin/index.ts
浏览文件 @
f32c4923
...
...
@@ -61,6 +61,18 @@ const options: UniMiniProgramPluginOptions = {
source
,
},
template
:
{
filter
:
{
extname
:
'
.wxs
'
,
tag
:
'
wxs
'
,
generate
(
filter
)
{
if
(
filter
.
src
)
{
return
`<wxs src="/
${
filter
.
src
}
.wxs" module="
${
filter
.
name
}
"/>`
}
return
`<wxs module="
${
filter
.
name
}
">
${
filter
.
code
}
</wxs>`
},
},
slot
:
{
fallback
:
false
,
},
...
...
@@ -77,10 +89,6 @@ const options: UniMiniProgramPluginOptions = {
'
--window-right
'
:
'
0px
'
,
},
},
filter
:
{
extname
:
'
.wxs
'
,
tag
:
'
wxs
'
,
},
}
export
default
[
uniMiniProgramWeixinPlugin
,
...
initMiniProgramPlugin
(
options
)]
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录