提交 0f89a16a 编写于 作者: fxy060608's avatar fxy060608

wip: uni_modules 编译模式

上级 ad023b0b
......@@ -241,7 +241,7 @@ open class GenUniModulesTestCom2ComponentsTestCom21TestCom21 : VueComponent {
createElementVNode("image", utsMapOf("src" to _ctx.api), null, 8, utsArrayOf(
"src"
)),
createElementVNode("video")
createElementVNode("video", utsMapOf("src" to "https://qiniu-web-assets.dcloud.net.cn/video/sample/2minute-demo.mp4"))
), 64);
}
open var msg: String by \`$data\`;
......@@ -460,7 +460,7 @@ function _sfc_render$1(_ctx, _cache, $props, $setup, $data, $options) {
return openBlock(), createElementBlock(Fragment, null, [
createElementVNode("text", { class: "text" }, toDisplayString($data.msg) + toDisplayString($data.api), 1),
createElementVNode("image", { src: $data.api }, null, 8, ["src"]),
createElementVNode("video")
createElementVNode("video", { src: "https://qiniu-web-assets.dcloud.net.cn/video/sample/2minute-demo.mp4" })
], 64);
}
const testCom21 = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["render", _sfc_render$1], ["styles", [_style_0$1]]]);
......@@ -617,10 +617,10 @@ exports[`uni_modules playground uni-app-x build:h5 5`] = `
.text[data-v-d600df3c] {
.text[data-v-e2332c62] {
color: red;
}
.image[data-v-d600df3c] {
.image[data-v-e2332c62] {
background: url('@/uni_modules/test-com2/components/test-com2-1/api.png');
}
"
......@@ -668,10 +668,10 @@ function _sfc_render$1(_ctx, _cache, $props, $setup, $data, $options) {
_: 1
}),
createVNode(_component_v_uni_image, { src: $data.api }, null, 8, ["src"]),
createVNode(_component_v_uni_video)
createVNode(_component_v_uni_video, { src: "https://qiniu-web-assets.dcloud.net.cn/video/sample/2minute-demo.mp4" })
], 64);
}
const testCom21 = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["render", _sfc_render$1], ["__scopeId", "data-v-d600df3c"]]);
const testCom21 = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["render", _sfc_render$1], ["__scopeId", "data-v-e2332c62"]]);
const _sfc_main = defineComponent({
data() {
return {
......@@ -958,7 +958,7 @@ open class GenUniModulesTestCom2ComponentsTestCom21TestCom21 : VueComponent {
createElementVNode("image", utsMapOf("src" to _ctx.api), null, 8, utsArrayOf(
"src"
)),
createElementVNode("video")
createElementVNode("video", utsMapOf("src" to "https://qiniu-web-assets.dcloud.net.cn/video/sample/2minute-demo.mp4"))
), 64);
}
open var msg: String by \`$data\`;
......@@ -1212,7 +1212,7 @@ function _sfc_render$1(_ctx, _cache, $props, $setup, $data, $options) {
/* TEXT */
),
createElementVNode("image", { src: $data.api }, null, 8, ["src"]),
createElementVNode("video")
createElementVNode("video", { src: "https://qiniu-web-assets.dcloud.net.cn/video/sample/2minute-demo.mp4" })
],
64
/* STABLE_FRAGMENT */
......@@ -1465,7 +1465,7 @@ function _sfc_render$1(_ctx, _cache, $props, $setup, $data, $options) {
/* STABLE */
}),
createVNode(_component_v_uni_image, { src: $data.api }, null, 8, ["src"]),
createVNode(_component_v_uni_video)
createVNode(_component_v_uni_video, { src: "https://qiniu-web-assets.dcloud.net.cn/video/sample/2minute-demo.mp4" })
],
64
/* STABLE_FRAGMENT */
......
<template>
<text class="text">{{ msg }}{{ api }}</text>
<image :src="api" />
<video />
<video src="https://qiniu-web-assets.dcloud.net.cn/video/sample/2minute-demo.mp4" />
</template>
<script>
import Api from './api.png'
......
......@@ -13262,15 +13262,15 @@ function parseTheme(pageStyle) {
function useTabBarThemeChange(tabBar, options) {
if (__uniConfig.darkmode) {
const fn = () => {
const { list = [], color, selectedColor, backgroundColor, borderStyle, } = parseTheme(options);
tabBar &&
const { list = [], color, selectedColor, backgroundColor, borderStyle, midButton, } = parseTheme(options);
if (tabBar) {
tabBar.setTabBarStyle({
color,
selectedColor,
backgroundColor,
borderStyle,
midButton,
});
tabBar &&
tabBar.setTabBarItems({
list: list.map((item) => ({
iconPath: item.iconPath,
......@@ -13278,6 +13278,7 @@ function useTabBarThemeChange(tabBar, options) {
visible: item.visible,
})),
});
}
};
// 由于应用首次启动获取不到手机 theme 应用首次启动设置下 tabBar
fn();
......
......@@ -34,7 +34,14 @@ import {
locStub,
toValidAssetId,
} from '@vue/compiler-core'
import { NOOP, isArray, isString, isSymbol } from '@vue/shared'
import {
NOOP,
camelize,
capitalize,
isArray,
isString,
isSymbol,
} from '@vue/shared'
import { type ParserPlugin, parseExpression } from '@babel/parser'
import {
isCompoundExpressionNode,
......@@ -318,8 +325,17 @@ function genEasyComImports(
}
const source = matchEasyCom(id, true)
if (source) {
const componentId = toValidAssetId(id, 'easycom' as 'component')
push(`import ${componentId} from '${source}'`)
if (source.includes('?uts-proxy')) {
push(
`import { ${genEncryptUniModuleEasyComClass(
id,
parseUniModuleId(source)
)} } from '${source}';`
)
} else {
const componentId = toValidAssetId(id, 'easycom' as 'component')
push(`import ${componentId} from '${source}'`)
}
newline()
}
}
......@@ -352,12 +368,25 @@ function genAssets(
if (type === 'component') {
const source = matchEasyCom(id, false)
if (source) {
const easyComponentId = toValidAssetId(id, 'easycom' as 'component')
let importCode = ''
const componentId = toValidAssetId(id, type)
assetCode = `const ${componentId} = ${helper(
RESOLVE_EASY_COMPONENT
)}(${JSON.stringify(id)},${easyComponentId})`
const importCode = `import ${easyComponentId} from '${source}';`
// 加密 easyCom
if (source.includes('?uts-proxy')) {
const easyComponentId = genEncryptUniModuleEasyComClass(
id,
parseUniModuleId(source)
)
assetCode = `const ${componentId} = ${helper(
RESOLVE_EASY_COMPONENT
)}(${JSON.stringify(id)},${easyComponentId})`
importCode = `import { ${easyComponentId} } from '${source}';`
} else {
const easyComponentId = toValidAssetId(id, 'easycom' as 'component')
assetCode = `const ${componentId} = ${helper(
RESOLVE_EASY_COMPONENT
)}(${JSON.stringify(id)},${easyComponentId})`
importCode = `import ${easyComponentId} from '${source}';`
}
if (!importEasyComponents.includes(importCode)) {
importEasyComponents.push(importCode)
addEasyComponentAutoImports(
......@@ -384,6 +413,23 @@ function genAssets(
}
}
function parseUniModuleId(source: string) {
const parts = source.split('/')
return parts[parts.length - 1].replace('?uts-proxy', '')
}
// GenUniModulesTestCom1ComponentsTestCom11TestCom11Class
function genEncryptUniModuleEasyComClass(
componentName: string,
uniModuleId: string
) {
return capitalize(
camelize(
`gen-uni-modules-${uniModuleId}-components-${componentName}-${componentName}-class`
)
)
}
function isText(n: string | CodegenNode) {
return (
isString(n) ||
......
......@@ -12940,6 +12940,7 @@ const TabBar = /* @__PURE__ */ defineSystemComponent({
tabBar2.color = tabBarStyle.color;
tabBar2.selectedColor = tabBarStyle.selectedColor;
tabBar2.blurEffect = tabBarStyle.blurEffect;
tabBar2.midButton = tabBarStyle.midButton;
if (tabBarStyle.list && tabBarStyle.list.length) {
tabBarStyle.list.forEach((item, index2) => {
tabBar2.list[index2].iconPath = item.iconPath;
......@@ -13569,8 +13570,13 @@ function updateBackgroundColorContent(backgroundColorContent) {
}
function useBackgroundColorContent(pageMeta) {
function update() {
updateBackgroundColorContent(pageMeta.backgroundColorContent || "");
if (pageMeta.backgroundColorContent) {
updateBackgroundColorContent(
parseTheme({ backgroundColorContent: pageMeta.backgroundColorContent }).backgroundColorContent
);
}
}
onThemeChange(update);
vue.watchEffect(update);
}
function usePageHeadTransparentBackgroundColor(backgroundColor) {
......
......@@ -24200,6 +24200,7 @@ const TabBar = /* @__PURE__ */ defineSystemComponent({
tabBar2.color = tabBarStyle.color;
tabBar2.selectedColor = tabBarStyle.selectedColor;
tabBar2.blurEffect = tabBarStyle.blurEffect;
tabBar2.midButton = tabBarStyle.midButton;
if (tabBarStyle.list && tabBarStyle.list.length) {
tabBarStyle.list.forEach((item, index2) => {
tabBar2.list[index2].iconPath = item.iconPath;
......@@ -26835,8 +26836,13 @@ function updateBackgroundColorContent(backgroundColorContent) {
}
function useBackgroundColorContent(pageMeta) {
function update() {
updateBackgroundColorContent(pageMeta.backgroundColorContent || "");
if (pageMeta.backgroundColorContent) {
updateBackgroundColorContent(
parseTheme({ backgroundColorContent: pageMeta.backgroundColorContent }).backgroundColorContent
);
}
}
onThemeChange$2(update);
watchEffect(update);
onActivated(update);
}
......
......@@ -11618,6 +11618,7 @@ const TabBar = /* @__PURE__ */ defineSystemComponent({
tabBar2.color = tabBarStyle.color;
tabBar2.selectedColor = tabBarStyle.selectedColor;
tabBar2.blurEffect = tabBarStyle.blurEffect;
tabBar2.midButton = tabBarStyle.midButton;
if (tabBarStyle.list && tabBarStyle.list.length) {
tabBarStyle.list.forEach((item, index2) => {
tabBar2.list[index2].iconPath = item.iconPath;
......
......@@ -22418,6 +22418,7 @@ const TabBar = /* @__PURE__ */ defineSystemComponent({
tabBar2.color = tabBarStyle.color;
tabBar2.selectedColor = tabBarStyle.selectedColor;
tabBar2.blurEffect = tabBarStyle.blurEffect;
tabBar2.midButton = tabBarStyle.midButton;
if (tabBarStyle.list && tabBarStyle.list.length) {
tabBarStyle.list.forEach((item, index2) => {
tabBar2.list[index2].iconPath = item.iconPath;
......
......@@ -156,7 +156,7 @@ async function compileEncryptByUniHelpers(pluginDir: string) {
addInjectComponents(pkg.uni_modules?.artifacts?.components || [])
return {
dir: outputPluginDir,
code: '',
code: 'export default {}',
deps: [] as string[],
encrypt: true,
inject_apis,
......@@ -230,11 +230,16 @@ async function compileEncryptByUniHelpers(pluginDir: string) {
} else if (msg) {
console.error(msg)
}
const assets = path.resolve(cachePluginDir, 'assets')
if (fs.existsSync(assets)) {
fs.copySync(assets, path.resolve(outputDir, pluginRelativeDir, 'assets'))
}
}
return {
dir: outputPluginDir,
code: '',
code: 'export default {}',
deps: [] as string[],
encrypt: true,
inject_apis: [],
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册