diff --git a/packages/uni-app-vite/dist/plugin/configResolved.js b/packages/uni-app-vite/dist/plugin/configResolved.js index e315c9e38961786f5e2de3c3a156b3ca29b308d0..1886725b381a0e5925d419c4d6ec4a26581aa6bc 100644 --- a/packages/uni-app-vite/dist/plugin/configResolved.js +++ b/packages/uni-app-vite/dist/plugin/configResolved.js @@ -3,16 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true }); exports.configResolved = void 0; const uni_cli_shared_1 = require("@dcloudio/uni-cli-shared"); const configResolved = (config) => { - if (process.env.UNI_APP_CODE_SPLITING) { - initCodeSpliting(config); - } - else { - // 移除 vite 内置的 css post 处理,交由 @dcloudio/uni-cli-shared 的 uniCssPlugin 实现 - uni_cli_shared_1.removePlugins(['vite:asset', 'vite:css-post'], config); - } + // 移除 vite 内置的 css post 处理,交由 @dcloudio/uni-cli-shared 的 uniCssPlugin 实现 + uni_cli_shared_1.removePlugins(['vite:css-post'], config); + // removePlugins('vite:import-analysis', config) + // injectCssPlugin(config) + // injectCssPostPlugin(config) + // injectAssetPlugin(config) }; exports.configResolved = configResolved; -function initCodeSpliting(config) { - uni_cli_shared_1.removePlugins('vite:import-analysis', config); - uni_cli_shared_1.injectAssetAndCssPlugins(config); -} diff --git a/packages/uni-app-vite/src/plugin/configResolved.ts b/packages/uni-app-vite/src/plugin/configResolved.ts index 514f5a14f859f2e16d3988d5e9acb94343eb63e1..908419613842e8c4026234891b05bd05bb5d4a1e 100644 --- a/packages/uni-app-vite/src/plugin/configResolved.ts +++ b/packages/uni-app-vite/src/plugin/configResolved.ts @@ -1,20 +1,18 @@ -import { Plugin, ResolvedConfig } from 'vite' +import { Plugin } from 'vite' import { removePlugins, - injectAssetAndCssPlugins, + // injectAssetPlugin, + // injectCssPlugin, + // injectCssPostPlugin, } from '@dcloudio/uni-cli-shared' export const configResolved: Plugin['configResolved'] = (config) => { - if (process.env.UNI_APP_CODE_SPLITING) { - initCodeSpliting(config as ResolvedConfig) - } else { - // 移除 vite 内置的 css post 处理,交由 @dcloudio/uni-cli-shared 的 uniCssPlugin 实现 - removePlugins(['vite:css-post'], config) - } -} + // 移除 vite 内置的 css post 处理,交由 @dcloudio/uni-cli-shared 的 uniCssPlugin 实现 + removePlugins(['vite:css-post'], config) -function initCodeSpliting(config: ResolvedConfig) { - removePlugins('vite:import-analysis', config) - injectAssetAndCssPlugins(config) + // removePlugins('vite:import-analysis', config) + // injectCssPlugin(config) + // injectCssPostPlugin(config) + // injectAssetPlugin(config) } diff --git a/packages/uni-app-vite/src/plugin/uni.ts b/packages/uni-app-vite/src/plugin/uni.ts index 8bd9d897202e08d48959d2b704f710da0eb650a6..8410c759882f859a75f808e33e7cc83d5e6c96a8 100644 --- a/packages/uni-app-vite/src/plugin/uni.ts +++ b/packages/uni-app-vite/src/plugin/uni.ts @@ -12,8 +12,4 @@ export const uniOptions: UniVitePlugin['uni'] = { transformEvent: { tap: 'click', }, - transformAssetUrls: { - base: '/', - tags: {}, - }, } diff --git a/packages/uni-app-vue/dist/service.runtime.esm.js b/packages/uni-app-vue/dist/service.runtime.esm.js index 16ce37bca352b231693e8b9ddcb3bf23d6ec9d9f..f255f8741a5a61db54452c00887d1b3603535ccc 100644 --- a/packages/uni-app-vue/dist/service.runtime.esm.js +++ b/packages/uni-app-vue/dist/service.runtime.esm.js @@ -2307,8 +2307,16 @@ export default function vueFactory(exports) { var preFlushIndex = 0; var pendingPostFlushCbs = []; var activePostFlushCbs = null; - var postFlushIndex = 0; - var resolvedPromise = Promise.resolve(); + var postFlushIndex = 0; // fixed by xxxxxx iOS + + var iOSPromise = { + then(callback) { + setTimeout(() => callback(), 0); + } + + }; + var isIOS = plus.os.name === 'iOS'; + var resolvedPromise = isIOS ? iOSPromise : Promise.resolve(); var currentFlushPromise = null; var currentPreFlushParentJob = null; var RECURSION_LIMIT = 100; diff --git a/packages/uni-app-vue/lib/service.runtime.esm.js b/packages/uni-app-vue/lib/service.runtime.esm.js index 0e4bbbebcf44742a9a9294ac69b0237dd3a1ff8a..b191463142c7121c372ada5aec5e2a584fa30a69 100644 --- a/packages/uni-app-vue/lib/service.runtime.esm.js +++ b/packages/uni-app-vue/lib/service.runtime.esm.js @@ -1374,7 +1374,14 @@ let preFlushIndex = 0; const pendingPostFlushCbs = []; let activePostFlushCbs = null; let postFlushIndex = 0; -const resolvedPromise = Promise.resolve(); +// fixed by xxxxxx iOS +const iOSPromise = { + then(callback) { + setTimeout(() => callback(), 0); + } +}; +const isIOS = plus.os.name === 'iOS'; +const resolvedPromise = isIOS ? iOSPromise : Promise.resolve(); let currentFlushPromise = null; let currentPreFlushParentJob = null; const RECURSION_LIMIT = 100; diff --git a/packages/uni-cli-nvue/dist/webpack/config/plugins/provide.js b/packages/uni-cli-nvue/dist/webpack/config/plugins/provide.js index 28ab0a5655ba72f12b8cbcc7695fe58f4897710e..f0e73659808768399d4ea28b926aa89132383248 100644 --- a/packages/uni-cli-nvue/dist/webpack/config/plugins/provide.js +++ b/packages/uni-cli-nvue/dist/webpack/config/plugins/provide.js @@ -5,12 +5,17 @@ const webpack_1 = require("webpack"); const uni_cli_shared_1 = require("@dcloudio/uni-cli-shared"); const utils_1 = require("../../../utils"); function createProvidePlugin() { - return new webpack_1.ProvidePlugin(Object.assign({ uniCloud: [ + return new webpack_1.ProvidePlugin({ + uniCloud: [ require.resolve('@dcloudio/uni-cloud/dist/uni-cloud.es.js'), 'default', - ], 'uni.getCurrentSubNVue': [utils_1.resolveLib('get-current-sub-nvue.js'), 'default'], 'uni.requireNativePlugin': [ + ], + 'uni.getCurrentSubNVue': [utils_1.resolveLib('get-current-sub-nvue.js'), 'default'], + 'uni.requireNativePlugin': [ utils_1.resolveLib('require-native-plugin.js'), 'default', - ] }, uni_cli_shared_1.initProvide())); + ], + ...uni_cli_shared_1.initProvide(), + }); } exports.createProvidePlugin = createProvidePlugin; diff --git a/packages/uni-cli-shared/src/vite/index.ts b/packages/uni-cli-shared/src/vite/index.ts index 7fe8c9ec72cbfd8148e702a0406a7d358044b086..f247f1a89a47c83b643f4832ea6f8286c1094508 100644 --- a/packages/uni-cli-shared/src/vite/index.ts +++ b/packages/uni-cli-shared/src/vite/index.ts @@ -1,6 +1,6 @@ import { Plugin } from 'vite' import { ParserOptions } from '@vue/compiler-core' -import { CompilerOptions, SFCTemplateCompileOptions } from '@vue/compiler-sfc' +import { CompilerOptions } from '@vue/compiler-sfc' export interface UniVitePlugin extends Plugin { uni?: { compilerOptions?: { @@ -9,7 +9,6 @@ export interface UniVitePlugin extends Plugin { directiveTransforms?: CompilerOptions['directiveTransforms'] } transformEvent?: Record - transformAssetUrls?: SFCTemplateCompileOptions['transformAssetUrls'] } } diff --git a/packages/uni-cli-shared/src/vite/plugins/vitejs/plugins/asset.ts b/packages/uni-cli-shared/src/vite/plugins/vitejs/plugins/asset.ts index 160f4e61f3696e9caa07866e56dfe4c23be29678..636e39039c2a8de98f496612c15e118a00848a43 100644 --- a/packages/uni-cli-shared/src/vite/plugins/vitejs/plugins/asset.ts +++ b/packages/uni-cli-shared/src/vite/plugins/vitejs/plugins/asset.ts @@ -1,12 +1,10 @@ import path from 'path' import { parse as parseUrl } from 'url' import fs, { promises as fsp } from 'fs' -import mime from 'mime/lite' import { Plugin } from '../plugin' import { ResolvedConfig } from '../config' import { cleanUrl } from '../utils' -import { FS_PREFIX } from '../constants' -import { OutputOptions, PluginContext, RenderedChunk } from 'rollup' +import { PluginContext, RenderedChunk } from 'rollup' import MagicString from 'magic-string' import { createHash } from 'crypto' @@ -107,20 +105,6 @@ export function assetPlugin(config: ResolvedConfig): Plugin { return null } }, - - generateBundle(_, bundle) { - // do not emit assets for SSR build - if (config.command === 'build' && config.build.ssr) { - for (const file in bundle) { - if ( - bundle[file].type === 'asset' && - !file.includes('ssr-manifest.json') - ) { - delete bundle[file] - } - } - } - }, } } @@ -154,28 +138,8 @@ export function fileToUrl( id: string, config: ResolvedConfig, ctx: PluginContext -): string | Promise { - if (config.command === 'serve') { - return fileToDevUrl(id, config) - } else { - return fileToBuiltUrl(id, config, ctx) - } -} - -function fileToDevUrl(id: string, config: ResolvedConfig) { - let rtn: string - if (checkPublicFile(id, config)) { - // in public dir, keep the url as-is - rtn = id - } else if (id.startsWith(config.root)) { - // in project root, infer short public path - rtn = '/' + path.posix.relative(config.root, id) - } else { - // outside of project root, use absolute fs path - // (this is special handled by the serve static middleware - rtn = path.posix.join(FS_PREFIX + id) - } - return config.base + rtn.replace(/^\//, '') +): string { + return fileToBuiltUrl(id, config, ctx) } export function getAssetFilename( @@ -184,97 +148,19 @@ export function getAssetFilename( ): string | undefined { return assetHashToFilenameMap.get(config)?.get(hash) } - -/** - * converts the source filepath of the asset to the output filename based on the assetFileNames option. \ - * this function imitates the behavior of rollup.js. \ - * https://rollupjs.org/guide/en/#outputassetfilenames - * - * @example - * ```ts - * const content = Buffer.from('text'); - * const fileName = assetFileNamesToFileName( - * 'assets/[name].[hash][extname]', - * '/path/to/file.txt', - * getAssetHash(content), - * content - * ) - * // fileName: 'assets/file.982d9e3e.txt' - * ``` - * - * @param assetFileNames filename pattern. e.g. `'assets/[name].[hash][extname]'` - * @param file filepath of the asset - * @param contentHash hash of the asset. used for `'[hash]'` placeholder - * @param content content of the asset. passed to `assetFileNames` if `assetFileNames` is a function - * @returns output filename - */ -export function assetFileNamesToFileName( - assetFileNames: Exclude, - file: string, - contentHash: string, - content: string | Buffer -): string { - const basename = path.basename(file) - - // placeholders for `assetFileNames` - // `hash` is slightly different from the rollup's one - const extname = path.extname(basename) - const ext = extname.substr(1) - const name = basename.slice(0, -extname.length) - const hash = contentHash - - if (typeof assetFileNames === 'function') { - assetFileNames = assetFileNames({ - name: file, - source: content, - type: 'asset', - }) - if (typeof assetFileNames !== 'string') { - throw new TypeError('assetFileNames must return a string') - } - } else if (typeof assetFileNames !== 'string') { - throw new TypeError('assetFileNames must be a string or a function') - } - - const fileName = assetFileNames.replace( - /\[\w+\]/g, - (placeholder: string): string => { - switch (placeholder) { - case '[ext]': - return ext - - case '[extname]': - return extname - - case '[hash]': - return hash - - case '[name]': - return name - } - throw new Error( - `invalid placeholder ${placeholder} in assetFileNames "${assetFileNames}"` - ) - } - ) - - return fileName -} - /** * Register an asset to be emitted as part of the bundle (if necessary) * and returns the resolved public URL */ -async function fileToBuiltUrl( +function fileToBuiltUrl( id: string, config: ResolvedConfig, pluginContext: PluginContext, skipPublicCheck = false -): Promise { +): string { if (!skipPublicCheck && checkPublicFile(id, config)) { return config.base + id.slice(1) } - const cache = assetCache.get(config)! const cached = cache.get(id) if (cached) { @@ -282,56 +168,19 @@ async function fileToBuiltUrl( } const file = cleanUrl(id) - const content = await fsp.readFile(file) + const content = fs.readFileSync(file) let url: string - if ( - config.build.lib || - (!file.endsWith('.svg') && - content.length < Number(config.build.assetsInlineLimit)) - ) { - // base64 inlined as a string - url = `data:${mime.getType(file)};base64,${content.toString('base64')}` - } else { - // emit as asset - // rollup supports `import.meta.ROLLUP_FILE_URL_*`, but it generates code - // that uses runtime url sniffing and it can be verbose when targeting - // non-module format. It also fails to cascade the asset content change - // into the chunk's hash, so we have to do our own content hashing here. - // https://bundlers.tooling.report/hashing/asset-cascade/ - // https://github.com/rollup/rollup/issues/3415 - const map = assetHashToFilenameMap.get(config)! - const contentHash = getAssetHash(content) - const { search, hash } = parseUrl(id) - const postfix = (search || '') + (hash || '') - const output = config.build?.rollupOptions?.output - const assetFileNames = - (output && !Array.isArray(output) ? output.assetFileNames : undefined) ?? - // defaults to '/[name].[hash][extname]' - // slightly different from rollup's one ('assets/[name]-[hash][extname]') - path.posix.join(config.build.assetsDir, '[name].[hash][extname]') - const fileName = assetFileNamesToFileName( - assetFileNames, - file, - contentHash, - content - ) - if (!map.has(contentHash)) { - map.set(contentHash, fileName) - } - const emittedSet = emittedHashMap.get(config)! - if (!emittedSet.has(contentHash)) { - pluginContext.emitFile({ - fileName, - type: 'asset', - source: content, - }) - emittedSet.add(contentHash) - } - url = `__VITE_ASSET__${contentHash}__${postfix ? `$_${postfix}__` : ``}` + const map = assetHashToFilenameMap.get(config)! + const contentHash = getAssetHash(content) + const { search, hash } = parseUrl(id) + const postfix = (search || '') + (hash || '') + const fileName = '/' + path.posix.relative(process.env.UNI_INPUT_DIR, id) + if (!map.has(contentHash)) { + map.set(contentHash, fileName) } - + url = `__VITE_ASSET__${contentHash}__${postfix ? `$_${postfix}__` : ``}` cache.set(id, url) return url } @@ -340,12 +189,12 @@ export function getAssetHash(content: Buffer): string { return createHash('sha256').update(content).digest('hex').slice(0, 8) } -export async function urlToBuiltUrl( +export function urlToBuiltUrl( url: string, importer: string, config: ResolvedConfig, pluginContext: PluginContext -): Promise { +): string { if (checkPublicFile(url, config)) { return config.base + url.slice(1) } diff --git a/packages/uni-cli-shared/src/vite/utils/plugin.ts b/packages/uni-cli-shared/src/vite/utils/plugin.ts index 0137d0c3dd8f2a01581d4989bc3b6ead0c2f24f2..331377017fc2aea3113927f7828062660d7d845f 100644 --- a/packages/uni-cli-shared/src/vite/utils/plugin.ts +++ b/packages/uni-cli-shared/src/vite/utils/plugin.ts @@ -9,11 +9,16 @@ export interface UniViteFilterPluginOptions { filter: (id: string) => boolean } -export function injectAssetAndCssPlugins(config: ResolvedConfig) { - replacePlugins( - [assetPlugin(config), cssPlugin(config), cssPostPlugin(config)], - config - ) +export function injectAssetPlugin(config: ResolvedConfig) { + replacePlugins([assetPlugin(config)], config) +} + +export function injectCssPlugin(config: ResolvedConfig) { + replacePlugins([cssPlugin(config)], config) +} + +export function injectCssPostPlugin(config: ResolvedConfig) { + replacePlugins([cssPostPlugin(config)], config) } export function replacePlugins(plugins: Plugin[], config: ResolvedConfig) { diff --git a/packages/uni-h5-vite/dist/handleHotUpdate/index.js b/packages/uni-h5-vite/dist/handleHotUpdate/index.js index 6640cd2ec065eb92b37dea6f8e59aba1f3a72d75..5dd822889f5de062f6176d87c94863930e19a64a 100644 --- a/packages/uni-h5-vite/dist/handleHotUpdate/index.js +++ b/packages/uni-h5-vite/dist/handleHotUpdate/index.js @@ -1,13 +1,4 @@ "use strict"; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; @@ -19,71 +10,67 @@ const shared_1 = require("@vue/shared"); const uni_cli_shared_1 = require("@dcloudio/uni-cli-shared"); const utils_1 = require("../utils"); const debugHmr = debug_1.default('vite:uni:hmr'); -function invalidate(file, moduleGraph) { - return __awaiter(this, void 0, void 0, function* () { - const mods = yield moduleGraph.getModulesByFile(uni_cli_shared_1.normalizePath(file)); - if (mods && mods.size) { - ; - [...mods].forEach((mod) => { - debugHmr('invalidate', mod.id); - moduleGraph.invalidateModule(mod); - }); - } - }); +async function invalidate(file, moduleGraph) { + const mods = await moduleGraph.getModulesByFile(uni_cli_shared_1.normalizePath(file)); + if (mods && mods.size) { + ; + [...mods].forEach((mod) => { + debugHmr('invalidate', mod.id); + moduleGraph.invalidateModule(mod); + }); + } } let invalidateFiles; function createHandleHotUpdate() { - return function ({ file, server }) { - return __awaiter(this, void 0, void 0, function* () { - const inputDir = process.env.UNI_INPUT_DIR; - const platform = process.env.UNI_PLATFORM; - if (!invalidateFiles) { - invalidateFiles = [ - path_1.default.resolve(inputDir, 'pages.json.js'), - path_1.default.resolve(inputDir, 'manifest.json.js'), - require.resolve('@dcloudio/uni-h5/dist/uni-h5.es.js'), - ]; - try { - invalidateFiles.push(require.resolve('vite/dist/client/env.mjs')); - } - catch (e) { } - } - // TODO 目前简单处理,当pages.json,manifest.json发生变化,就直接刷新,理想情况下,应该区分变化的内容,仅必要时做整页面刷新 - const isPagesJson = file.endsWith('pages.json'); - const isManifestJson = file.endsWith('manifest.json'); - if (!isPagesJson && !isManifestJson) { - return; - } - debugHmr(file); - const pagesJson = uni_cli_shared_1.parsePagesJson(inputDir, platform); - // 更新define - const { define, server: { middlewareMode }, } = server.config; - shared_1.extend(define, utils_1.initFeatures({ - inputDir, - command: 'serve', - platform, - pagesJson, - manifestJson: uni_cli_shared_1.parseManifestJson(inputDir), - ssr: !!middlewareMode, - })); - debugHmr('define', define); - if (isPagesJson) { - const easycom = pagesJson.easycom || {}; - const { options, refresh } = uni_cli_shared_1.initEasycomsOnce(inputDir, platform); - if (!equal({ autoscan: easycom.autoscan, custom: easycom.custom }, { autoscan: options.autoscan, custom: options.custom })) { - refresh(); - } + return async function ({ file, server }) { + const inputDir = process.env.UNI_INPUT_DIR; + const platform = process.env.UNI_PLATFORM; + if (!invalidateFiles) { + invalidateFiles = [ + path_1.default.resolve(inputDir, 'pages.json.js'), + path_1.default.resolve(inputDir, 'manifest.json.js'), + require.resolve('@dcloudio/uni-h5/dist/uni-h5.es.js'), + ]; + try { + invalidateFiles.push(require.resolve('vite/dist/client/env.mjs')); } - // 当pages.json,manifest.json发生变化时,作废pages.json.js缓存 - for (const file of invalidateFiles) { - yield invalidate(file, server.moduleGraph); + catch (e) { } + } + // TODO 目前简单处理,当pages.json,manifest.json发生变化,就直接刷新,理想情况下,应该区分变化的内容,仅必要时做整页面刷新 + const isPagesJson = file.endsWith('pages.json'); + const isManifestJson = file.endsWith('manifest.json'); + if (!isPagesJson && !isManifestJson) { + return; + } + debugHmr(file); + const pagesJson = uni_cli_shared_1.parsePagesJson(inputDir, platform); + // 更新define + const { define, server: { middlewareMode }, } = server.config; + shared_1.extend(define, utils_1.initFeatures({ + inputDir, + command: 'serve', + platform, + pagesJson, + manifestJson: uni_cli_shared_1.parseManifestJson(inputDir), + ssr: !!middlewareMode, + })); + debugHmr('define', define); + if (isPagesJson) { + const easycom = pagesJson.easycom || {}; + const { options, refresh } = uni_cli_shared_1.initEasycomsOnce(inputDir, platform); + if (!equal({ autoscan: easycom.autoscan, custom: easycom.custom }, { autoscan: options.autoscan, custom: options.custom })) { + refresh(); } - server.ws.send({ - type: 'full-reload', - path: '*', - }); - return []; + } + // 当pages.json,manifest.json发生变化时,作废pages.json.js缓存 + for (const file of invalidateFiles) { + await invalidate(file, server.moduleGraph); + } + server.ws.send({ + type: 'full-reload', + path: '*', }); + return []; }; } exports.createHandleHotUpdate = createHandleHotUpdate; diff --git a/packages/uni-h5-vite/dist/index.js b/packages/uni-h5-vite/dist/index.js index 02815323c368ba09db3fed56522163b9b439fcae..4384329ff5428a9ac356dbac9324bc827c5aa649 100644 --- a/packages/uni-h5-vite/dist/index.js +++ b/packages/uni-h5-vite/dist/index.js @@ -24,24 +24,6 @@ const UniH5Plugin = { transformEvent: { tap: 'click', }, - transformAssetUrls: { - base: '/', - tags: { - audio: ['src'], - video: ['src', 'poster'], - img: ['src'], - image: ['src'], - 'cover-image': ['src'], - // h5 - 'v-uni-audio': ['src'], - 'v-uni-video': ['src', 'poster'], - 'v-uni-image': ['src'], - 'v-uni-cover-image': ['src'], - // nvue - 'u-image': ['src'], - 'u-video': ['src', 'poster'], - }, - }, }, config(config, env) { if (uni_cli_shared_1.isInHBuilderX()) { diff --git a/packages/uni-h5-vite/dist/plugins/cssScoped.js b/packages/uni-h5-vite/dist/plugins/cssScoped.js index f3a7f34a430536109d519710b4464b181c8c4d0a..edac99447983d9440cd7ac1b1b2f0d4a6d36b586 100644 --- a/packages/uni-h5-vite/dist/plugins/cssScoped.js +++ b/packages/uni-h5-vite/dist/plugins/cssScoped.js @@ -1,13 +1,4 @@ "use strict"; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; @@ -53,10 +44,10 @@ function uniCssScopedPlugin() { } debugScoped('hmr', ctx.file); const oldRead = ctx.read; - ctx.read = () => __awaiter(this, void 0, void 0, function* () { - const code = yield oldRead(); + ctx.read = async () => { + const code = await oldRead(); return addScoped(code); - }); + }; }, }; } diff --git a/packages/uni-h5-vite/dist/plugins/manifestJson.js b/packages/uni-h5-vite/dist/plugins/manifestJson.js index 5da5c512c4416ba6b2cc135ca39843b432348989..c73dd2facc2da0d5360675fa7bfe20377bbafd8c 100644 --- a/packages/uni-h5-vite/dist/plugins/manifestJson.js +++ b/packages/uni-h5-vite/dist/plugins/manifestJson.js @@ -26,11 +26,11 @@ function uniManifestJsonPlugin() { const manifest = uni_cli_shared_1.parseJson(code); const { debug, h5 } = manifest; const appid = (manifest.appid || '').replace('__UNI__', ''); - const router = Object.assign(Object.assign({}, defaultRouter), ((h5 && h5.router) || {})); + const router = { ...defaultRouter, ...((h5 && h5.router) || {}) }; if (!router.base) { router.base = '/'; } - const async = Object.assign(Object.assign({}, defaultAsync), ((h5 && h5.async) || {})); + const async = { ...defaultAsync, ...((h5 && h5.async) || {}) }; const networkTimeout = uni_cli_shared_1.normalizeNetworkTimeout(manifest.networkTimeout); const sdkConfigs = (h5 && h5.sdkConfigs) || {}; const qqMapKey = (sdkConfigs.maps && diff --git a/packages/uni-h5-vite/dist/transformIndexHtml/index.js b/packages/uni-h5-vite/dist/transformIndexHtml/index.js index 9be7e71db651e918024c8855163d41d4c43d0f25..7349572f82d1f0b852c47b94c8737f77ee237d64 100644 --- a/packages/uni-h5-vite/dist/transformIndexHtml/index.js +++ b/packages/uni-h5-vite/dist/transformIndexHtml/index.js @@ -1,24 +1,13 @@ "use strict"; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; Object.defineProperty(exports, "__esModule", { value: true }); exports.createTransformIndexHtml = void 0; const dist_1 = require("../../../uni-cli-shared/dist"); function createTransformIndexHtml() { - return function (html) { + return async function (html) { var _a; - return __awaiter(this, void 0, void 0, function* () { - const manifestJson = dist_1.parseManifestJsonOnce(process.env.UNI_INPUT_DIR); - const title = ((_a = manifestJson.h5) === null || _a === void 0 ? void 0 : _a.title) || manifestJson.name || ''; - return html.replace(/(.*?)<\/title>/, `<title>${title}`); - }); + const manifestJson = dist_1.parseManifestJsonOnce(process.env.UNI_INPUT_DIR); + const title = ((_a = manifestJson.h5) === null || _a === void 0 ? void 0 : _a.title) || manifestJson.name || ''; + return html.replace(/(.*?)<\/title>/, `<title>${title}`); }; } exports.createTransformIndexHtml = createTransformIndexHtml; diff --git a/packages/uni-h5-vite/src/index.ts b/packages/uni-h5-vite/src/index.ts index fc541db56c0160a85f35446710c816c3d1c34202..c1e4d9fb6a9b3e31800bb1cd5a76c686a4cb4341 100644 --- a/packages/uni-h5-vite/src/index.ts +++ b/packages/uni-h5-vite/src/index.ts @@ -21,24 +21,6 @@ const UniH5Plugin: UniVitePlugin = { transformEvent: { tap: 'click', }, - transformAssetUrls: { - base: '/', - tags: { - audio: ['src'], - video: ['src', 'poster'], - img: ['src'], - image: ['src'], - 'cover-image': ['src'], - // h5 - 'v-uni-audio': ['src'], - 'v-uni-video': ['src', 'poster'], - 'v-uni-image': ['src'], - 'v-uni-cover-image': ['src'], - // nvue - 'u-image': ['src'], - 'u-video': ['src', 'poster'], - }, - }, }, config(config, env) { if (isInHBuilderX()) { diff --git a/packages/uni-vue/src/componentOptions.ts b/packages/uni-vue/src/componentOptions.ts index 22a7bba169a4a942971abd50e57071a5bafd52cf..2b5d44f50f87aef0cfe8ceda05d8bdfa99facfe3 100644 --- a/packages/uni-vue/src/componentOptions.ts +++ b/packages/uni-vue/src/componentOptions.ts @@ -29,7 +29,11 @@ export function applyOptions( } }) if (__PLATFORM__ === 'app' && mpType === 'page') { - invokeHook(publicThis, ON_LOAD, instance.attrs.__pageQuery) - invokeHook(publicThis, ON_SHOW) + try { + invokeHook(publicThis, ON_LOAD, instance.attrs.__pageQuery) + invokeHook(publicThis, ON_SHOW) + } catch (e) { + console.error(e.message + '\n' + e.stack) + } } } diff --git a/packages/vite-plugin-uni/src/vue/options.ts b/packages/vite-plugin-uni/src/vue/options.ts index aff9771adc5fd1dae639d246f5e3b06f79e6cc5c..391b912f3a65408ebe031233072e7b0ad806e10a 100644 --- a/packages/vite-plugin-uni/src/vue/options.ts +++ b/packages/vite-plugin-uni/src/vue/options.ts @@ -14,6 +14,29 @@ import { transformMatchMedia } from './transforms/transformMatchMedia' import { createTransformEvent } from './transforms/transformEvent' // import { transformContext } from './transforms/transformContext' +function createUniVueTransformAssetUrls( + base: string +): SFCTemplateCompileOptions['transformAssetUrls'] { + return { + base, + tags: { + audio: ['src'], + video: ['src', 'poster'], + img: ['src'], + image: ['src'], + 'cover-image': ['src'], + // h5 + 'v-uni-audio': ['src'], + 'v-uni-video': ['src', 'poster'], + 'v-uni-image': ['src'], + 'v-uni-cover-image': ['src'], + // nvue + 'u-image': ['src'], + 'u-video': ['src', 'poster'], + }, + } +} + export function initPluginVueOptions( options: VitePluginUniResolvedOptions, UniVitePlugins: UniVitePlugin[] @@ -29,15 +52,18 @@ export function initPluginVueOptions( const templateOptions = vueOptions.template || (vueOptions.template = {}) - let transformAssetUrls: SFCTemplateCompileOptions['transformAssetUrls'] + templateOptions.transformAssetUrls = createUniVueTransformAssetUrls( + options.base + ) + let isCompilerNativeTag: ParserOptions['isNativeTag'] = isNativeTag let isCompilerCustomElement: ParserOptions['isCustomElement'] = isCustomElement let directiveTransforms: CompilerOptions['directiveTransforms'] - UniVitePlugins.forEach(({ uni }) => { - const compilerOptions = uni?.compilerOptions + UniVitePlugins.forEach((plugin) => { + const compilerOptions = plugin.uni?.compilerOptions if (compilerOptions) { if (compilerOptions.isNativeTag) { isCompilerNativeTag = compilerOptions.isNativeTag @@ -48,21 +74,14 @@ export function initPluginVueOptions( if (compilerOptions.directiveTransforms) { directiveTransforms = compilerOptions.directiveTransforms } - if (uni!.transformAssetUrls) { - transformAssetUrls = uni!.transformAssetUrls - } } }) - const compilerOptions = templateOptions.compilerOptions || (templateOptions.compilerOptions = {}) compilerOptions.isNativeTag = isCompilerNativeTag if (!compilerOptions.nodeTransforms) { compilerOptions.nodeTransforms = [] } - if (transformAssetUrls) { - templateOptions.transformAssetUrls = transformAssetUrls - } const compatConfig = parseCompatConfigOnce(options.inputDir) diff --git a/tsconfig.node.json b/tsconfig.node.json index b73c0e0999888c2e9e0560e97e562c23c0f69e28..d596f5bacee0e1248266bd499fe38704c53ca7c0 100644 --- a/tsconfig.node.json +++ b/tsconfig.node.json @@ -1,6 +1,6 @@ { "compilerOptions": { - "target": "es2015", + "target": "es2018", "moduleResolution": "node", "strict": true, "declaration": false,