Skip to content

Commit

Permalink
wip: uni_modules 编译模式
Browse files Browse the repository at this point in the history
  • Loading branch information
fxy060608 committed Apr 30, 2024
1 parent 776f595 commit c222644
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 285 deletions.
276 changes: 4 additions & 272 deletions packages/playground/__tests__/__snapshots__/uni_modules.spec.ts.snap
Original file line number Diff line number Diff line change
@@ -1,275 +1,7 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`uni_modules playground uni-app build:app 1`] = `
"import Logo from "../../test-com1/components/test-com1-1/logo.png";
import { openBlock, createElementBlock, Fragment, createElementVNode, toDisplayString } from "vue";
import _export_sfc from "plugin-vue:export-helper";
const _sfc_main$1 = {
data() {
return {
msg: "test-com1-1",
logo: Logo
};
}
};
function _sfc_render$1(_ctx, _cache, $props, $setup, $data, $options) {
return openBlock(), createElementBlock(Fragment, null, [
createElementVNode("text", { class: "text" }, toDisplayString($data.msg) + toDisplayString($data.logo), 1),
createElementVNode("image", { src: Logo })
], 64);
}
const testCom11 = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["render", _sfc_render$1]]);
const _sfc_main = {
data() {
return {
msg: "test-com1-2",
logo: Logo
};
}
};
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
return openBlock(), createElementBlock(Fragment, null, [
createElementVNode("text", { class: "text2" }, toDisplayString($data.msg) + toDisplayString($data.logo), 1),
createElementVNode("image", { src: Logo })
], 64);
}
const testCom12 = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render]]);
export {
testCom11 as TestCom11,
testCom12 as TestCom12
};
"
`;

exports[`uni_modules playground uni-app build:app 2`] = `
"import Logo from "../../test-com2/components/test-com2-1/logo.png";
import { openBlock, createElementBlock, toDisplayString } from "vue";
import _export_sfc from "plugin-vue:export-helper";
const _sfc_main$1 = {
data() {
return {
msg: "test-com2-1",
logo: Logo
};
}
};
function _sfc_render$1(_ctx, _cache, $props, $setup, $data, $options) {
return openBlock(), createElementBlock("text", { class: "text" }, toDisplayString($data.msg) + toDisplayString($data.logo), 1);
}
const testCom21 = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["render", _sfc_render$1]]);
const _sfc_main = {
data() {
return {
msg: "test-com2-2",
logo: Logo
};
}
};
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
return openBlock(), createElementBlock("text", { class: "text2" }, toDisplayString($data.msg) + toDisplayString($data.logo), 1);
}
const testCom22 = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render]]);
export {
testCom21 as TestCom21,
testCom22 as TestCom22
};
"
`;

exports[`uni_modules playground uni-app build:app 3`] = `
"
.text {
color: red;
}
.image {
background: url('@/uni_modules/test-com1/components/test-com1-1/logo.png');
}
"
`;

exports[`uni_modules playground uni-app build:app 4`] = `
"
.text2 {
color: red;
}
"
`;

exports[`uni_modules playground uni-app build:app 5`] = `
"
.text {
color: red;
}
.image {
background: url('@/uni_modules/test-com2/components/test-com2-1/logo.png');
}
"
`;

exports[`uni_modules playground uni-app build:app 6`] = `
"
.text2 {
color: red;
}
"
`;

exports[`uni_modules playground uni-app build:h5 1`] = `
"import "@dcloudio/uni-components/style/text.css";
import { Text, Image } from "@dcloudio/uni-h5";
import "@dcloudio/uni-components/style/image.css";
import "@dcloudio/uni-components/style/resize-sensor.css";
import Logo from "../../test-com1/components/test-com1-1/logo.png";
import { openBlock, createElementBlock, Fragment, createVNode, withCtx, createTextVNode, toDisplayString } from "vue";
import _export_sfc from "plugin-vue:export-helper";
const _sfc_main$1 = {
data() {
return {
msg: "test-com1-1",
logo: Logo
};
}
};
function _sfc_render$1(_ctx, _cache, $props, $setup, $data, $options) {
const _component_v_uni_text = Text;
const _component_v_uni_image = Image;
return openBlock(), createElementBlock(Fragment, null, [
createVNode(_component_v_uni_text, { class: "text" }, {
default: withCtx(() => [
createTextVNode(toDisplayString($data.msg) + toDisplayString($data.logo), 1)
]),
_: 1
}),
createVNode(_component_v_uni_image, { src: Logo })
], 64);
}
const testCom11 = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["render", _sfc_render$1], ["__scopeId", "data-v-a4ecbcc3"]]);
const _sfc_main = {
data() {
return {
msg: "test-com1-2",
logo: Logo
};
}
};
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
const _component_v_uni_text = Text;
const _component_v_uni_image = Image;
return openBlock(), createElementBlock(Fragment, null, [
createVNode(_component_v_uni_text, { class: "text2" }, {
default: withCtx(() => [
createTextVNode(toDisplayString($data.msg) + toDisplayString($data.logo), 1)
]),
_: 1
}),
createVNode(_component_v_uni_image, { src: Logo })
], 64);
}
const testCom12 = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-4d21cdc3"]]);
export {
testCom11 as TestCom11,
testCom12 as TestCom12
};
"
`;

exports[`uni_modules playground uni-app build:h5 2`] = `
"import "@dcloudio/uni-components/style/text.css";
import { Text } from "@dcloudio/uni-h5";
import Logo from "../../test-com2/components/test-com2-1/logo.png";
import { openBlock, createBlock, withCtx, createTextVNode, toDisplayString } from "vue";
import _export_sfc from "plugin-vue:export-helper";
const _sfc_main$1 = {
data() {
return {
msg: "test-com2-1",
logo: Logo
};
}
};
function _sfc_render$1(_ctx, _cache, $props, $setup, $data, $options) {
const _component_v_uni_text = Text;
return openBlock(), createBlock(_component_v_uni_text, { class: "text" }, {
default: withCtx(() => [
createTextVNode(toDisplayString($data.msg) + toDisplayString($data.logo), 1)
]),
_: 1
});
}
const testCom21 = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["render", _sfc_render$1], ["__scopeId", "data-v-f33122a3"]]);
const _sfc_main = {
data() {
return {
msg: "test-com2-2",
logo: Logo
};
}
};
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
const _component_v_uni_text = Text;
return openBlock(), createBlock(_component_v_uni_text, { class: "text2" }, {
default: withCtx(() => [
createTextVNode(toDisplayString($data.msg) + toDisplayString($data.logo), 1)
]),
_: 1
});
}
const testCom22 = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-ac423ad8"]]);
export {
testCom21 as TestCom21,
testCom22 as TestCom22
};
"
`;

exports[`uni_modules playground uni-app build:h5 3`] = `
"
.text[data-v-a4ecbcc3] {
color: red;
}
.image[data-v-a4ecbcc3] {
background: url('@/uni_modules/test-com1/components/test-com1-1/logo.png');
}
"
`;

exports[`uni_modules playground uni-app build:h5 4`] = `
"
.text2[data-v-4d21cdc3] {
color: red;
}
"
`;

exports[`uni_modules playground uni-app build:h5 5`] = `
"
.text[data-v-f33122a3] {
color: red;
}
.image[data-v-f33122a3] {
background: url('@/uni_modules/test-com2/components/test-com2-1/logo.png');
}
"
`;

exports[`uni_modules playground uni-app build:h5 6`] = `
"
.text2[data-v-ac423ad8] {
color: red;
}
"
`;

exports[`uni_modules playground uni-app-x build:app-ios 1`] = `
"import Logo from "../../test-com1/components/test-com1-1/logo.png";
"import Logo from "./test-com1/components/test-com1-1/logo.png";
import { openBlock, createElementBlock, Fragment, createElementVNode, toDisplayString } from "vue";
import _export_sfc from "plugin-vue:export-helper";
const _sfc_main$1 = {
Expand Down Expand Up @@ -310,7 +42,7 @@ export {
`;

exports[`uni_modules playground uni-app-x build:app-ios 2`] = `
"import Logo from "../../test-com2/components/test-com2-1/logo.png";
"import Logo from "./test-com2/components/test-com2-1/logo.png";
import { openBlock, createElementBlock, toDisplayString } from "vue";
import _export_sfc from "plugin-vue:export-helper";
const _sfc_main$1 = {
Expand Down Expand Up @@ -387,7 +119,7 @@ exports[`uni_modules playground uni-app-x build:h5 1`] = `
import { Text, Image } from "@dcloudio/uni-h5";
import "@dcloudio/uni-components/style/image.css";
import "@dcloudio/uni-components/style/resize-sensor.css";
import Logo from "../../test-com1/components/test-com1-1/logo.png";
import Logo from "./test-com1/components/test-com1-1/logo.png";
import { openBlock, createElementBlock, Fragment, createVNode, withCtx, createTextVNode, toDisplayString } from "vue";
import _export_sfc from "plugin-vue:export-helper";
const _sfc_main$1 = {
Expand Down Expand Up @@ -444,7 +176,7 @@ export {
exports[`uni_modules playground uni-app-x build:h5 2`] = `
"import "@dcloudio/uni-components/style/text.css";
import { Text } from "@dcloudio/uni-h5";
import Logo from "../../test-com2/components/test-com2-1/logo.png";
import Logo from "./test-com2/components/test-com2-1/logo.png";
import { openBlock, createBlock, withCtx, createTextVNode, toDisplayString } from "vue";
import _export_sfc from "plugin-vue:export-helper";
const _sfc_main$1 = {
Expand Down
22 changes: 11 additions & 11 deletions packages/playground/__tests__/uni_modules.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ const projectDir = path.resolve(__dirname, '../uni_modules')
describe('uni_modules playground', () => {
jest.setTimeout(50 * 1000)
const modes = {
'uni-app': [
'build:app',
'build:h5',
// 'build:mp-alipay',
// 'build:mp-baidu',
// 'build:mp-kuaishou',
// 'build:mp-lark',
// 'build:mp-qq',
// 'build:mp-toutiao',
// 'build:mp-weixin',
],
// 'uni-app': [
// 'build:app',
// 'build:h5',
// // 'build:mp-alipay',
// // 'build:mp-baidu',
// // 'build:mp-kuaishou',
// // 'build:mp-lark',
// // 'build:mp-qq',
// // 'build:mp-toutiao',
// // 'build:mp-weixin',
// ],
'uni-app-x': [
// "build:app-android",
'build:app-ios',
Expand Down
7 changes: 6 additions & 1 deletion packages/uni-cli-shared/src/easycom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,12 @@ function initAutoScanEasycom(
const ext = extensions[i]
if (files.includes(name + ext)) {
easycoms[`^${name}$`] = is_encrypt_uni_modules
? `@/uni_modules/${uni_modules_plugin_id}?uni_helpers`
? normalizePath(
path.join(
rootDir,
`uni_modules/${uni_modules_plugin_id}?uni_helpers`
)
)
: `${importDir}/${name}${ext}`
break
}
Expand Down
15 changes: 14 additions & 1 deletion packages/uni-cli-shared/src/vite/cloud.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,18 @@ export function uniEncryptUniModulesPlugin(): Plugin {
return `\0${id}`
}
},
generateBundle(_, bundle) {
Object.keys(bundle).forEach((fileName) => {
if (fileName.endsWith('.encrypt.js')) {
const newFileName =
'uni_modules/' +
fileName.replace('.encrypt.js', '/index.encrypt.js')
bundle[newFileName] = bundle[fileName]
bundle[newFileName].fileName = newFileName
delete bundle[fileName]
}
})
},
}
}

Expand Down Expand Up @@ -120,7 +132,8 @@ function initEncryptUniModulesBuildOptions(inputDir: string): BuildOptions {
genEncryptEasyComModuleIndex(modules[module])
)
}
input['uni_modules/' + module + '/index.encrypt'] = indexEncryptFile
// 输出 xxx.encrypt ,确保相对路径的准确性,因为真正引用的时候,是从 @/uni_modules/xxx 引入的
input[module + '.encrypt'] = indexEncryptFile
})
return {
lib: false, // 不使用 lib 模式,lib模式会直接内联资源
Expand Down
2 changes: 2 additions & 0 deletions packages/uni-cli-shared/src/vite/plugins/easycom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ export function uniEasycomPlugin(options: UniEasycomPluginOptions): Plugin {
source,
source.includes('uts-proxy')
? capitalize(camelize(name)) + 'Component'
: source.includes('uni_helpers')
? capitalize(camelize(name))
: ''
)
)
Expand Down

0 comments on commit c222644

Please sign in to comment.