diff --git a/packages/uni-template-compiler/lib/asset-url.js b/packages/uni-template-compiler/lib/asset-url.js index 653e3895998ddd36cb67994bad551bf2b4732d21..8ffc8986f271834fb92f70af8474a65492afef0e 100644 --- a/packages/uni-template-compiler/lib/asset-url.js +++ b/packages/uni-template-compiler/lib/asset-url.js @@ -68,10 +68,15 @@ function rewrite (attr, name, options) { .replace('"@/', '"/') .replace('"~@/', '"/') } - // h5 - if (options.h5) { + // v3,h5 + const needRequire = options.service || options.view || options.h5 + if (needRequire) { attr.value = urlToRequire(attr.value.slice(1, -1)) - if (attr.value.startsWith('require("') && options.publicPath === './') { // require + if ( + options.h5 && + options.publicPath === './' && + attr.value.startsWith('require("') + ) { // require // h5 且 publicPath 为 ./ (仅生产模式可能为./) attr.value = `(${attr.value}).substr(1)` }