Skip to content

Commit

Permalink
wip: uni_modules 编译模式
Browse files Browse the repository at this point in the history
  • Loading branch information
fxy060608 committed May 2, 2024
1 parent fbc2c76 commit b66f12b
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ exports[`uni_modules playground uni-app-x build:app-ios 2`] = `
import Logo from './test-com2/components/test-com2-1/logo.png';
import _export_sfc from 'plugin-vue:export-helper';
function test() { }
const _sfc_main$1 = defineComponent({
data() {
return {
Expand Down Expand Up @@ -84,7 +86,7 @@ function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
}
const testCom22 = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render], ["styles", [_style_0]]]);
export { testCom21 as TestCom21, testCom22 as TestCom22 };
export { testCom21 as TestCom21, testCom22 as TestCom22, test };
"
`;

Expand Down Expand Up @@ -153,6 +155,8 @@ import { Text } from "@dcloudio/uni-h5";
import { defineComponent, openBlock, createBlock, withCtx, createTextVNode, toDisplayString } from "vue";
import Logo from "./test-com2/components/test-com2-1/logo.png";
import _export_sfc from "plugin-vue:export-helper";
function test() {
}
const _sfc_main$1 = defineComponent({
data() {
return {
Expand Down Expand Up @@ -191,7 +195,8 @@ function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
const testCom22 = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-6088c0cc"]]);
export {
testCom21 as TestCom21,
testCom22 as TestCom22
testCom22 as TestCom22,
test
};
"
`;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './index'

import TestCom21 from './components/test-com2-1/test-com2-1.vue'
import TestCom22 from './components/test-com2-2/test-com2-2.vue'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './utils'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export function test(){}
27 changes: 10 additions & 17 deletions packages/uni-cli-shared/src/uni_modules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -385,24 +385,17 @@ export function parseEncryptUniModules(
fs.readdirSync(modulesDir).forEach((uniModuleDir) => {
// 判断是否是加密插件
if (fs.existsSync(path.resolve(modulesDir, uniModuleDir, 'encrypt'))) {
if (
// 手动指定了加密入口
fs.existsSync(
path.resolve(modulesDir, uniModuleDir, 'index.encrypt.js')
)
) {
uniModules[uniModuleDir] = []
} else {
// 解析加密的 easyCom 插件列表
const components = parseEncryptEasyComComponents(
uniModuleDir,
inputDir,
detectBinary
)
if (components.length) {
uniModules[uniModuleDir] = components
}
// 非utssdk插件
if (fs.existsSync(path.resolve(modulesDir, uniModuleDir, 'utssdk'))) {
return
}
// 解析加密的 easyCom 插件列表
const components = parseEncryptEasyComComponents(
uniModuleDir,
inputDir,
detectBinary
)
uniModules[uniModuleDir] = components
}
})
}
Expand Down
23 changes: 16 additions & 7 deletions packages/uni-cli-shared/src/vite/cloud.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ function initEncryptUniModulesAlias(): AliasOptions {
]
}

const indexFiles = ['index.uts', 'index.ts', 'index.js']
function hasIndexFile(uniModuleDir: string) {
return fs.readdirSync(uniModuleDir).some((file) => indexFiles.includes(file))
}

function initEncryptUniModulesBuildOptions(inputDir: string): BuildOptions {
const modules = parseEncryptUniModules(inputDir, false)
const moduleNames = Object.keys(modules)
Expand All @@ -125,15 +130,19 @@ function initEncryptUniModulesBuildOptions(inputDir: string): BuildOptions {
module,
'index.encrypt.js'
)
// 生成 index.encrypt.js,如果 length 为 0,说明是手动指定了 index.encrypt.js
const codes: string[] = []
if (hasIndexFile(path.resolve(inputDir, 'uni_modules', module))) {
codes.push(`export * from './index'`)
}
// easyCom
if (modules[module].length) {
fs.writeFileSync(
indexEncryptFile,
genEncryptEasyComModuleIndex(modules[module])
)
codes.push(genEncryptEasyComModuleIndex(modules[module]))
}
if (codes.length) {
fs.writeFileSync(indexEncryptFile, codes.join(`\n`))
// 输出 xxx.encrypt ,确保相对路径的准确性,因为真正引用的时候,是从 @/uni_modules/xxx 引入的
input[module + '.encrypt'] = indexEncryptFile
}
// 输出 xxx.encrypt ,确保相对路径的准确性,因为真正引用的时候,是从 @/uni_modules/xxx 引入的
input[module + '.encrypt'] = indexEncryptFile
})
return {
lib: false, // 不使用 lib 模式,lib模式会直接内联资源
Expand Down

0 comments on commit b66f12b

Please sign in to comment.