diff --git a/packages/uni-cloud/lib/uni.plugin.js b/packages/uni-cloud/lib/uni.plugin.js index 1f6d5f43af28140f3bdb8fdcebbc54c683ad4168..43580e38101eee758fa9a1a100c5d4b4b397a7a9 100644 --- a/packages/uni-cloud/lib/uni.plugin.js +++ b/packages/uni-cloud/lib/uni.plugin.js @@ -96,6 +96,23 @@ function initUniCloudEnv() { catch (e) { } } exports.default = () => [ + (0, uni_cli_shared_1.defineUniMainJsPlugin)((opts) => { + return { + name: 'uni:cloud', + enforce: 'pre', + transform(code, id) { + if (!opts.filter(id)) { + return; + } + if (uniCloudSpaces.length) { + return { + code: code + `;import '@dcloudio/uni-cloud';`, + map: null, + }; + } + }, + }; + }), uniCloudPlugin(), (0, uni_cli_shared_1.uniViteInjectPlugin)('uni:cloud-inject', { exclude: [...uni_cli_shared_1.COMMON_EXCLUDE], diff --git a/packages/uni-cloud/src/uni.plugin.ts b/packages/uni-cloud/src/uni.plugin.ts index 21b8f5c1c67af0de09e8d251a0283f98e412d872..d92e47ce414fb8fe6b3df58f3eb065f67b6f664a 100644 --- a/packages/uni-cloud/src/uni.plugin.ts +++ b/packages/uni-cloud/src/uni.plugin.ts @@ -1,6 +1,7 @@ import { isArray } from '@vue/shared' import { once } from '@dcloudio/uni-shared' import { + defineUniMainJsPlugin, COMMON_EXCLUDE, isInHybridNVue, uniViteInjectPlugin, @@ -123,6 +124,23 @@ function initUniCloudEnv() { } export default () => [ + defineUniMainJsPlugin((opts) => { + return { + name: 'uni:cloud', + enforce: 'pre', + transform(code, id) { + if (!opts.filter(id)) { + return + } + if (uniCloudSpaces.length) { + return { + code: code + `;import '@dcloudio/uni-cloud';`, + map: null, + } + } + }, + } + }), uniCloudPlugin(), uniViteInjectPlugin('uni:cloud-inject', { exclude: [...COMMON_EXCLUDE],