diff --git a/packages/taro-webpack5-runner/src/loaders/miniTemplateLoader.ts b/packages/taro-webpack5-runner/src/loaders/miniTemplateLoader.ts index 0a72f102b73f..0312ced4816d 100644 --- a/packages/taro-webpack5-runner/src/loaders/miniTemplateLoader.ts +++ b/packages/taro-webpack5-runner/src/loaders/miniTemplateLoader.ts @@ -1,5 +1,6 @@ import { isUrlRequest, urlToRequest } from 'loader-utils' import sax from 'sax' +import { isSpecialFormat } from '../utils/index' export default function miniTemplateLoader (source) { this.cacheable && this.cacheable() @@ -20,6 +21,8 @@ export default function miniTemplateLoader (source) { parser.onattribute = ({ name, value }) => { if (value && (name === 'src' || name === 'from') && isUrlRequest(value)) { + if (isSpecialFormat(name, value)) return + const request = urlToRequest(value) requests.add(request) } diff --git a/packages/taro-webpack5-runner/src/utils/index.ts b/packages/taro-webpack5-runner/src/utils/index.ts index 017cb0ccc6ce..0af62eecf9d0 100644 --- a/packages/taro-webpack5-runner/src/utils/index.ts +++ b/packages/taro-webpack5-runner/src/utils/index.ts @@ -45,3 +45,12 @@ export const formatOpenHost = (host?: string) => { export function parsePublicPath (publicPath = '/') { return ['', 'auto'].includes(publicPath) ? publicPath : addTrailingSlash(publicPath) } + +export function isSpecialFormat(key: string, value: string) { + if (key === 'src' && /{{\s*\w+\s*}}/.test(value)) { + // in .wxml, the value url in should not be requested, it is a state value in page data + return true + } + + return false +}