Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lzb_79
uni-app
提交
24dfc6f6
U
uni-app
项目概览
lzb_79
/
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,体验更适合开发者的 AI 搜索 >>
提交
24dfc6f6
编写于
8月 08, 2021
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor(h5): renderjs
上级
a9950fbe
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
125 addition
and
2 deletion
+125
-2
packages/uni-cli-shared/src/index.ts
packages/uni-cli-shared/src/index.ts
+1
-0
packages/uni-cli-shared/src/renderjs.ts
packages/uni-cli-shared/src/renderjs.ts
+36
-0
packages/uni-h5-vite/dist/index.js
packages/uni-h5-vite/dist/index.js
+2
-0
packages/uni-h5-vite/dist/plugins/renderjs.js
packages/uni-h5-vite/dist/plugins/renderjs.js
+41
-0
packages/uni-h5-vite/src/index.ts
packages/uni-h5-vite/src/index.ts
+2
-0
packages/uni-h5-vite/src/plugins/renderjs.ts
packages/uni-h5-vite/src/plugins/renderjs.ts
+43
-0
packages/vite-plugin-uni/src/configResolved/plugins/index.ts
packages/vite-plugin-uni/src/configResolved/plugins/index.ts
+0
-2
未找到文件。
packages/uni-cli-shared/src/index.ts
浏览文件 @
24dfc6f6
...
...
@@ -11,5 +11,6 @@ export * from './easycom'
export
*
from
'
./constants
'
export
*
from
'
./preprocess
'
export
*
from
'
./postcss
'
export
*
from
'
./renderjs
'
export
{
checkUpdate
}
from
'
./checkUpdate
'
packages/uni-cli-shared/src/renderjs.ts
0 → 100644
浏览文件 @
24dfc6f6
import
{
parseVueRequest
}
from
'
./vite/utils/url
'
const
WXS_RE
=
/vue&type=wxs/
export
function
isWxs
(
id
:
string
)
{
return
WXS_RE
.
test
(
id
)
}
const
RENDERJS_RE
=
/vue&type=renderjs/
export
function
isRenderjs
(
id
:
string
)
{
return
RENDERJS_RE
.
test
(
id
)
}
export
function
parseRenderjs
(
id
:
string
)
{
if
(
isWxs
(
id
))
{
return
{
type
:
'
wxs
'
,
name
:
(
parseVueRequest
(
id
).
query
as
any
).
name
as
string
,
}
as
const
}
if
(
isRenderjs
(
id
))
{
return
{
type
:
'
renderjs
'
,
name
:
(
parseVueRequest
(
id
).
query
as
any
).
name
as
string
,
}
as
const
}
return
{
type
:
''
,
name
:
''
,
}
as
const
}
export
function
missingModuleName
(
type
:
'
wxs
'
|
'
renderjs
'
,
code
:
string
)
{
return
`<script module="missing module name" lang="
${
type
}
">
${
code
}
</script>`
}
packages/uni-h5-vite/dist/index.js
浏览文件 @
24dfc6f6
...
...
@@ -7,6 +7,7 @@ const inject_1 = require("./plugins/inject");
const
mainJs_1
=
require
(
"
./plugins/mainJs
"
);
const
manifestJson_1
=
require
(
"
./plugins/manifestJson
"
);
const
pagesJson_1
=
require
(
"
./plugins/pagesJson
"
);
const
renderjs_1
=
require
(
"
./plugins/renderjs
"
);
const
resolveId_1
=
require
(
"
./plugins/resolveId
"
);
const
setup_1
=
require
(
"
./plugins/setup
"
);
const
ssr_1
=
require
(
"
./plugins/ssr
"
);
...
...
@@ -20,5 +21,6 @@ exports.default = [
css_1
.
uniCssPlugin
(),
ssr_1
.
uniSSRPlugin
(),
setup_1
.
uniSetupPlugin
(),
renderjs_1
.
uniRenderjsPlugin
(),
plugin_1
.
UniH5Plugin
,
];
packages/uni-h5-vite/dist/plugins/renderjs.js
0 → 100644
浏览文件 @
24dfc6f6
"
use strict
"
;
var
__importDefault
=
(
this
&&
this
.
__importDefault
)
||
function
(
mod
)
{
return
(
mod
&&
mod
.
__esModule
)
?
mod
:
{
"
default
"
:
mod
};
};
Object
.
defineProperty
(
exports
,
"
__esModule
"
,
{
value
:
true
});
exports
.
uniRenderjsPlugin
=
void
0
;
const
debug_1
=
__importDefault
(
require
(
"
debug
"
));
const
compiler_sfc_1
=
require
(
"
@vue/compiler-sfc
"
);
const
uni_cli_shared_1
=
require
(
"
@dcloudio/uni-cli-shared
"
);
const
debugRenderjs
=
debug_1
.
default
(
'
vite:uni:renderjs
'
);
function
uniRenderjsPlugin
()
{
return
{
name
:
'
vite:uni-h5-renderjs
'
,
transform
(
code
,
id
)
{
const
{
type
,
name
}
=
uni_cli_shared_1
.
parseRenderjs
(
id
);
if
(
!
type
)
{
return
;
}
debugRenderjs
(
id
);
if
(
!
name
)
{
this
.
error
(
uni_cli_shared_1
.
missingModuleName
(
type
,
code
));
}
return
`
${
compiler_sfc_1
.
rewriteDefault
(
code
.
replace
(
/module
\.
exports
\s
*=/
,
'
export default
'
),
'
_sfc_
'
+
type
)}
${
type
===
'
renderjs
'
?
genRenderjsCode
(
name
)
:
genWxsCode
(
name
)}
`
;
},
};
}
exports
.
uniRenderjsPlugin
=
uniRenderjsPlugin
;
function
genRenderjsCode
(
name
)
{
return
`export default Comp => {
if(!Comp.mixins){Comp.mixins = []}
Comp.mixins.push({beforeCreate(){ this['
${
name
}
'] = this }})
Comp.mixins.push(_sfc_renderjs)
}`
;
}
function
genWxsCode
(
name
)
{
return
`export default Comp => {
if(!Comp.mixins){Comp.mixins = []}
Comp.mixins.push({beforeCreate(){ this['
${
name
}
'] = _sfc_wxs }})
}`
;
}
packages/uni-h5-vite/src/index.ts
浏览文件 @
24dfc6f6
...
...
@@ -5,6 +5,7 @@ import { uniInjectPlugin } from './plugins/inject'
import
{
uniMainJsPlugin
}
from
'
./plugins/mainJs
'
import
{
uniManifestJsonPlugin
}
from
'
./plugins/manifestJson
'
import
{
uniPagesJsonPlugin
}
from
'
./plugins/pagesJson
'
import
{
uniRenderjsPlugin
}
from
'
./plugins/renderjs
'
import
{
uniResolveIdPlugin
}
from
'
./plugins/resolveId
'
import
{
uniSetupPlugin
}
from
'
./plugins/setup
'
import
{
uniSSRPlugin
}
from
'
./plugins/ssr
'
...
...
@@ -19,5 +20,6 @@ export default [
uniCssPlugin
(),
uniSSRPlugin
(),
uniSetupPlugin
(),
uniRenderjsPlugin
(),
UniH5Plugin
,
]
packages/uni-h5-vite/src/plugins/renderjs.ts
0 → 100644
浏览文件 @
24dfc6f6
import
debug
from
'
debug
'
import
{
Plugin
}
from
'
vite
'
import
{
rewriteDefault
}
from
'
@vue/compiler-sfc
'
import
{
missingModuleName
,
parseRenderjs
}
from
'
@dcloudio/uni-cli-shared
'
const
debugRenderjs
=
debug
(
'
vite:uni:renderjs
'
)
export
function
uniRenderjsPlugin
():
Plugin
{
return
{
name
:
'
vite:uni-h5-renderjs
'
,
transform
(
code
,
id
)
{
const
{
type
,
name
}
=
parseRenderjs
(
id
)
if
(
!
type
)
{
return
}
debugRenderjs
(
id
)
if
(
!
name
)
{
this
.
error
(
missingModuleName
(
type
,
code
))
}
return
`
${
rewriteDefault
(
code
.
replace
(
/module
\.
exports
\s
*=/
,
'
export default
'
),
'
_sfc_
'
+
type
)}
${
type
===
'
renderjs
'
?
genRenderjsCode
(
name
)
:
genWxsCode
(
name
)}
`
},
}
}
function
genRenderjsCode
(
name
:
string
)
{
return
`export default Comp => {
if(!Comp.mixins){Comp.mixins = []}
Comp.mixins.push({beforeCreate(){ this['
${
name
}
'] = this }})
Comp.mixins.push(_sfc_renderjs)
}`
}
function
genWxsCode
(
name
:
string
)
{
return
`export default Comp => {
if(!Comp.mixins){Comp.mixins = []}
Comp.mixins.push({beforeCreate(){ this['
${
name
}
'] = _sfc_wxs }})
}`
}
packages/vite-plugin-uni/src/configResolved/plugins/index.ts
浏览文件 @
24dfc6f6
...
...
@@ -12,7 +12,6 @@ import { uniPreCssPlugin } from './preCss'
import
{
uniEasycomPlugin
}
from
'
./easycom
'
import
{
uniStaticPlugin
}
from
'
./static
'
import
{
uniRenderjsPlugin
}
from
'
./renderjs
'
import
{
uniPreVuePlugin
}
from
'
./preVue
'
import
{
uniSSRPlugin
}
from
'
./ssr
'
import
{
uniResolveIdPlugin
}
from
'
./resolveId
'
...
...
@@ -60,7 +59,6 @@ export function initPlugins(
'
vite:css
'
)
addPlugin
(
plugins
,
uniPreVuePlugin
(),
'
vite:vue
'
,
'
pre
'
)
addPlugin
(
plugins
,
uniRenderjsPlugin
(),
'
vite:vue
'
)
addPlugin
(
plugins
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录