@weapp-vite/web 1.4.0 → 1.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/compiler/wxml/renderer.mjs +4 -1
- package/dist/compiler/wxml/renderer.mjs.map +1 -1
- package/dist/compiler/wxml/specialNodes.mjs +2 -1
- package/dist/compiler/wxml/specialNodes.mjs.map +1 -1
- package/dist/index.d.mts +1 -6
- package/dist/index.mjs +1 -177
- package/dist/plugin/index.mjs +10 -6
- package/dist/plugin/index.mjs.map +1 -1
- package/dist/plugin/path.mjs +2 -1
- package/dist/plugin/path.mjs.map +1 -1
- package/dist/plugin/scan.mjs +23 -16
- package/dist/plugin/scan.mjs.map +1 -1
- package/dist/plugin/vueSfc.mjs +3 -2
- package/dist/plugin/vueSfc.mjs.map +1 -1
- package/dist/runtime/component/relations.mjs +2 -1
- package/dist/runtime/component/relations.mjs.map +1 -1
- package/dist/runtime/polyfill/deviceApi.mjs +6 -3
- package/dist/runtime/polyfill/deviceApi.mjs.map +1 -1
- package/dist/runtime/polyfill/font.mjs +2 -1
- package/dist/runtime/polyfill/font.mjs.map +1 -1
- package/dist/runtime/polyfill/interactionApi.mjs +6 -3
- package/dist/runtime/polyfill/interactionApi.mjs.map +1 -1
- package/dist/runtime/polyfill/locationApi.mjs +4 -2
- package/dist/runtime/polyfill/locationApi.mjs.map +1 -1
- package/dist/runtime/polyfill/mediaApi/file.mjs +2 -1
- package/dist/runtime/polyfill/mediaApi/file.mjs.map +1 -1
- package/dist/runtime/polyfill/mediaApi/picker.mjs +16 -8
- package/dist/runtime/polyfill/mediaApi/picker.mjs.map +1 -1
- package/dist/runtime/polyfill/mediaApi/preview.mjs +4 -2
- package/dist/runtime/polyfill/mediaApi/preview.mjs.map +1 -1
- package/dist/runtime/polyfill/mediaApi/process.mjs +4 -2
- package/dist/runtime/polyfill/mediaApi/process.mjs.map +1 -1
- package/dist/runtime/polyfill/menuApi.mjs +3 -2
- package/dist/runtime/polyfill/menuApi.mjs.map +1 -1
- package/dist/runtime/polyfill/platformApi.mjs +2 -1
- package/dist/runtime/polyfill/platformApi.mjs.map +1 -1
- package/dist/runtime/polyfill/storageAsync.mjs +4 -2
- package/dist/runtime/polyfill/storageAsync.mjs.map +1 -1
- package/dist/runtime/polyfill/system.mjs +1 -1
- package/dist/runtime/polyfill/system.mjs.map +1 -1
- package/dist/runtime/polyfill/systemApi.mjs +2 -1
- package/dist/runtime/polyfill/systemApi.mjs.map +1 -1
- package/package.json +5 -5
- package/dist/index.mjs.map +0 -1
|
@@ -66,7 +66,10 @@ var Renderer = class {
|
|
|
66
66
|
};
|
|
67
67
|
}
|
|
68
68
|
renderNode(node, scopeVar, wxsVar, componentTags) {
|
|
69
|
-
if (node.type === "text")
|
|
69
|
+
if (node.type === "text") {
|
|
70
|
+
const parts = parseInterpolations(node.data ?? "");
|
|
71
|
+
return buildExpression(parts, scopeVar, wxsVar);
|
|
72
|
+
}
|
|
70
73
|
if (node.type === "element") return this.renderElement(node, scopeVar, wxsVar, componentTags);
|
|
71
74
|
return "\"\"";
|
|
72
75
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renderer.mjs","names":[],"sources":["../../../src/compiler/wxml/renderer.ts"],"sourcesContent":["import type { RenderElementNode, RenderNode } from './types'\nimport { resolveNativeComponentPropertyAttributes } from '../../shared/nativeComponents'\nimport {\n hasControlAttribute,\n normalizeTagName,\n resolveControlAttributeValue,\n SELF_CLOSING_TAGS,\n} from '../../shared/wxml'\nimport {\n extractFor,\n isConditionalElement,\n renderAttributes,\n resolveComponentTagName,\n stripControlAttributes,\n} from './attributes'\nimport { buildExpression, buildTemplateDataExpression, parseInterpolations } from './interpolation'\n\ninterface RenderElementOptions {\n skipFor?: boolean\n overrideAttribs?: Record<string, string>\n}\n\nexport class Renderer {\n renderNodes(\n nodes: RenderNode[],\n scopeVar: string,\n wxsVar: string,\n componentTags?: Record<string, string>,\n ): string {\n const parts: string[] = []\n for (let index = 0; index < nodes.length; index += 1) {\n const node = nodes[index]\n if (isConditionalElement(node)) {\n const { rendered, endIndex } = this.renderConditionalSequence(\n nodes,\n index,\n scopeVar,\n wxsVar,\n componentTags,\n )\n parts.push(rendered)\n index = endIndex\n continue\n }\n parts.push(this.renderNode(node, scopeVar, wxsVar, componentTags))\n }\n if (parts.length === 0) {\n return '\"\"'\n }\n if (parts.length === 1) {\n return parts[0]!\n }\n return `[${parts.join(', ')}]`\n }\n\n private renderConditionalSequence(\n nodes: RenderNode[],\n startIndex: number,\n scopeVar: string,\n wxsVar: string,\n componentTags?: Record<string, string>,\n ): { rendered: string, endIndex: number } {\n const branches: Array<{ node: RenderElementNode, attribs: Record<string, string> }> = []\n let cursor = startIndex\n while (cursor < nodes.length) {\n const candidate = nodes[cursor]\n if (!isConditionalElement(candidate)) {\n break\n }\n const attribs = candidate.attribs!\n if (branches.length === 0 && !hasControlAttribute(attribs, 'if')) {\n break\n }\n if (branches.length > 0 && !hasControlAttribute(attribs, 'elif') && !hasControlAttribute(attribs, 'else')) {\n break\n }\n branches.push({ node: candidate, attribs })\n cursor += 1\n if (hasControlAttribute(attribs, 'else')) {\n break\n }\n }\n if (!branches.length) {\n const node = nodes[startIndex]\n if (!node) {\n return { rendered: '\"\"', endIndex: startIndex }\n }\n return { rendered: this.renderNode(node, scopeVar, wxsVar, componentTags), endIndex: startIndex }\n }\n let expr = '\"\"'\n for (let index = branches.length - 1; index >= 0; index -= 1) {\n const { node, attribs } = branches[index]!\n const cleanedAttribs = stripControlAttributes(attribs)\n if (hasControlAttribute(attribs, 'else')) {\n expr = this.renderElement(node, scopeVar, wxsVar, componentTags, { overrideAttribs: cleanedAttribs })\n continue\n }\n const conditionExpr = resolveControlAttributeValue(attribs, 'if')\n ?? resolveControlAttributeValue(attribs, 'elif')!\n const rendered = this.renderElement(node, scopeVar, wxsVar, componentTags, { overrideAttribs: cleanedAttribs })\n const condition = buildExpression(parseInterpolations(conditionExpr), scopeVar, wxsVar)\n expr = `(${condition} ? ${rendered} : ${expr})`\n }\n return { rendered: expr, endIndex: startIndex + branches.length - 1 }\n }\n\n private renderNode(\n node: RenderNode,\n scopeVar: string,\n wxsVar: string,\n componentTags?: Record<string, string>,\n ): string {\n if (node.type === 'text') {\n const parts = parseInterpolations(node.data ?? '')\n return buildExpression(parts, scopeVar, wxsVar)\n }\n if (node.type === 'element') {\n return this.renderElement(node, scopeVar, wxsVar, componentTags)\n }\n return '\"\"'\n }\n\n private renderTemplateInvoke(\n node: RenderElementNode,\n scopeVar: string,\n wxsVar: string,\n overrideAttribs?: Record<string, string>,\n ): string {\n const attribs = overrideAttribs ?? node.attribs ?? {}\n const isExpr = buildExpression(parseInterpolations(attribs.is ?? ''), scopeVar, wxsVar)\n const dataExpr = attribs.data\n ? buildTemplateDataExpression(attribs.data, scopeVar, wxsVar)\n : undefined\n const scopeExpr = dataExpr\n ? `ctx.mergeScope(${scopeVar}, ${dataExpr})`\n : scopeVar\n return `ctx.renderTemplate(__templates, ${isExpr}, ${scopeExpr}, ctx)`\n }\n\n private renderElement(\n node: RenderElementNode,\n scopeVar: string,\n wxsVar: string,\n componentTags?: Record<string, string>,\n options: RenderElementOptions = {},\n ): string {\n const attribs = options.overrideAttribs ?? node.attribs ?? {}\n if (!options.skipFor) {\n const forInfo = extractFor(node.attribs ?? {})\n if (forInfo.expr) {\n const listExpression = buildExpression(parseInterpolations(forInfo.expr), scopeVar, wxsVar)\n const listExpr = `ctx.normalizeList(${listExpression})`\n const itemVar = forInfo.itemName\n const indexVar = forInfo.indexName\n const nestedScopeVar = scopeVar === 'scope'\n ? '__scope'\n : `${scopeVar}_nested`\n const scopeExpr = `ctx.createScope(${scopeVar}, { ${itemVar}: ${itemVar}, ${indexVar}: ${indexVar} })`\n const itemRender = this.renderElement(\n node,\n nestedScopeVar,\n wxsVar,\n componentTags,\n { skipFor: true, overrideAttribs: forInfo.restAttribs },\n )\n const keyExpr = `ctx.key(${JSON.stringify(forInfo.key ?? '')}, ${itemVar}, ${indexVar}, ${scopeExpr}, ${wxsVar})`\n return `repeat(${listExpr}, (${itemVar}, ${indexVar}) => ${keyExpr}, (${itemVar}, ${indexVar}) => { const ${nestedScopeVar} = ${scopeExpr}; return ${itemRender}; })`\n }\n }\n\n if (node.name === 'template' && attribs.is) {\n return this.renderTemplateInvoke(node, scopeVar, wxsVar, attribs)\n }\n\n const customTag = resolveComponentTagName(node.name ?? '', componentTags)\n const tagName = customTag ?? normalizeTagName(node.name ?? '')\n if (tagName === '#fragment') {\n return this.renderNodes(node.children ?? [], scopeVar, wxsVar, componentTags)\n }\n\n const attrs = renderAttributes(attribs, scopeVar, wxsVar, {\n skipControl: true,\n preferProperty: Boolean(customTag),\n propertyAttributes: customTag\n ? undefined\n : resolveNativeComponentPropertyAttributes(node.name ?? ''),\n })\n const childNodes = node.children ?? []\n const children = childNodes.length > 0\n ? `\\${${this.renderNodes(childNodes, scopeVar, wxsVar, componentTags)}}`\n : ''\n if (SELF_CLOSING_TAGS.has(tagName) && childNodes.length === 0) {\n return `html\\`<${tagName}${attrs} />\\``\n }\n return `html\\`<${tagName}${attrs}>${children}</${tagName}>\\``\n }\n}\n\nexport const renderer = new Renderer()\n"],"mappings":";;;;;;AAsBA,IAAa,WAAb,MAAsB;CACpB,YACE,OACA,UACA,QACA,eACQ;EACR,MAAM,QAAkB,CAAC;EACzB,KAAK,IAAI,QAAQ,GAAG,QAAQ,MAAM,QAAQ,SAAS,GAAG;GACpD,MAAM,OAAO,MAAM;GACnB,IAAI,qBAAqB,IAAI,GAAG;IAC9B,MAAM,EAAE,UAAU,aAAa,KAAK,0BAClC,OACA,OACA,UACA,QACA,aACF;IACA,MAAM,KAAK,QAAQ;IACnB,QAAQ;IACR;GACF;GACA,MAAM,KAAK,KAAK,WAAW,MAAM,UAAU,QAAQ,aAAa,CAAC;EACnE;EACA,IAAI,MAAM,WAAW,GACnB,OAAO;EAET,IAAI,MAAM,WAAW,GACnB,OAAO,MAAM;EAEf,OAAO,IAAI,M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AK,UAAU,QAAQ,OAAO,EAAE,EAAE,IAAI,QAAQ,IAAI,SAAS,IAAI,UAAU,IAAI,OAAO,GAC5C,KAAK,QAAQ,IAAI,SAAS,eAAe,eAAe,KAAK,UAAU,WAAW,WAAW;GAClK;EACF;EAEA,IAAI,KAAK,SAAS,cAAc,QAAQ,IACtC,OAAO,KAAK,qBAAqB,MAAM,UAAU,QAAQ,OAAO;EAGlE,MAAM,YAAY,wBAAwB,KAAK,QAAQ,IAAI,aAAa;EACxE,MAAM,UAAU,aAAa,iBAAiB,KAAK,QAAQ,EAAE;EAC7D,IAAI,YAAY,aACd,OAAO,KAAK,YAAY,KAAK,YAAY,CAAC,GAAG,UAAU,QAAQ,aAAa;EAG9E,MAAM,QAAQ,iBAAiB,SAAS,UAAU,QAAQ;GACxD,aAAa;GACb,gBAAgB,QAAQ,SAAS;GACjC,oBAAoB,YAChB,SACA,yCAAyC,KAAK,QAAQ,EAAE;EAC9D,CAAC;EACD,MAAM,aAAa,KAAK,YAAY,CAAC;EACrC,MAAM,WAAW,WAAW,SAAS,IACjC,MAAM,KAAK,YAAY,YAAY,UAAU,QAAQ,aAAa,EAAE,KACpE;EACJ,IAAI,kBAAkB,IAAI,OAAO,KAAK,WAAW,WAAW,GAC1D,OAAO,UAAU,UAAU,MAAM;EAEnC,OAAO,UAAU,UAAU,MAAM,GAAG,SAAS,IAAI,QAAQ;CAC3D;AACF;AAEA,MAAa,WAAW,IAAI,SAAS"}
|
|
1
|
+
{"version":3,"file":"renderer.mjs","names":[],"sources":["../../../src/compiler/wxml/renderer.ts"],"sourcesContent":["import type { RenderElementNode, RenderNode } from './types'\nimport { resolveNativeComponentPropertyAttributes } from '../../shared/nativeComponents'\nimport {\n hasControlAttribute,\n normalizeTagName,\n resolveControlAttributeValue,\n SELF_CLOSING_TAGS,\n} from '../../shared/wxml'\nimport {\n extractFor,\n isConditionalElement,\n renderAttributes,\n resolveComponentTagName,\n stripControlAttributes,\n} from './attributes'\nimport { buildExpression, buildTemplateDataExpression, parseInterpolations } from './interpolation'\n\ninterface RenderElementOptions {\n skipFor?: boolean\n overrideAttribs?: Record<string, string>\n}\n\nexport class Renderer {\n renderNodes(\n nodes: RenderNode[],\n scopeVar: string,\n wxsVar: string,\n componentTags?: Record<string, string>,\n ): string {\n const parts: string[] = []\n for (let index = 0; index < nodes.length; index += 1) {\n const node = nodes[index]\n if (isConditionalElement(node)) {\n const { rendered, endIndex } = this.renderConditionalSequence(\n nodes,\n index,\n scopeVar,\n wxsVar,\n componentTags,\n )\n parts.push(rendered)\n index = endIndex\n continue\n }\n parts.push(this.renderNode(node, scopeVar, wxsVar, componentTags))\n }\n if (parts.length === 0) {\n return '\"\"'\n }\n if (parts.length === 1) {\n return parts[0]!\n }\n return `[${parts.join(', ')}]`\n }\n\n private renderConditionalSequence(\n nodes: RenderNode[],\n startIndex: number,\n scopeVar: string,\n wxsVar: string,\n componentTags?: Record<string, string>,\n ): { rendered: string, endIndex: number } {\n const branches: Array<{ node: RenderElementNode, attribs: Record<string, string> }> = []\n let cursor = startIndex\n while (cursor < nodes.length) {\n const candidate = nodes[cursor]\n if (!isConditionalElement(candidate)) {\n break\n }\n const attribs = candidate.attribs!\n if (branches.length === 0 && !hasControlAttribute(attribs, 'if')) {\n break\n }\n if (branches.length > 0 && !hasControlAttribute(attribs, 'elif') && !hasControlAttribute(attribs, 'else')) {\n break\n }\n branches.push({ node: candidate, attribs })\n cursor += 1\n if (hasControlAttribute(attribs, 'else')) {\n break\n }\n }\n if (!branches.length) {\n const node = nodes[startIndex]\n if (!node) {\n return { rendered: '\"\"', endIndex: startIndex }\n }\n return { rendered: this.renderNode(node, scopeVar, wxsVar, componentTags), endIndex: startIndex }\n }\n let expr = '\"\"'\n for (let index = branches.length - 1; index >= 0; index -= 1) {\n const { node, attribs } = branches[index]!\n const cleanedAttribs = stripControlAttributes(attribs)\n if (hasControlAttribute(attribs, 'else')) {\n expr = this.renderElement(node, scopeVar, wxsVar, componentTags, { overrideAttribs: cleanedAttribs })\n continue\n }\n const conditionExpr = resolveControlAttributeValue(attribs, 'if')\n ?? resolveControlAttributeValue(attribs, 'elif')!\n const rendered = this.renderElement(node, scopeVar, wxsVar, componentTags, { overrideAttribs: cleanedAttribs })\n const condition = buildExpression(parseInterpolations(conditionExpr), scopeVar, wxsVar)\n expr = `(${condition} ? ${rendered} : ${expr})`\n }\n return { rendered: expr, endIndex: startIndex + branches.length - 1 }\n }\n\n private renderNode(\n node: RenderNode,\n scopeVar: string,\n wxsVar: string,\n componentTags?: Record<string, string>,\n ): string {\n if (node.type === 'text') {\n const parts = parseInterpolations(node.data ?? '')\n return buildExpression(parts, scopeVar, wxsVar)\n }\n if (node.type === 'element') {\n return this.renderElement(node, scopeVar, wxsVar, componentTags)\n }\n return '\"\"'\n }\n\n private renderTemplateInvoke(\n node: RenderElementNode,\n scopeVar: string,\n wxsVar: string,\n overrideAttribs?: Record<string, string>,\n ): string {\n const attribs = overrideAttribs ?? node.attribs ?? {}\n const isExpr = buildExpression(parseInterpolations(attribs.is ?? ''), scopeVar, wxsVar)\n const dataExpr = attribs.data\n ? buildTemplateDataExpression(attribs.data, scopeVar, wxsVar)\n : undefined\n const scopeExpr = dataExpr\n ? `ctx.mergeScope(${scopeVar}, ${dataExpr})`\n : scopeVar\n return `ctx.renderTemplate(__templates, ${isExpr}, ${scopeExpr}, ctx)`\n }\n\n private renderElement(\n node: RenderElementNode,\n scopeVar: string,\n wxsVar: string,\n componentTags?: Record<string, string>,\n options: RenderElementOptions = {},\n ): string {\n const attribs = options.overrideAttribs ?? node.attribs ?? {}\n if (!options.skipFor) {\n const forInfo = extractFor(node.attribs ?? {})\n if (forInfo.expr) {\n const listExpression = buildExpression(parseInterpolations(forInfo.expr), scopeVar, wxsVar)\n const listExpr = `ctx.normalizeList(${listExpression})`\n const itemVar = forInfo.itemName\n const indexVar = forInfo.indexName\n const nestedScopeVar = scopeVar === 'scope'\n ? '__scope'\n : `${scopeVar}_nested`\n const scopeExpr = `ctx.createScope(${scopeVar}, { ${itemVar}: ${itemVar}, ${indexVar}: ${indexVar} })`\n const itemRender = this.renderElement(\n node,\n nestedScopeVar,\n wxsVar,\n componentTags,\n { skipFor: true, overrideAttribs: forInfo.restAttribs },\n )\n const keyExpr = `ctx.key(${JSON.stringify(forInfo.key ?? '')}, ${itemVar}, ${indexVar}, ${scopeExpr}, ${wxsVar})`\n return `repeat(${listExpr}, (${itemVar}, ${indexVar}) => ${keyExpr}, (${itemVar}, ${indexVar}) => { const ${nestedScopeVar} = ${scopeExpr}; return ${itemRender}; })`\n }\n }\n\n if (node.name === 'template' && attribs.is) {\n return this.renderTemplateInvoke(node, scopeVar, wxsVar, attribs)\n }\n\n const customTag = resolveComponentTagName(node.name ?? '', componentTags)\n const tagName = customTag ?? normalizeTagName(node.name ?? '')\n if (tagName === '#fragment') {\n return this.renderNodes(node.children ?? [], scopeVar, wxsVar, componentTags)\n }\n\n const attrs = renderAttributes(attribs, scopeVar, wxsVar, {\n skipControl: true,\n preferProperty: Boolean(customTag),\n propertyAttributes: customTag\n ? undefined\n : resolveNativeComponentPropertyAttributes(node.name ?? ''),\n })\n const childNodes = node.children ?? []\n const children = childNodes.length > 0\n ? `\\${${this.renderNodes(childNodes, scopeVar, wxsVar, componentTags)}}`\n : ''\n if (SELF_CLOSING_TAGS.has(tagName) && childNodes.length === 0) {\n return `html\\`<${tagName}${attrs} />\\``\n }\n return `html\\`<${tagName}${attrs}>${children}</${tagName}>\\``\n }\n}\n\nexport const renderer = new Renderer()\n"],"mappings":";;;;;;AAsBA,IAAa,WAAb,MAAsB;CACpB,YACE,OACA,UACA,QACA,eACQ;EACR,MAAM,QAAkB,CAAC;EACzB,KAAK,IAAI,QAAQ,GAAG,QAAQ,MAAM,QAAQ,SAAS,GAAG;GACpD,MAAM,OAAO,MAAM;GACnB,IAAI,qBAAqB,IAAI,GAAG;IAC9B,MAAM,EAAE,UAAU,aAAa,KAAK,0BAClC,OACA,OACA,UACA,QACA,aACF;IACA,MAAM,KA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
|
function toRelativeImport(from, target) {
|
|
80
|
-
const
|
|
80
|
+
const fromDir = dirname(from);
|
|
81
|
+
const rel = relative(fromDir, target);
|
|
81
82
|
if (!rel || rel.startsWith(".")) {
|
|
82
83
|
const fallback = normalizeTemplatePath(target).split("/").pop();
|
|
83
84
|
return rel || `./${fallback}`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"specialNodes.mjs","names":[],"sources":["../../../src/compiler/wxml/specialNodes.ts"],"sourcesContent":["import type {\n ImportEntry,\n IncludeEntry,\n RenderNode,\n TemplateDefinition,\n WxsEntry,\n} from './types'\n\nimport { dirname, relative } from 'pathe'\nimport { isKnownUnsupportedNativeComponent } from '../../shared/nativeComponents'\nimport { TEMPLATE_IMPORT_TAG_NAMES, TEMPLATE_INCLUDE_TAG_NAMES } from '../../shared/wxml'\n\nexport function shouldMarkWxsImport(pathname: string) {\n const lower = pathname.toLowerCase()\n if (lower.endsWith('.wxs') || lower.endsWith('.wxs.ts') || lower.endsWith('.wxs.js')) {\n return false\n }\n return lower.endsWith('.ts') || lower.endsWith('.js')\n}\n\ninterface CollectSpecialNodesContext {\n templates: TemplateDefinition[]\n includes: IncludeEntry[]\n imports: ImportEntry[]\n wxs: WxsEntry[]\n wxsModules: Map<string, string>\n warnings: string[]\n sourceId: string\n resolveTemplate: (raw: string) => string | undefined\n resolveWxs: (raw: string) => string | undefined\n}\n\nexport function collectSpecialNodes(nodes: RenderNode[], context: CollectSpecialNodesContext) {\n const renderable: RenderNode[] = []\n for (const node of nodes) {\n if (node.type === 'element') {\n const name = node.name ?? ''\n if (isKnownUnsupportedNativeComponent(name)) {\n const warning = `[web] 小程序组件 <${name}> 尚未提供完整 Web 语义,当前使用兼容 DOM 降级 (from ${context.sourceId})`\n if (!context.warnings.includes(warning)) {\n context.warnings.push(warning)\n }\n }\n if (name === 'template' && node.attribs?.name) {\n context.templates.push({\n name: node.attribs.name,\n nodes: collectSpecialNodes(node.children ?? [], context),\n })\n continue\n }\n if (TEMPLATE_IMPORT_TAG_NAMES.includes(name) && node.attribs?.src) {\n const resolved = context.resolveTemplate(node.attribs.src)\n if (resolved) {\n context.imports.push({\n id: resolved,\n importName: `__wxml_import_${context.imports.length}`,\n })\n }\n else {\n context.warnings.push(`[web] 无法解析模板依赖: ${node.attribs.src} (from ${context.sourceId})`)\n }\n continue\n }\n if (TEMPLATE_INCLUDE_TAG_NAMES.includes(name) && node.attribs?.src) {\n const resolved = context.resolveTemplate(node.attribs.src)\n if (resolved) {\n context.includes.push({\n id: resolved,\n importName: `__wxml_include_${context.includes.length}`,\n })\n }\n else {\n context.warnings.push(`[web] 无法解析模板依赖: ${node.attribs.src} (from ${context.sourceId})`)\n }\n continue\n }\n if (name === 'wxs') {\n const moduleName = node.attribs?.module?.trim()\n if (moduleName) {\n const previousSource = context.wxsModules.get(moduleName)\n if (previousSource) {\n context.warnings.push(`[web] WXS 模块名重复: ${moduleName} (from ${context.sourceId})`)\n }\n context.wxsModules.set(moduleName, context.sourceId)\n if (node.attribs?.src) {\n const resolved = context.resolveWxs(node.attribs.src)\n if (resolved) {\n context.wxs.push({\n module: moduleName,\n kind: 'src',\n importName: `__wxs_${context.wxs.length}`,\n value: resolved,\n })\n }\n }\n else {\n const inlineCode = (node.children ?? [])\n .filter(child => child.type === 'text')\n .map(child => child.data ?? '')\n .join('')\n context.wxs.push({\n module: moduleName,\n kind: 'inline',\n importName: `__wxs_${context.wxs.length}`,\n value: inlineCode,\n })\n }\n }\n continue\n }\n if (node.children?.length) {\n node.children = collectSpecialNodes(node.children, context)\n }\n }\n renderable.push(node)\n }\n return renderable\n}\n\nexport function normalizeTemplatePath(pathname: string) {\n return pathname.split('\\\\').join('/')\n}\n\nexport function toRelativeImport(from: string, target: string) {\n const fromDir = dirname(from)\n const rel = relative(fromDir, target)\n if (!rel || rel.startsWith('.')) {\n const fallback = normalizeTemplatePath(target).split('/').pop()!\n return rel || `./${fallback}`\n }\n return `./${rel}`\n}\n"],"mappings":";;;;;AAY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AK,QAAQ,IAAI,SAAS,QAAQ,SAAS,EAAE;IAExF;GACF;GACA,IAAI,SAAS,OAAO;IAClB,MAAM,aAAa,KAAK,SAAS,QAAQ,KAAK;IAC9C,IAAI,YAAY;KAEd,IADuB,QAAQ,WAAW,IAAI,UAC7B,GACf,QAAQ,SAAS,KAAK,oBAAoB,WAAW,SAAS,QAAQ,SAAS,EAAE;KAEnF,QAAQ,WAAW,IAAI,YAAY,QAAQ,QAAQ;KACnD,IAAI,KAAK,SAAS,KAAK;MACrB,MAAM,WAAW,QAAQ,WAAW,KAAK,QAAQ,GAAG;MACpD,IAAI,UACF,QAAQ,IAAI,KAAK;OACf,QAAQ;OACR,MAAM;OACN,YAAY,SAAS,QAAQ,IAAI;OACjC,OAAO;MACT,CAAC;KAEL,OACK;MACH,MAAM,cAAc,KAAK,YAAY,CAAC,EAAC,CACpC,QAAO,UAAS,MAAM,SAAS,MAAM,CAAC,CACtC,KAAI,UAAS,MAAM,QAAQ,EAAE,CAAC,CAC9B,KAAK,EAAE;MACV,QAAQ,IAAI,KAAK;OACf,QAAQ;OACR,MAAM;OACN,YAAY,SAAS,QAAQ,IAAI;OACjC,OAAO;MACT,CAAC;KACH;IACF;IACA;GACF;GACA,IAAI,KAAK,UAAU,QACjB,KAAK,WAAW,oBAAoB,KAAK,UAAU,OAAO;EAE9D;EACA,WAAW,KAAK,IAAI;CACtB;CACA,OAAO;AACT;AAEA,SAAgB,sBAAsB,UAAkB;CACtD,OAAO,SAAS,MAAM,IAAI,CAAC,CAAC,KAAK,GAAG;AACtC;AAEA,SAAgB,iBAAiB,MAAc,QAAgB;
|
|
1
|
+
{"version":3,"file":"specialNodes.mjs","names":[],"sources":["../../../src/compiler/wxml/specialNodes.ts"],"sourcesContent":["import type {\n ImportEntry,\n IncludeEntry,\n RenderNode,\n TemplateDefinition,\n WxsEntry,\n} from './types'\n\nimport { dirname, relative } from 'pathe'\nimport { isKnownUnsupportedNativeComponent } from '../../shared/nativeComponents'\nimport { TEMPLATE_IMPORT_TAG_NAMES, TEMPLATE_INCLUDE_TAG_NAMES } from '../../shared/wxml'\n\nexport function shouldMarkWxsImport(pathname: string) {\n const lower = pathname.toLowerCase()\n if (lower.endsWith('.wxs') || lower.endsWith('.wxs.ts') || lower.endsWith('.wxs.js')) {\n return false\n }\n return lower.endsWith('.ts') || lower.endsWith('.js')\n}\n\ninterface CollectSpecialNodesContext {\n templates: TemplateDefinition[]\n includes: IncludeEntry[]\n imports: ImportEntry[]\n wxs: WxsEntry[]\n wxsModules: Map<string, string>\n warnings: string[]\n sourceId: string\n resolveTemplate: (raw: string) => string | undefined\n resolveWxs: (raw: string) => string | undefined\n}\n\nexport function collectSpecialNodes(nodes: RenderNode[], context: CollectSpecialNodesContext) {\n const renderable: RenderNode[] = []\n for (const node of nodes) {\n if (node.type === 'element') {\n const name = node.name ?? ''\n if (isKnownUnsupportedNativeComponent(name)) {\n const warning = `[web] 小程序组件 <${name}> 尚未提供完整 Web 语义,当前使用兼容 DOM 降级 (from ${context.sourceId})`\n if (!context.warnings.includes(warning)) {\n context.warnings.push(warning)\n }\n }\n if (name === 'template' && node.attribs?.name) {\n context.templates.push({\n name: node.attribs.name,\n nodes: collectSpecialNodes(node.children ?? [], context),\n })\n continue\n }\n if (TEMPLATE_IMPORT_TAG_NAMES.includes(name) && node.attribs?.src) {\n const resolved = context.resolveTemplate(node.attribs.src)\n if (resolved) {\n context.imports.push({\n id: resolved,\n importName: `__wxml_import_${context.imports.length}`,\n })\n }\n else {\n context.warnings.push(`[web] 无法解析模板依赖: ${node.attribs.src} (from ${context.sourceId})`)\n }\n continue\n }\n if (TEMPLATE_INCLUDE_TAG_NAMES.includes(name) && node.attribs?.src) {\n const resolved = context.resolveTemplate(node.attribs.src)\n if (resolved) {\n context.includes.push({\n id: resolved,\n importName: `__wxml_include_${context.includes.length}`,\n })\n }\n else {\n context.warnings.push(`[web] 无法解析模板依赖: ${node.attribs.src} (from ${context.sourceId})`)\n }\n continue\n }\n if (name === 'wxs') {\n const moduleName = node.attribs?.module?.trim()\n if (moduleName) {\n const previousSource = context.wxsModules.get(moduleName)\n if (previousSource) {\n context.warnings.push(`[web] WXS 模块名重复: ${moduleName} (from ${context.sourceId})`)\n }\n context.wxsModules.set(moduleName, context.sourceId)\n if (node.attribs?.src) {\n const resolved = context.resolveWxs(node.attribs.src)\n if (resolved) {\n context.wxs.push({\n module: moduleName,\n kind: 'src',\n importName: `__wxs_${context.wxs.length}`,\n value: resolved,\n })\n }\n }\n else {\n const inlineCode = (node.children ?? [])\n .filter(child => child.type === 'text')\n .map(child => child.data ?? '')\n .join('')\n context.wxs.push({\n module: moduleName,\n kind: 'inline',\n importName: `__wxs_${context.wxs.length}`,\n value: inlineCode,\n })\n }\n }\n continue\n }\n if (node.children?.length) {\n node.children = collectSpecialNodes(node.children, context)\n }\n }\n renderable.push(node)\n }\n return renderable\n}\n\nexport function normalizeTemplatePath(pathname: string) {\n return pathname.split('\\\\').join('/')\n}\n\nexport function toRelativeImport(from: string, target: string) {\n const fromDir = dirname(from)\n const rel = relative(fromDir, target)\n if (!rel || rel.startsWith('.')) {\n const fallback = normalizeTemplatePath(target).split('/').pop()!\n return rel || `./${fallback}`\n }\n return `./${rel}`\n}\n"],"mappings":";;;;;AAYA,SAAgB,oBAAoB,UAAkB;CACpD,MAAM,QAAQ,SAAS,YAAY;CACnC,IAAI,MAAM,SAAS,MAAM,KAAK,MAAM,SAAS,SAAS,KAAK,MAAM,SAAS,SAAS,GACjF,OAAO;CAET,OAAO,MAAM,SAAS,KAAK,KAAK,MAAM,SAAS,KAAK;AACtD;AAcA,SAAgB,oBAAoB,OAAqB,SAAqC;CAC5F,MAAM,aAA2B,CAAC;CAClC,KAAK,MAAM,QAAQ,OAAO;EACxB,IAAI,KAAK,SAAS,WAAW;GAC3B,MAAM,OAAO,KAAK,QAAQ;GAC1B,IAAI,kCAAkC,IAAI,GAAG;IAC3C,MAAM,UAAU,gBAAgB,KAAK,sCAAsC,QAAQ,SAAS;IAC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I;OACjC,OAAO;MACT,CAAC;KAEL,OACK;MACH,MAAM,cAAc,KAAK,YAAY,CAAC,EAAC,CACpC,QAAO,UAAS,MAAM,SAAS,MAAM,CAAC,CACtC,KAAI,UAAS,MAAM,QAAQ,EAAE,CAAC,CAC9B,KAAK,EAAE;MACV,QAAQ,IAAI,KAAK;OACf,QAAQ;OACR,MAAM;OACN,YAAY,SAAS,QAAQ,IAAI;OACjC,OAAO;MACT,CAAC;KACH;IACF;IACA;GACF;GACA,IAAI,KAAK,UAAU,QACjB,KAAK,WAAW,oBAAoB,KAAK,UAAU,OAAO;EAE9D;EACA,WAAW,KAAK,IAAI;CACtB;CACA,OAAO;AACT;AAEA,SAAgB,sBAAsB,UAAkB;CACtD,OAAO,SAAS,MAAM,IAAI,CAAC,CAAC,KAAK,GAAG;AACtC;AAEA,SAAgB,iBAAiB,MAAc,QAAgB;CAC7D,MAAM,UAAU,QAAQ,IAAI;CAC5B,MAAM,MAAM,SAAS,SAAS,MAAM;CACpC,IAAI,CAAC,OAAO,IAAI,WAAW,GAAG,GAAG;EAC/B,MAAM,WAAW,sBAAsB,MAAM,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,IAAI;EAC9D,OAAO,OAAO,KAAK;CACrB;CACA,OAAO,KAAK;AACd"}
|
package/dist/index.d.mts
CHANGED
|
@@ -36,9 +36,4 @@ import { RuntimeWarningLevel, RuntimeWarningOptions, setRuntimeWarningOptions }
|
|
|
36
36
|
import { installWebModuleRegistration, registerWebWevuApp, registerWebWevuComponent } from "./runtime/wevu.mjs";
|
|
37
37
|
import "./runtime/index.mjs";
|
|
38
38
|
export * from "wevu/internal-runtime";
|
|
39
|
-
|
|
40
|
-
export { ButtonFormConfig, NavigationBarMetrics, RenderContext, ResolvedWebRoutingConfig, ResolvedWebViewportConfig, RpxConfig, RuntimeWarningLevel, RuntimeWarningOptions, TemplateRenderer, TemplateScope, WeappWebPluginOptions, WebPageHead, WebResourceHint, WebResourceHintRelation, WebResourceHintsConfig, WebRouteHistoryState, WebRouteTarget, WebRoutingConfig, WebRoutingMode, WebRuntimeClipboard, WebRuntimeDialogs, WebRuntimeHost, WebRuntimeStorage, WebSeoConfig, WebTabBarConfig, WebTabBarItem, WebViewportConfig, authorize, canIUse, checkSession, chooseAddress, chooseFile, chooseImage, chooseLocation, chooseMedia, chooseMessageFile, chooseVideo, clearStorage, clearStorageSync, compressImage, compressVideo, configureWebSeo, createCanvasContext, createInputEventDetail, createInterstitialAd, createRenderContext, createRewardedVideoAd, createScrollEventDetail, createSelectorQuery, createSwitchEventDetail, createTemplate, createTextareaLineChangeDetail, createVKSession, createVideoContext, createVideoProgressDetail, createVideoTimeUpdateDetail, createWorker, defineComponent, disposeWebRouting, downloadFile, ensureButtonDefined, ensureNativeComponentsDefined, exitMiniProgram, getAccountInfoSync, getAppAuthorizeSetting, getAppBaseInfo, getBatteryInfo, getBatteryInfoSync, getClipboardData, getDeviceInfo, getEnterOptionsSync, getExtConfig, getExtConfigSync, getFileSystemManager, getFuzzyLocation, getImageInfo, getLaunchOptionsSync, getLocation, getLogManager, getMenuButtonBoundingClientRect, getNetworkType, getRuntimeClipboard, getRuntimeDialogs, getRuntimeExecutionMode, getRuntimeFetch, getRuntimeStorage, getSetting, getStorage, getStorageInfo, getStorageInfoSync, getStorageSync, getSystemInfo, getSystemInfoSync, getSystemSetting, getUpdateManager, getUserInfo, getUserProfile, getVideoInfo, getWebRoutingConfig, getWebRuntimeHost, getWebViewportWidth, getWindowInfo, hideKeyboard, hideLoading, hideNavigationBarLoading, hideTabBar, hideTabBarRedDot, initializePageRoutes, injectStyle, installWebHostGlobals, installWebModuleRegistration, loadSubPackage, login, makePhoneCall, navigateBack, navigateTo, navigateToMiniProgram, nextTick, offNetworkStatusChange, offWindowResize, onNetworkStatusChange, onWindowResize, openAppAuthorizeSetting, openCustomerServiceChat, openDocument, openLocation, openRuntimeUrl, openSetting, openVideoEditor, pageScrollTo, preloadSubpackage, previewImage, previewMedia, reLaunch, redirectTo, registerApp, registerComponent, registerPage, registerWebWevuApp, registerWebWevuComponent, removeStorage, removeStorageSync, removeStyle, removeTabBarBadge, renderTemplate, reportAnalytics, request, requestPayment, requestSubscribeMessage, resetWebDocumentHead, resetWebRuntimeHost, resolveImageModeStyle, resolveVideoObjectFit, resolveWebRoutingConfig, resolveWebViewportConfig, saveFile, saveFileToDisk, saveImageToPhotosAlbum, saveVideoToPhotosAlbum, scanCode, setBackgroundColor, setBackgroundTextStyle, setButtonFormConfig, setClipboardData, setNavigationBarColor, setNavigationBarMetrics, setNavigationBarTitle, setPageLayout, setRuntimeExecutionMode, setRuntimeWarningOptions, setStorage, setStorageSync, setTabBarBadge, setTabBarItem, setTabBarStyle, setWebRuntimeHost, setupRpx, setupWebResourceHints, setupWebViewport, showActionSheet, showLoading, showModal, showNavigationBarLoading, showShareMenu, showTabBar, showTabBarRedDot, showToast, startPullDownRefresh, stopPullDownRefresh, switchTab, syncWebDocumentHead, transformWxssToCss, updateShareMenu, updateWebDocumentTitle, uploadFile, vibrateShort, weappWebPlugin };
|
|
41
|
-
}
|
|
42
|
-
//#endregion
|
|
43
|
-
export { type ButtonFormConfig, type NavigationBarMetrics, type RenderContext, type ResolvedWebRoutingConfig, type ResolvedWebViewportConfig, type RpxConfig, type RuntimeWarningLevel, type RuntimeWarningOptions, type TemplateRenderer, type TemplateScope, type WeappWebPluginOptions, type WebPageHead, type WebResourceHint, type WebResourceHintRelation, type WebResourceHintsConfig, type WebRouteHistoryState, type WebRouteTarget, type WebRoutingConfig, type WebRoutingMode, type WebRuntimeClipboard, type WebRuntimeDialogs, type WebRuntimeHost, type WebRuntimeStorage, type WebSeoConfig, type WebTabBarConfig, type WebTabBarItem, type WebViewportConfig, authorize, canIUse, checkSession, chooseAddress, chooseFile, chooseImage, chooseLocation, chooseMedia, chooseMessageFile, chooseVideo, clearStorage, clearStorageSync, compressImage, compressVideo, configureWebSeo, createCanvasContext, createInputEventDetail, createInterstitialAd, createRenderContext, createRewardedVideoAd, createScrollEventDetail, createSelectorQuery, createSwitchEventDetail, createTemplate, createTextareaLineChangeDetail, createVKSession, createVideoContext, createVideoProgressDetail, createVideoTimeUpdateDetail, createWorker, defineComponent, disposeWebRouting, downloadFile, ensureButtonDefined, ensureNativeComponentsDefined, exitMiniProgram, getAccountInfoSync, getAppAuthorizeSetting, getAppBaseInfo, getBatteryInfo, getBatteryInfoSync, getClipboardData, getDeviceInfo, getEnterOptionsSync, getExtConfig, getExtConfigSync, getFileSystemManager, getFuzzyLocation, getImageInfo, getLaunchOptionsSync, getLocation, getLogManager, getMenuButtonBoundingClientRect, getNetworkType, getRuntimeClipboard, getRuntimeDialogs, getRuntimeExecutionMode, getRuntimeFetch, getRuntimeStorage, getSetting, getStorage, getStorageInfo, getStorageInfoSync, getStorageSync, getSystemInfo, getSystemInfoSync, getSystemSetting, getUpdateManager, getUserInfo, getUserProfile, getVideoInfo, getWebRoutingConfig, getWebRuntimeHost, getWebViewportWidth, getWindowInfo, hideKeyboard, hideLoading, hideNavigationBarLoading, hideTabBar, hideTabBarRedDot, initializePageRoutes, injectStyle, installWebHostGlobals, installWebModuleRegistration, loadSubPackage, login, makePhoneCall, navigateBack, navigateTo, navigateToMiniProgram, nextTick, offNetworkStatusChange, offWindowResize, onNetworkStatusChange, onWindowResize, openAppAuthorizeSetting, openCustomerServiceChat, openDocument, openLocation, openRuntimeUrl, openSetting, openVideoEditor, pageScrollTo, preloadSubpackage, previewImage, previewMedia, reLaunch, redirectTo, registerApp, registerComponent, registerPage, registerWebWevuApp, registerWebWevuComponent, removeStorage, removeStorageSync, removeStyle, removeTabBarBadge, renderTemplate, reportAnalytics, request, requestPayment, requestSubscribeMessage, resetWebDocumentHead, resetWebRuntimeHost, resolveImageModeStyle, resolveVideoObjectFit, resolveWebRoutingConfig, resolveWebViewportConfig, saveFile, saveFileToDisk, saveImageToPhotosAlbum, saveVideoToPhotosAlbum, scanCode, setBackgroundColor, setBackgroundTextStyle, setButtonFormConfig, setClipboardData, setNavigationBarColor, setNavigationBarMetrics, setNavigationBarTitle, setPageLayout, setRuntimeExecutionMode, setRuntimeWarningOptions, setStorage, setStorageSync, setTabBarBadge, setTabBarItem, setTabBarStyle, setWebRuntimeHost, setupRpx, setupWebResourceHints, setupWebViewport, showActionSheet, showLoading, showModal, showNavigationBarLoading, showShareMenu, showTabBar, showTabBarRedDot, showToast, startPullDownRefresh, stopPullDownRefresh, switchTab, syncWebDocumentHead, transformWxssToCss, updateShareMenu, updateWebDocumentTitle, uploadFile, vibrateShort, weappWebPlugin };
|
|
44
|
-
//# sourceMappingURL=index.d.mts.map
|
|
39
|
+
export { type ButtonFormConfig, type NavigationBarMetrics, type RenderContext, type ResolvedWebRoutingConfig, type ResolvedWebViewportConfig, type RpxConfig, type RuntimeWarningLevel, type RuntimeWarningOptions, type TemplateRenderer, type TemplateScope, type WeappWebPluginOptions, type WebPageHead, type WebResourceHint, type WebResourceHintRelation, type WebResourceHintsConfig, type WebRouteHistoryState, type WebRouteTarget, type WebRoutingConfig, type WebRoutingMode, type WebRuntimeClipboard, type WebRuntimeDialogs, type WebRuntimeHost, type WebRuntimeStorage, type WebSeoConfig, type WebTabBarConfig, type WebTabBarItem, type WebViewportConfig, authorize, canIUse, checkSession, chooseAddress, chooseFile, chooseImage, chooseLocation, chooseMedia, chooseMessageFile, chooseVideo, clearStorage, clearStorageSync, compressImage, compressVideo, configureWebSeo, createCanvasContext, createInputEventDetail, createInterstitialAd, createRenderContext, createRewardedVideoAd, createScrollEventDetail, createSelectorQuery, createSwitchEventDetail, createTemplate, createTextareaLineChangeDetail, createVKSession, createVideoContext, createVideoProgressDetail, createVideoTimeUpdateDetail, createWorker, defineComponent, disposeWebRouting, downloadFile, ensureButtonDefined, ensureNativeComponentsDefined, exitMiniProgram, getAccountInfoSync, getAppAuthorizeSetting, getAppBaseInfo, getBatteryInfo, getBatteryInfoSync, getClipboardData, getDeviceInfo, getEnterOptionsSync, getExtConfig, getExtConfigSync, getFileSystemManager, getFuzzyLocation, getImageInfo, getLaunchOptionsSync, getLocation, getLogManager, getMenuButtonBoundingClientRect, getNetworkType, getRuntimeClipboard, getRuntimeDialogs, getRuntimeExecutionMode, getRuntimeFetch, getRuntimeStorage, getSetting, getStorage, getStorageInfo, getStorageInfoSync, getStorageSync, getSystemInfo, getSystemInfoSync, getSystemSetting, getUpdateManager, getUserInfo, getUserProfile, getVideoInfo, getWebRoutingConfig, getWebRuntimeHost, getWebViewportWidth, getWindowInfo, hideKeyboard, hideLoading, hideNavigationBarLoading, hideTabBar, hideTabBarRedDot, initializePageRoutes, injectStyle, installWebHostGlobals, installWebModuleRegistration, loadSubPackage, login, makePhoneCall, navigateBack, navigateTo, navigateToMiniProgram, nextTick, offNetworkStatusChange, offWindowResize, onNetworkStatusChange, onWindowResize, openAppAuthorizeSetting, openCustomerServiceChat, openDocument, openLocation, openRuntimeUrl, openSetting, openVideoEditor, pageScrollTo, preloadSubpackage, previewImage, previewMedia, reLaunch, redirectTo, registerApp, registerComponent, registerPage, registerWebWevuApp, registerWebWevuComponent, removeStorage, removeStorageSync, removeStyle, removeTabBarBadge, renderTemplate, reportAnalytics, request, requestPayment, requestSubscribeMessage, resetWebDocumentHead, resetWebRuntimeHost, resolveImageModeStyle, resolveVideoObjectFit, resolveWebRoutingConfig, resolveWebViewportConfig, saveFile, saveFileToDisk, saveImageToPhotosAlbum, saveVideoToPhotosAlbum, scanCode, setBackgroundColor, setBackgroundTextStyle, setButtonFormConfig, setClipboardData, setNavigationBarColor, setNavigationBarMetrics, setNavigationBarTitle, setPageLayout, setRuntimeExecutionMode, setRuntimeWarningOptions, setStorage, setStorageSync, setTabBarBadge, setTabBarItem, setTabBarStyle, setWebRuntimeHost, setupRpx, setupWebResourceHints, setupWebViewport, showActionSheet, showLoading, showModal, showNavigationBarLoading, showShareMenu, showTabBar, showTabBarRedDot, showToast, startPullDownRefresh, stopPullDownRefresh, switchTab, syncWebDocumentHead, transformWxssToCss, updateShareMenu, updateWebDocumentTitle, uploadFile, vibrateShort, weappWebPlugin };
|
package/dist/index.mjs
CHANGED
|
@@ -32,180 +32,4 @@ import { installWebModuleRegistration, registerWebWevuApp, registerWebWevuCompon
|
|
|
32
32
|
|
|
33
33
|
export * from "wevu/internal-runtime"
|
|
34
34
|
|
|
35
|
-
|
|
36
|
-
var src_exports = /* @__PURE__ */ __exportAll({
|
|
37
|
-
authorize: () => authorize,
|
|
38
|
-
canIUse: () => canIUse,
|
|
39
|
-
checkSession: () => checkSession,
|
|
40
|
-
chooseAddress: () => chooseAddress,
|
|
41
|
-
chooseFile: () => chooseFile,
|
|
42
|
-
chooseImage: () => chooseImage,
|
|
43
|
-
chooseLocation: () => chooseLocation,
|
|
44
|
-
chooseMedia: () => chooseMedia,
|
|
45
|
-
chooseMessageFile: () => chooseMessageFile,
|
|
46
|
-
chooseVideo: () => chooseVideo,
|
|
47
|
-
clearStorage: () => clearStorage,
|
|
48
|
-
clearStorageSync: () => clearStorageSync,
|
|
49
|
-
compressImage: () => compressImage,
|
|
50
|
-
compressVideo: () => compressVideo,
|
|
51
|
-
configureWebSeo: () => configureWebSeo,
|
|
52
|
-
createCanvasContext: () => createCanvasContext,
|
|
53
|
-
createInputEventDetail: () => createInputEventDetail,
|
|
54
|
-
createInterstitialAd: () => createInterstitialAd,
|
|
55
|
-
createRenderContext: () => createRenderContext,
|
|
56
|
-
createRewardedVideoAd: () => createRewardedVideoAd,
|
|
57
|
-
createScrollEventDetail: () => createScrollEventDetail,
|
|
58
|
-
createSelectorQuery: () => createSelectorQuery,
|
|
59
|
-
createSwitchEventDetail: () => createSwitchEventDetail,
|
|
60
|
-
createTemplate: () => createTemplate,
|
|
61
|
-
createTextareaLineChangeDetail: () => createTextareaLineChangeDetail,
|
|
62
|
-
createVKSession: () => createVKSession,
|
|
63
|
-
createVideoContext: () => createVideoContext,
|
|
64
|
-
createVideoProgressDetail: () => createVideoProgressDetail,
|
|
65
|
-
createVideoTimeUpdateDetail: () => createVideoTimeUpdateDetail,
|
|
66
|
-
createWorker: () => createWorker,
|
|
67
|
-
defineComponent: () => defineComponent,
|
|
68
|
-
disposeWebRouting: () => disposeWebRouting,
|
|
69
|
-
downloadFile: () => downloadFile,
|
|
70
|
-
ensureButtonDefined: () => ensureButtonDefined,
|
|
71
|
-
ensureNativeComponentsDefined: () => ensureNativeComponentsDefined,
|
|
72
|
-
exitMiniProgram: () => exitMiniProgram,
|
|
73
|
-
getAccountInfoSync: () => getAccountInfoSync,
|
|
74
|
-
getAppAuthorizeSetting: () => getAppAuthorizeSetting,
|
|
75
|
-
getAppBaseInfo: () => getAppBaseInfo,
|
|
76
|
-
getBatteryInfo: () => getBatteryInfo,
|
|
77
|
-
getBatteryInfoSync: () => getBatteryInfoSync,
|
|
78
|
-
getClipboardData: () => getClipboardData,
|
|
79
|
-
getDeviceInfo: () => getDeviceInfo,
|
|
80
|
-
getEnterOptionsSync: () => getEnterOptionsSync,
|
|
81
|
-
getExtConfig: () => getExtConfig,
|
|
82
|
-
getExtConfigSync: () => getExtConfigSync,
|
|
83
|
-
getFileSystemManager: () => getFileSystemManager,
|
|
84
|
-
getFuzzyLocation: () => getFuzzyLocation,
|
|
85
|
-
getImageInfo: () => getImageInfo,
|
|
86
|
-
getLaunchOptionsSync: () => getLaunchOptionsSync,
|
|
87
|
-
getLocation: () => getLocation,
|
|
88
|
-
getLogManager: () => getLogManager,
|
|
89
|
-
getMenuButtonBoundingClientRect: () => getMenuButtonBoundingClientRect,
|
|
90
|
-
getNetworkType: () => getNetworkType,
|
|
91
|
-
getRuntimeClipboard: () => getRuntimeClipboard,
|
|
92
|
-
getRuntimeDialogs: () => getRuntimeDialogs,
|
|
93
|
-
getRuntimeExecutionMode: () => getRuntimeExecutionMode,
|
|
94
|
-
getRuntimeFetch: () => getRuntimeFetch,
|
|
95
|
-
getRuntimeStorage: () => getRuntimeStorage,
|
|
96
|
-
getSetting: () => getSetting,
|
|
97
|
-
getStorage: () => getStorage,
|
|
98
|
-
getStorageInfo: () => getStorageInfo,
|
|
99
|
-
getStorageInfoSync: () => getStorageInfoSync,
|
|
100
|
-
getStorageSync: () => getStorageSync,
|
|
101
|
-
getSystemInfo: () => getSystemInfo,
|
|
102
|
-
getSystemInfoSync: () => getSystemInfoSync,
|
|
103
|
-
getSystemSetting: () => getSystemSetting,
|
|
104
|
-
getUpdateManager: () => getUpdateManager,
|
|
105
|
-
getUserInfo: () => getUserInfo,
|
|
106
|
-
getUserProfile: () => getUserProfile,
|
|
107
|
-
getVideoInfo: () => getVideoInfo,
|
|
108
|
-
getWebRoutingConfig: () => getWebRoutingConfig,
|
|
109
|
-
getWebRuntimeHost: () => getWebRuntimeHost,
|
|
110
|
-
getWebViewportWidth: () => getWebViewportWidth,
|
|
111
|
-
getWindowInfo: () => getWindowInfo,
|
|
112
|
-
hideKeyboard: () => hideKeyboard,
|
|
113
|
-
hideLoading: () => hideLoading,
|
|
114
|
-
hideNavigationBarLoading: () => hideNavigationBarLoading,
|
|
115
|
-
hideTabBar: () => hideTabBar,
|
|
116
|
-
hideTabBarRedDot: () => hideTabBarRedDot,
|
|
117
|
-
initializePageRoutes: () => initializePageRoutes,
|
|
118
|
-
injectStyle: () => injectStyle,
|
|
119
|
-
installWebHostGlobals: () => installWebHostGlobals,
|
|
120
|
-
installWebModuleRegistration: () => installWebModuleRegistration,
|
|
121
|
-
loadSubPackage: () => loadSubPackage,
|
|
122
|
-
login: () => login,
|
|
123
|
-
makePhoneCall: () => makePhoneCall,
|
|
124
|
-
navigateBack: () => navigateBack,
|
|
125
|
-
navigateTo: () => navigateTo,
|
|
126
|
-
navigateToMiniProgram: () => navigateToMiniProgram,
|
|
127
|
-
nextTick: () => nextTick,
|
|
128
|
-
offNetworkStatusChange: () => offNetworkStatusChange,
|
|
129
|
-
offWindowResize: () => offWindowResize,
|
|
130
|
-
onNetworkStatusChange: () => onNetworkStatusChange,
|
|
131
|
-
onWindowResize: () => onWindowResize,
|
|
132
|
-
openAppAuthorizeSetting: () => openAppAuthorizeSetting,
|
|
133
|
-
openCustomerServiceChat: () => openCustomerServiceChat,
|
|
134
|
-
openDocument: () => openDocument,
|
|
135
|
-
openLocation: () => openLocation,
|
|
136
|
-
openRuntimeUrl: () => openRuntimeUrl,
|
|
137
|
-
openSetting: () => openSetting,
|
|
138
|
-
openVideoEditor: () => openVideoEditor,
|
|
139
|
-
pageScrollTo: () => pageScrollTo,
|
|
140
|
-
preloadSubpackage: () => preloadSubpackage,
|
|
141
|
-
previewImage: () => previewImage,
|
|
142
|
-
previewMedia: () => previewMedia,
|
|
143
|
-
reLaunch: () => reLaunch,
|
|
144
|
-
redirectTo: () => redirectTo,
|
|
145
|
-
registerApp: () => registerApp,
|
|
146
|
-
registerComponent: () => registerComponent,
|
|
147
|
-
registerPage: () => registerPage,
|
|
148
|
-
registerWebWevuApp: () => registerWebWevuApp,
|
|
149
|
-
registerWebWevuComponent: () => registerWebWevuComponent,
|
|
150
|
-
removeStorage: () => removeStorage,
|
|
151
|
-
removeStorageSync: () => removeStorageSync,
|
|
152
|
-
removeStyle: () => removeStyle,
|
|
153
|
-
removeTabBarBadge: () => removeTabBarBadge,
|
|
154
|
-
renderTemplate: () => renderTemplate,
|
|
155
|
-
reportAnalytics: () => reportAnalytics,
|
|
156
|
-
request: () => request,
|
|
157
|
-
requestPayment: () => requestPayment,
|
|
158
|
-
requestSubscribeMessage: () => requestSubscribeMessage,
|
|
159
|
-
resetWebDocumentHead: () => resetWebDocumentHead,
|
|
160
|
-
resetWebRuntimeHost: () => resetWebRuntimeHost,
|
|
161
|
-
resolveImageModeStyle: () => resolveImageModeStyle,
|
|
162
|
-
resolveVideoObjectFit: () => resolveVideoObjectFit,
|
|
163
|
-
resolveWebRoutingConfig: () => resolveWebRoutingConfig,
|
|
164
|
-
resolveWebViewportConfig: () => resolveWebViewportConfig,
|
|
165
|
-
saveFile: () => saveFile,
|
|
166
|
-
saveFileToDisk: () => saveFileToDisk,
|
|
167
|
-
saveImageToPhotosAlbum: () => saveImageToPhotosAlbum,
|
|
168
|
-
saveVideoToPhotosAlbum: () => saveVideoToPhotosAlbum,
|
|
169
|
-
scanCode: () => scanCode,
|
|
170
|
-
setBackgroundColor: () => setBackgroundColor,
|
|
171
|
-
setBackgroundTextStyle: () => setBackgroundTextStyle,
|
|
172
|
-
setButtonFormConfig: () => setButtonFormConfig,
|
|
173
|
-
setClipboardData: () => setClipboardData,
|
|
174
|
-
setNavigationBarColor: () => setNavigationBarColor,
|
|
175
|
-
setNavigationBarMetrics: () => setNavigationBarMetrics,
|
|
176
|
-
setNavigationBarTitle: () => setNavigationBarTitle,
|
|
177
|
-
setPageLayout: () => setPageLayout,
|
|
178
|
-
setRuntimeExecutionMode: () => setRuntimeExecutionMode,
|
|
179
|
-
setRuntimeWarningOptions: () => setRuntimeWarningOptions,
|
|
180
|
-
setStorage: () => setStorage,
|
|
181
|
-
setStorageSync: () => setStorageSync,
|
|
182
|
-
setTabBarBadge: () => setTabBarBadge,
|
|
183
|
-
setTabBarItem: () => setTabBarItem,
|
|
184
|
-
setTabBarStyle: () => setTabBarStyle,
|
|
185
|
-
setWebRuntimeHost: () => setWebRuntimeHost,
|
|
186
|
-
setupRpx: () => setupRpx,
|
|
187
|
-
setupWebResourceHints: () => setupWebResourceHints,
|
|
188
|
-
setupWebViewport: () => setupWebViewport,
|
|
189
|
-
showActionSheet: () => showActionSheet,
|
|
190
|
-
showLoading: () => showLoading,
|
|
191
|
-
showModal: () => showModal,
|
|
192
|
-
showNavigationBarLoading: () => showNavigationBarLoading,
|
|
193
|
-
showShareMenu: () => showShareMenu,
|
|
194
|
-
showTabBar: () => showTabBar,
|
|
195
|
-
showTabBarRedDot: () => showTabBarRedDot,
|
|
196
|
-
showToast: () => showToast,
|
|
197
|
-
startPullDownRefresh: () => startPullDownRefresh,
|
|
198
|
-
stopPullDownRefresh: () => stopPullDownRefresh,
|
|
199
|
-
switchTab: () => switchTab,
|
|
200
|
-
syncWebDocumentHead: () => syncWebDocumentHead,
|
|
201
|
-
transformWxssToCss: () => transformWxssToCss,
|
|
202
|
-
updateShareMenu: () => updateShareMenu,
|
|
203
|
-
updateWebDocumentTitle: () => updateWebDocumentTitle,
|
|
204
|
-
uploadFile: () => uploadFile,
|
|
205
|
-
vibrateShort: () => vibrateShort,
|
|
206
|
-
weappWebPlugin: () => weappWebPlugin
|
|
207
|
-
});
|
|
208
|
-
|
|
209
|
-
//#endregion
|
|
210
|
-
export { authorize, canIUse, checkSession, chooseAddress, chooseFile, chooseImage, chooseLocation, chooseMedia, chooseMessageFile, chooseVideo, clearStorage, clearStorageSync, compressImage, compressVideo, configureWebSeo, createCanvasContext, createInputEventDetail, createInterstitialAd, createRenderContext, createRewardedVideoAd, createScrollEventDetail, createSelectorQuery, createSwitchEventDetail, createTemplate, createTextareaLineChangeDetail, createVKSession, createVideoContext, createVideoProgressDetail, createVideoTimeUpdateDetail, createWorker, defineComponent, disposeWebRouting, downloadFile, ensureButtonDefined, ensureNativeComponentsDefined, exitMiniProgram, getAccountInfoSync, getAppAuthorizeSetting, getAppBaseInfo, getBatteryInfo, getBatteryInfoSync, getClipboardData, getDeviceInfo, getEnterOptionsSync, getExtConfig, getExtConfigSync, getFileSystemManager, getFuzzyLocation, getImageInfo, getLaunchOptionsSync, getLocation, getLogManager, getMenuButtonBoundingClientRect, getNetworkType, getRuntimeClipboard, getRuntimeDialogs, getRuntimeExecutionMode, getRuntimeFetch, getRuntimeStorage, getSetting, getStorage, getStorageInfo, getStorageInfoSync, getStorageSync, getSystemInfo, getSystemInfoSync, getSystemSetting, getUpdateManager, getUserInfo, getUserProfile, getVideoInfo, getWebRoutingConfig, getWebRuntimeHost, getWebViewportWidth, getWindowInfo, hideKeyboard, hideLoading, hideNavigationBarLoading, hideTabBar, hideTabBarRedDot, initializePageRoutes, injectStyle, installWebHostGlobals, installWebModuleRegistration, loadSubPackage, login, makePhoneCall, navigateBack, navigateTo, navigateToMiniProgram, nextTick, offNetworkStatusChange, offWindowResize, onNetworkStatusChange, onWindowResize, openAppAuthorizeSetting, openCustomerServiceChat, openDocument, openLocation, openRuntimeUrl, openSetting, openVideoEditor, pageScrollTo, preloadSubpackage, previewImage, previewMedia, reLaunch, redirectTo, registerApp, registerComponent, registerPage, registerWebWevuApp, registerWebWevuComponent, removeStorage, removeStorageSync, removeStyle, removeTabBarBadge, renderTemplate, reportAnalytics, request, requestPayment, requestSubscribeMessage, resetWebDocumentHead, resetWebRuntimeHost, resolveImageModeStyle, resolveVideoObjectFit, resolveWebRoutingConfig, resolveWebViewportConfig, saveFile, saveFileToDisk, saveImageToPhotosAlbum, saveVideoToPhotosAlbum, scanCode, setBackgroundColor, setBackgroundTextStyle, setButtonFormConfig, setClipboardData, setNavigationBarColor, setNavigationBarMetrics, setNavigationBarTitle, setPageLayout, setRuntimeExecutionMode, setRuntimeWarningOptions, setStorage, setStorageSync, setTabBarBadge, setTabBarItem, setTabBarStyle, setWebRuntimeHost, setupRpx, setupWebResourceHints, setupWebViewport, showActionSheet, showLoading, showModal, showNavigationBarLoading, showShareMenu, showTabBar, showTabBarRedDot, showToast, startPullDownRefresh, stopPullDownRefresh, switchTab, syncWebDocumentHead, transformWxssToCss, updateShareMenu, updateWebDocumentTitle, uploadFile, vibrateShort, weappWebPlugin };
|
|
211
|
-
//# sourceMappingURL=index.mjs.map
|
|
35
|
+
export { authorize, canIUse, checkSession, chooseAddress, chooseFile, chooseImage, chooseLocation, chooseMedia, chooseMessageFile, chooseVideo, clearStorage, clearStorageSync, compressImage, compressVideo, configureWebSeo, createCanvasContext, createInputEventDetail, createInterstitialAd, createRenderContext, createRewardedVideoAd, createScrollEventDetail, createSelectorQuery, createSwitchEventDetail, createTemplate, createTextareaLineChangeDetail, createVKSession, createVideoContext, createVideoProgressDetail, createVideoTimeUpdateDetail, createWorker, defineComponent, disposeWebRouting, downloadFile, ensureButtonDefined, ensureNativeComponentsDefined, exitMiniProgram, getAccountInfoSync, getAppAuthorizeSetting, getAppBaseInfo, getBatteryInfo, getBatteryInfoSync, getClipboardData, getDeviceInfo, getEnterOptionsSync, getExtConfig, getExtConfigSync, getFileSystemManager, getFuzzyLocation, getImageInfo, getLaunchOptionsSync, getLocation, getLogManager, getMenuButtonBoundingClientRect, getNetworkType, getRuntimeClipboard, getRuntimeDialogs, getRuntimeExecutionMode, getRuntimeFetch, getRuntimeStorage, getSetting, getStorage, getStorageInfo, getStorageInfoSync, getStorageSync, getSystemInfo, getSystemInfoSync, getSystemSetting, getUpdateManager, getUserInfo, getUserProfile, getVideoInfo, getWebRoutingConfig, getWebRuntimeHost, getWebViewportWidth, getWindowInfo, hideKeyboard, hideLoading, hideNavigationBarLoading, hideTabBar, hideTabBarRedDot, initializePageRoutes, injectStyle, installWebHostGlobals, installWebModuleRegistration, loadSubPackage, login, makePhoneCall, navigateBack, navigateTo, navigateToMiniProgram, nextTick, offNetworkStatusChange, offWindowResize, onNetworkStatusChange, onWindowResize, openAppAuthorizeSetting, openCustomerServiceChat, openDocument, openLocation, openRuntimeUrl, openSetting, openVideoEditor, pageScrollTo, preloadSubpackage, previewImage, previewMedia, reLaunch, redirectTo, registerApp, registerComponent, registerPage, registerWebWevuApp, registerWebWevuComponent, removeStorage, removeStorageSync, removeStyle, removeTabBarBadge, renderTemplate, reportAnalytics, request, requestPayment, requestSubscribeMessage, resetWebDocumentHead, resetWebRuntimeHost, resolveImageModeStyle, resolveVideoObjectFit, resolveWebRoutingConfig, resolveWebViewportConfig, saveFile, saveFileToDisk, saveImageToPhotosAlbum, saveVideoToPhotosAlbum, scanCode, setBackgroundColor, setBackgroundTextStyle, setButtonFormConfig, setClipboardData, setNavigationBarColor, setNavigationBarMetrics, setNavigationBarTitle, setPageLayout, setRuntimeExecutionMode, setRuntimeWarningOptions, setStorage, setStorageSync, setTabBarBadge, setTabBarItem, setTabBarStyle, setWebRuntimeHost, setupRpx, setupWebResourceHints, setupWebViewport, showActionSheet, showLoading, showModal, showNavigationBarLoading, showShareMenu, showTabBar, showTabBarRedDot, showToast, startPullDownRefresh, stopPullDownRefresh, switchTab, syncWebDocumentHead, transformWxssToCss, updateShareMenu, updateWebDocumentTitle, uploadFile, vibrateShort, weappWebPlugin };
|
package/dist/plugin/index.mjs
CHANGED
|
@@ -184,7 +184,8 @@ function weappWebPlugin(options = {}) {
|
|
|
184
184
|
}
|
|
185
185
|
if (hasWxsQuery(id)) {
|
|
186
186
|
const filename = cleanUrl(id);
|
|
187
|
-
const
|
|
187
|
+
const source = await readFile(filename, "utf8");
|
|
188
|
+
const compiled = transformWxsToEsm(source, filename, {
|
|
188
189
|
resolvePath: resolveWxsPath,
|
|
189
190
|
toImportPath: (resolved, importer) => normalizePath(toRelativeImport(importer, resolved))
|
|
190
191
|
});
|
|
@@ -193,14 +194,15 @@ function weappWebPlugin(options = {}) {
|
|
|
193
194
|
return compiled.code;
|
|
194
195
|
}
|
|
195
196
|
if (hasQuery(id, "weapp-web-style")) {
|
|
196
|
-
const
|
|
197
|
+
const source = await readFile(cleanUrl(id), "utf8");
|
|
198
|
+
const { css } = transformWxssToCss(source, wxssOptions);
|
|
197
199
|
return createInlineStyleModule(css);
|
|
198
200
|
}
|
|
199
201
|
if (id.includes(`?${"weapp-web-sfc-template"}`) || id.includes(`&${"weapp-web-sfc-template"}`)) {
|
|
200
202
|
const filename = cleanUrl(id);
|
|
201
203
|
const meta = state.moduleMeta.get(normalizePath(filename));
|
|
202
204
|
if (!meta) return null;
|
|
203
|
-
const
|
|
205
|
+
const result = await ensureWebVueSfcResult({
|
|
204
206
|
filename,
|
|
205
207
|
meta,
|
|
206
208
|
srcRoot,
|
|
@@ -208,7 +210,8 @@ function weappWebPlugin(options = {}) {
|
|
|
208
210
|
resolveId: resolveWebModuleId,
|
|
209
211
|
resolveAutoImportTag: resolveWebAutoImportTag,
|
|
210
212
|
uniApp: options.__uniApp
|
|
211
|
-
})
|
|
213
|
+
});
|
|
214
|
+
const compiled = generateWebVueSfcTemplate(result, meta, filename, srcRoot);
|
|
212
215
|
for (const dependency of compiled.dependencies) this.addWatchFile?.(dependency);
|
|
213
216
|
for (const warning of compiled.warnings ?? []) this.warn?.(warning);
|
|
214
217
|
return compiled.code;
|
|
@@ -217,7 +220,7 @@ function weappWebPlugin(options = {}) {
|
|
|
217
220
|
const filename = resolveSfcStyleSourceFilename(id);
|
|
218
221
|
const meta = state.moduleMeta.get(normalizePath(filename));
|
|
219
222
|
if (!meta) return null;
|
|
220
|
-
|
|
223
|
+
const result = await ensureWebVueSfcResult({
|
|
221
224
|
filename,
|
|
222
225
|
meta,
|
|
223
226
|
srcRoot,
|
|
@@ -225,7 +228,8 @@ function weappWebPlugin(options = {}) {
|
|
|
225
228
|
resolveId: resolveWebModuleId,
|
|
226
229
|
resolveAutoImportTag: resolveWebAutoImportTag,
|
|
227
230
|
uniApp: options.__uniApp
|
|
228
|
-
})
|
|
231
|
+
});
|
|
232
|
+
return generateWebVueSfcStyle(result);
|
|
229
233
|
}
|
|
230
234
|
return null;
|
|
231
235
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/plugin/index.ts"],"sourcesContent":["import type { SourceMap } from 'magic-string'\nimport type { ResolveWebAutoImportTag, ResolveWebModuleId, WeappWebPluginOptions, WebResolvedComponent } from './types'\nimport { readFile } from 'node:fs/promises'\nimport process from 'node:process'\n\nimport { dirname, extname, resolve } from 'pathe'\nimport { isUniAppCompatibilityFile, transformUniAppSource } from 'wevu/compiler'\nimport { compileWxml } from '../compiler/wxml'\nimport { transformWxsToEsm } from '../compiler/wxs'\nimport { createWxssPostcssPlugin, transformWxssToCss } from '../css/wxss'\nimport { createWebAssetMiddleware, emitWebAssets } from './assets'\nimport { AUTO_ROUTES_ID, ENTRY_ID, RESOLVED_AUTO_ROUTES_ID, SCRIPT_EXTS, SFC_STYLE_QUERY, SFC_TEMPLATE_QUERY, STYLE_EXTS, STYLE_QUERY, TEMPLATE_EXTS, TEMPLATE_QUERY, TRANSFORM_STYLE_EXTS, WEB_COMPONENT_PREFIX, WEB_COMPONENT_QUERY, WXS_EXTS } from './constants'\nimport { collectExternalComponentOptimizeDeps } from './dependencyScan'\nimport { generateAutoRoutesModule, generateEntryModule } from './entry'\nimport { wrapPageTemplate } from './layout'\nimport { cleanUrl, isHtmlEntry, isInsideDir, normalizePath, resolveFileWithExtensionsSync, resolveRuntimePolyfillPath, resolveTemplatePathSync, resolveWxsPathSync, toRelativeImport, toViteFsImport } from './path'\nimport { transformScriptModule } from './register'\nimport { getStableWebComponentId, scanProject } from './scan'\nimport { createEmptyScanState } from './state'\nimport { createInlineStyleModule } from './styleModule'\nimport { ensureWebVueSfcResult, generateWebVueSfcStyle, generateWebVueSfcTemplate, resolveWebVueSfcStyleLanguage, transformWebVueSfcScript } from './vueSfc'\n\ninterface WebPluginContext {\n warn?: (message: string) => void\n addWatchFile?: (id: string) => void\n emitFile?: (asset: { type: 'asset', fileName: string, source: Uint8Array }) => void\n resolve?: (source: string, importer?: string, options?: { skipSelf?: boolean }) => Promise<{ id: string } | null>\n}\n\ntype WebTransformResult = { code: string, map: SourceMap | null } | null\n\ninterface WebPostcssConfig {\n plugins?: Array<{ postcssPlugin?: string }>\n [key: string]: unknown\n}\n\ninterface WebCssConfig {\n postcss?: string | WebPostcssConfig\n}\n\ninterface WebUserConfig {\n css?: {\n postcss?: string | WebPostcssConfig\n }\n}\n\ninterface WebResolvedConfig extends WebUserConfig {\n root: string\n command: string\n createResolver?: () => ResolveWebModuleId\n optimizeDeps?: {\n exclude?: string[]\n include?: string[]\n }\n}\n\ninterface WebHmrContext {\n file: string\n}\n\ninterface WebDevServer {\n middlewares: {\n use: (middleware: ReturnType<typeof createWebAssetMiddleware>) => void\n }\n}\n\ninterface WeappWebVitePlugin {\n name: string\n enforce?: 'pre' | 'post'\n config?: (this: WebPluginContext, config: WebUserConfig) => WebUserConfig | void\n configResolved?: (this: WebPluginContext, config: WebResolvedConfig) => void | Promise<void>\n configureServer?: (server: WebDevServer) => void\n buildStart?: (this: WebPluginContext) => void | Promise<void>\n resolveId?: (id: string, importer?: string) => string | null | Promise<string | null>\n load?: (id: string) => string | null | Promise<string | null>\n handleHotUpdate?: (this: WebPluginContext, ctx: WebHmrContext) => void | Promise<void>\n transform?: (\n this: WebPluginContext,\n code: string,\n id: string,\n ) => WebTransformResult | Promise<WebTransformResult>\n}\n\nfunction isTemplateFile(id: string) {\n const lower = id.toLowerCase()\n return TEMPLATE_EXTS.some(ext => lower.endsWith(ext))\n}\n\nfunction isWxsFile(id: string) {\n const lower = id.toLowerCase()\n return WXS_EXTS.some(ext => lower.endsWith(ext))\n}\n\nfunction hasWxsQuery(id: string) {\n return id.includes('?wxs') || id.includes('&wxs')\n}\n\nfunction hasQuery(id: string, query: string) {\n return id.includes(`?${query}`) || id.includes(`&${query}`)\n}\n\nfunction isUniAppDependency(id: string, includes: readonly string[]) {\n return includes.some(packageName => id === packageName || id.startsWith(`${packageName}/`))\n}\n\nfunction resolveSfcStyleSourceFilename(id: string) {\n const filename = cleanUrl(id)\n const vueSuffixIndex = filename.lastIndexOf('.vue.')\n return vueSuffixIndex >= 0\n ? filename.slice(0, vueSuffixIndex + '.vue'.length)\n : filename\n}\n\nfunction createWebCssConfig(\n config: WebUserConfig,\n wxssOptions: WeappWebPluginOptions['wxss'],\n warn?: (message: string) => void,\n): WebCssConfig | undefined {\n const postcssConfig = config.css?.postcss\n if (typeof postcssConfig === 'string') {\n warn?.('[@weapp-vite/web] css.postcss 使用配置文件路径时无法注入 WXSS 转换插件。')\n return undefined\n }\n\n const plugins = postcssConfig?.plugins ?? []\n if (plugins.some(plugin => plugin.postcssPlugin === 'weapp-vite-web-wxss')) {\n return undefined\n }\n\n return {\n postcss: {\n ...postcssConfig,\n plugins: [...plugins, createWxssPostcssPlugin(wxssOptions)],\n },\n }\n}\n\nexport function weappWebPlugin(options: WeappWebPluginOptions = {}): WeappWebVitePlugin {\n let root = process.cwd()\n let srcRoot = resolve(root, options.srcDir ?? 'src')\n let enableHmr = false\n let resolveWebModuleId: ResolveWebModuleId | undefined\n let resolveWebAutoImportTag: ResolveWebAutoImportTag | undefined\n const componentImportIdMap = new Map<string, string>()\n\n const state = createEmptyScanState()\n const wxssOptions = options.wxss\n const runtimeProvider = options.__runtimeProvider\n const hmrAcceptCode = runtimeProvider\n ? runtimeProvider.hmrAcceptCode\n : 'if (import.meta.hot) { import.meta.hot.accept() }'\n\n const resolveTemplatePath = (raw: string, importer: string) => resolveTemplatePathSync(raw, importer, srcRoot)\n const resolveWxsPath = (raw: string, importer: string) => resolveWxsPathSync(raw, importer, srcRoot)\n const resolveMetaByTemplate = (filename: string) => {\n const normalized = normalizePath(filename)\n for (const meta of state.moduleMeta.values()) {\n if (meta.templatePath && normalizePath(meta.templatePath) === normalized) {\n return meta\n }\n }\n return undefined\n }\n\n const createAutoImportTagResolver = (): ResolveWebAutoImportTag | undefined => {\n const resolvers = options.__autoImportResolvers\n if (!resolvers?.length) {\n return undefined\n }\n return async (tag, importer) => {\n for (const resolver of resolvers) {\n let matched: WebResolvedComponent | void\n if (typeof resolver === 'function') {\n matched = resolver(tag, importer)\n }\n else if (typeof resolver.resolve === 'function') {\n matched = resolver.resolve(tag, importer)\n }\n else {\n const from = resolver.components?.[tag]\n matched = from ? { name: tag, from } : undefined\n }\n if (!matched) {\n continue\n }\n const request = matched.resolvedId ?? matched.from\n const resolvedId = await resolveWebModuleId?.(request, importer)\n return {\n ...matched,\n resolvedId: resolvedId ?? matched.resolvedId,\n sourceType: matched.sourceType ?? (resolvedId?.endsWith('.vue') ? 'wevu-sfc' : 'native'),\n }\n }\n return undefined\n }\n }\n\n const scan = async (context: WebPluginContext) => {\n await scanProject({\n srcRoot,\n warn: context.warn?.bind(context),\n state,\n resolveId: resolveWebModuleId,\n resolveAutoImportTag: resolveWebAutoImportTag,\n resolveAppConfig: options.__resolveAppConfig,\n uniApp: options.__uniApp,\n })\n componentImportIdMap.clear()\n for (const component of state.scanResult.components) {\n if (component.importId) {\n componentImportIdMap.set(component.importId, component.script)\n }\n }\n }\n\n return {\n name: '@weapp-vite/web',\n enforce: 'pre',\n config(this: WebPluginContext, config: WebUserConfig) {\n const css = createWebCssConfig(config, wxssOptions, this.warn?.bind(this))\n return css ? { css } : undefined\n },\n async configResolved(this: WebPluginContext, config: WebResolvedConfig) {\n root = config.root\n srcRoot = resolve(root, options.srcDir ?? 'src')\n enableHmr = config.command === 'serve'\n resolveWebModuleId = config.createResolver?.()\n resolveWebAutoImportTag = createAutoImportTagResolver()\n await scan(this)\n const componentDependencies = await collectExternalComponentOptimizeDeps(state.scanResult.components)\n const uniAppIncludes = options.__uniApp?.include ?? []\n config.optimizeDeps ??= {}\n config.optimizeDeps.exclude = Array.from(new Set([\n ...(config.optimizeDeps.exclude ?? []),\n ...uniAppIncludes,\n ]))\n config.optimizeDeps.include = Array.from(new Set([\n ...(config.optimizeDeps.include ?? []),\n ...componentDependencies,\n ])).filter(dependency => !isUniAppDependency(dependency, uniAppIncludes))\n },\n configureServer(server: WebDevServer) {\n server.middlewares.use(createWebAssetMiddleware(srcRoot))\n },\n async buildStart(this: WebPluginContext) {\n if (!resolveWebModuleId && this.resolve) {\n resolveWebModuleId = async (source, importer) => {\n const resolved = await this.resolve?.(source, importer, { skipSelf: true })\n return resolved?.id\n }\n }\n resolveWebAutoImportTag = createAutoImportTagResolver()\n await scan(this)\n if (!enableHmr) {\n await emitWebAssets(this, srcRoot)\n }\n },\n resolveId(id: string, importer?: string) {\n if (id === '/@weapp-vite/web/entry' || id === '@weapp-vite/web/entry') {\n return ENTRY_ID\n }\n if (id === AUTO_ROUTES_ID) {\n return RESOLVED_AUTO_ROUTES_ID\n }\n if (id.startsWith(WEB_COMPONENT_PREFIX)) {\n const request = decodeURIComponent(id.slice(WEB_COMPONENT_PREFIX.length))\n const resolvedId = componentImportIdMap.get(request)\n return resolvedId ? `${cleanUrl(resolvedId)}?${WEB_COMPONENT_QUERY}` : null\n }\n if (id.startsWith('.') && importer && cleanUrl(importer).endsWith('.vue') && !extname(id)) {\n const resolvedScript = resolveFileWithExtensionsSync(resolve(dirname(cleanUrl(importer)), id), SCRIPT_EXTS)\n if (resolvedScript?.endsWith('.vue')) {\n return resolvedScript\n }\n }\n if (hasQuery(id, SFC_STYLE_QUERY)) {\n const queryIndex = id.indexOf('?')\n const pathname = queryIndex >= 0 ? id.slice(0, queryIndex) : id\n const query = queryIndex >= 0 ? id.slice(queryIndex) : ''\n if (pathname.startsWith('.') && importer) {\n return `${resolve(dirname(cleanUrl(importer)), pathname)}${query}`\n }\n return id\n }\n return null\n },\n async load(this: WebPluginContext, id: string) {\n if (id === ENTRY_ID) {\n return generateEntryModule(state.scanResult, root, wxssOptions, options)\n }\n if (id === RESOLVED_AUTO_ROUTES_ID) {\n return generateAutoRoutesModule(state.scanResult)\n }\n if (hasQuery(id, TEMPLATE_QUERY)) {\n const filename = cleanUrl(id)\n let source = await readFile(filename, 'utf8')\n const pageMeta = resolveMetaByTemplate(filename)\n if (pageMeta?.kind === 'page' && state.scanResult.layouts.length) {\n source = wrapPageTemplate(source, state.scanResult.layouts)\n }\n const navigationConfig = state.pageNavigationMap.get(normalizePath(filename))\n const componentTags = state.templateComponentMap.get(normalizePath(filename))\n const compiled = compileWxml({\n id: filename,\n source,\n resolveTemplatePath,\n resolveWxsPath,\n navigationBar: navigationConfig ? { config: navigationConfig } : undefined,\n componentTags,\n })\n for (const dependency of compiled.dependencies) {\n this.addWatchFile?.(dependency)\n }\n for (const warning of compiled.warnings ?? []) {\n this.warn?.(warning)\n }\n return compiled.code\n }\n if (hasWxsQuery(id)) {\n const filename = cleanUrl(id)\n const source = await readFile(filename, 'utf8')\n const compiled = transformWxsToEsm(source, filename, {\n resolvePath: resolveWxsPath,\n toImportPath: (resolved, importer) => normalizePath(toRelativeImport(importer, resolved)),\n })\n for (const dependency of compiled.dependencies) {\n this.addWatchFile?.(dependency)\n }\n for (const warning of compiled.warnings ?? []) {\n this.warn?.(warning)\n }\n return compiled.code\n }\n if (hasQuery(id, STYLE_QUERY)) {\n const source = await readFile(cleanUrl(id), 'utf8')\n const { css } = transformWxssToCss(source, wxssOptions)\n return createInlineStyleModule(css)\n }\n if (id.includes(`?${SFC_TEMPLATE_QUERY}`) || id.includes(`&${SFC_TEMPLATE_QUERY}`)) {\n const filename = cleanUrl(id)\n const meta = state.moduleMeta.get(normalizePath(filename))\n if (!meta) {\n return null\n }\n const result = await ensureWebVueSfcResult({\n filename,\n meta,\n srcRoot,\n state,\n resolveId: resolveWebModuleId,\n resolveAutoImportTag: resolveWebAutoImportTag,\n uniApp: options.__uniApp,\n })\n const compiled = generateWebVueSfcTemplate(result, meta, filename, srcRoot)\n for (const dependency of compiled.dependencies) {\n this.addWatchFile?.(dependency)\n }\n for (const warning of compiled.warnings ?? []) {\n this.warn?.(warning)\n }\n return compiled.code\n }\n if (id.includes(`?${SFC_STYLE_QUERY}`) || id.includes(`&${SFC_STYLE_QUERY}`)) {\n const filename = resolveSfcStyleSourceFilename(id)\n const meta = state.moduleMeta.get(normalizePath(filename))\n if (!meta) {\n return null\n }\n const result = await ensureWebVueSfcResult({\n filename,\n meta,\n srcRoot,\n state,\n resolveId: resolveWebModuleId,\n resolveAutoImportTag: resolveWebAutoImportTag,\n uniApp: options.__uniApp,\n })\n return generateWebVueSfcStyle(result)\n }\n return null\n },\n async handleHotUpdate(this: WebPluginContext, ctx: WebHmrContext) {\n const clean = cleanUrl(ctx.file)\n if (clean.endsWith('.json') || isTemplateFile(clean) || isWxsFile(clean) || clean.endsWith('.wxss') || SCRIPT_EXTS.includes(extname(clean))) {\n await scan(this)\n }\n },\n async transform(this: WebPluginContext, code: string, id: string) {\n const clean = cleanUrl(id)\n let uniAppTransformed = false\n\n if (\n options.__uniApp\n && isUniAppCompatibilityFile(clean, srcRoot, options.__uniApp.include)\n && !clean.endsWith('.vue')\n ) {\n const transformed = transformUniAppSource(code, { filename: clean, target: 'h5' })\n if (transformed.changed) {\n code = transformed.code\n uniAppTransformed = true\n }\n }\n\n if (\n hasQuery(id, TEMPLATE_QUERY)\n || hasWxsQuery(id)\n || hasQuery(id, STYLE_QUERY)\n || hasQuery(id, SFC_TEMPLATE_QUERY)\n || hasQuery(id, SFC_STYLE_QUERY)\n ) {\n return null\n }\n\n if (clean.endsWith('.vue')) {\n const normalized = normalizePath(clean)\n const meta = state.moduleMeta.get(normalized) ?? {\n kind: 'component' as const,\n id: getStableWebComponentId(clean, srcRoot),\n scriptPath: clean,\n sourceType: 'vue-sfc' as const,\n }\n state.moduleMeta.set(normalized, meta)\n const result = await ensureWebVueSfcResult({\n filename: clean,\n meta,\n srcRoot,\n state,\n source: code,\n resolveId: resolveWebModuleId,\n resolveAutoImportTag: resolveWebAutoImportTag,\n uniApp: options.__uniApp,\n })\n return transformWebVueSfcScript({\n code: result.script!,\n filename: clean,\n meta,\n runtimeModuleId: runtimeProvider?.moduleId ?? toViteFsImport(resolveRuntimePolyfillPath()),\n styleLanguage: resolveWebVueSfcStyleLanguage(result, clean),\n enableHmr,\n hmrAcceptCode,\n })\n }\n\n if (isTemplateFile(clean)) {\n if (isHtmlEntry(clean, root)) {\n return null\n }\n const normalizedId = normalizePath(clean)\n if (state.templatePathSet.size > 0) {\n if (!isInsideDir(clean, srcRoot)) {\n return null\n }\n if (!state.templatePathSet.has(normalizedId)) {\n return null\n }\n }\n let templateSource = code\n const pageMeta = resolveMetaByTemplate(clean)\n if (pageMeta?.kind === 'page' && state.scanResult.layouts.length) {\n templateSource = wrapPageTemplate(code, state.scanResult.layouts)\n }\n const navigationConfig = state.pageNavigationMap.get(normalizedId)\n const componentTags = state.templateComponentMap.get(normalizedId)\n const { code: compiled, dependencies, warnings } = compileWxml({\n id: clean,\n source: templateSource,\n resolveTemplatePath,\n resolveWxsPath,\n navigationBar: navigationConfig ? { config: navigationConfig } : undefined,\n componentTags,\n })\n const addWatchFile = this.addWatchFile\n if (dependencies.length > 0 && addWatchFile) {\n for (const dep of dependencies) {\n addWatchFile.call(this, dep)\n }\n }\n const warn = this.warn\n if (warnings?.length && warn) {\n for (const warning of warnings) {\n warn.call(this, warning)\n }\n }\n return { code: compiled, map: null }\n }\n\n if (isWxsFile(clean) || hasWxsQuery(id)) {\n const { code: compiled, dependencies, warnings } = transformWxsToEsm(code, clean, {\n resolvePath: resolveWxsPath,\n toImportPath: (resolved, importer) => normalizePath(toRelativeImport(importer, resolved)),\n })\n const addWatchFile = this.addWatchFile\n if (dependencies.length > 0 && addWatchFile) {\n for (const dep of dependencies) {\n addWatchFile.call(this, dep)\n }\n }\n const warn = this.warn\n if (warnings?.length && warn) {\n for (const warning of warnings) {\n warn.call(this, warning)\n }\n }\n return { code: compiled, map: null }\n }\n\n if (TRANSFORM_STYLE_EXTS.some(ext => clean.endsWith(ext))) {\n const { css } = transformWxssToCss(code, wxssOptions)\n return {\n code: createInlineStyleModule(css),\n map: null,\n }\n }\n\n if (STYLE_EXTS.some(ext => clean.endsWith(ext)) && !clean.endsWith('.wxss')) {\n const { css } = transformWxssToCss(code, wxssOptions)\n return { code: css, map: null }\n }\n\n if (!SCRIPT_EXTS.some(ext => clean.endsWith(ext))) {\n return uniAppTransformed ? { code, map: null } : null\n }\n if (clean.includes('node_modules') && !hasQuery(id, WEB_COMPONENT_QUERY)) {\n return options.__uniApp && isUniAppCompatibilityFile(clean, srcRoot, options.__uniApp.include)\n ? { code, map: null }\n : null\n }\n\n const meta = state.moduleMeta.get(normalizePath(clean))\n if (!meta) {\n return null\n }\n\n return transformScriptModule({\n code,\n cleanId: clean,\n meta,\n enableHmr,\n runtimeModuleId: runtimeProvider?.moduleId,\n hmrAcceptCode,\n })\n },\n }\n}\n\nexport type { WeappWebPluginOptions } from './types'\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAmFA,SAAS,eAAe,IAAY;CAClC,MAAM,QAAQ,GAAG,YAAY;CAC7B,OAAO,cAAc,MAAK,QAAO,MAAM,SAAS,GAAG,CAAC;AACtD;AAEA,SAAS,UAAU,IAAY;CAC7B,MAAM,QAAQ,GAAG,YAAY;CAC7B,OAAO,SAAS,MAAK,QAAO,MAAM,SAAS,GAAG,CAAC;AACjD;AAEA,SAAS,YAAY,IAAY;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K,MAAM,OAAO,cAChB,aAAa,KAAK,MAAM,GAAG;IAG/B,MAAM,OAAO,KAAK;IAClB,IAAI,UAAU,UAAU,MACtB,KAAK,MAAM,WAAW,UACpB,KAAK,KAAK,MAAM,OAAO;IAG3B,OAAO;KAAE,MAAM;KAAU,KAAK;IAAK;GACrC;GAEA,IAAI,qBAAqB,MAAK,QAAO,MAAM,SAAS,GAAG,CAAC,GAAG;IACzD,MAAM,EAAE,QAAQ,mBAAmB,MAAM,WAAW;IACpD,OAAO;KACL,MAAM,wBAAwB,GAAG;KACjC,KAAK;IACP;GACF;GAEA,IAAI,WAAW,MAAK,QAAO,MAAM,SAAS,GAAG,CAAC,KAAK,CAAC,MAAM,SAAS,OAAO,GAAG;IAC3E,MAAM,EAAE,QAAQ,mBAAmB,MAAM,WAAW;IACpD,OAAO;KAAE,MAAM;KAAK,KAAK;IAAK;GAChC;GAEA,IAAI,CAAC,YAAY,MAAK,QAAO,MAAM,SAAS,GAAG,CAAC,GAC9C,OAAO,oBAAoB;IAAE;IAAM,KAAK;GAAK,IAAI;GAEnD,IAAI,MAAM,SAAS,cAAc,KAAK,CAAC,SAAS,yBAAuB,GACrE,OAAO,QAAQ,YAAY,0BAA0B,OAAO,SAAS,QAAQ,SAAS,OAAO,IACzF;IAAE;IAAM,KAAK;GAAK,IAClB;GAGN,MAAM,OAAO,MAAM,WAAW,IAAI,cAAc,KAAK,CAAC;GACtD,IAAI,CAAC,MACH,OAAO;GAGT,OAAO,sBAAsB;IAC3B;IACA,SAAS;IACT;IACA;IACA,iBAAiB,iBAAiB;IAClC;GACF,CAAC;EACH;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/plugin/index.ts"],"sourcesContent":["import type { SourceMap } from 'magic-string'\nimport type { ResolveWebAutoImportTag, ResolveWebModuleId, WeappWebPluginOptions, WebResolvedComponent } from './types'\nimport { readFile } from 'node:fs/promises'\nimport process from 'node:process'\n\nimport { dirname, extname, resolve } from 'pathe'\nimport { isUniAppCompatibilityFile, transformUniAppSource } from 'wevu/compiler'\nimport { compileWxml } from '../compiler/wxml'\nimport { transformWxsToEsm } from '../compiler/wxs'\nimport { createWxssPostcssPlugin, transformWxssToCss } from '../css/wxss'\nimport { createWebAssetMiddleware, emitWebAssets } from './assets'\nimport { AUTO_ROUTES_ID, ENTRY_ID, RESOLVED_AUTO_ROUTES_ID, SCRIPT_EXTS, SFC_STYLE_QUERY, SFC_TEMPLATE_QUERY, STYLE_EXTS, STYLE_QUERY, TEMPLATE_EXTS, TEMPLATE_QUERY, TRANSFORM_STYLE_EXTS, WEB_COMPONENT_PREFIX, WEB_COMPONENT_QUERY, WXS_EXTS } from './constants'\nimport { collectExternalComponentOptimizeDeps } from './dependencyScan'\nimport { generateAutoRoutesModule, generateEntryModule } from './entry'\nimport { wrapPageTemplate } from './layout'\nimport { cleanUrl, isHtmlEntry, isInsideDir, normalizePath, resolveFileWithExtensionsSync, resolveRuntimePolyfillPath, resolveTemplatePathSync, resolveWxsPathSync, toRelativeImport, toViteFsImport } from './path'\nimport { transformScriptModule } from './register'\nimport { getStableWebComponentId, scanProject } from './scan'\nimport { createEmptyScanState } from './state'\nimport { createInlineStyleModule } from './styleModule'\nimport { ensureWebVueSfcResult, generateWebVueSfcStyle, generateWebVueSfcTemplate, resolveWebVueSfcStyleLanguage, transformWebVueSfcScript } from './vueSfc'\n\ninterface WebPluginContext {\n warn?: (message: string) => void\n addWatchFile?: (id: string) => void\n emitFile?: (asset: { type: 'asset', fileName: string, source: Uint8Array }) => void\n resolve?: (source: string, importer?: string, options?: { skipSelf?: boolean }) => Promise<{ id: string } | null>\n}\n\ntype WebTransformResult = { code: string, map: SourceMap | null } | null\n\ninterface WebPostcssConfig {\n plugins?: Array<{ postcssPlugin?: string }>\n [key: string]: unknown\n}\n\ninterface WebCssConfig {\n postcss?: string | WebPostcssConfig\n}\n\ninterface WebUserConfig {\n css?: {\n postcss?: string | WebPostcssConfig\n }\n}\n\ninterface WebResolvedConfig extends WebUserConfig {\n root: string\n command: string\n createResolver?: () => ResolveWebModuleId\n optimizeDeps?: {\n exclude?: string[]\n include?: string[]\n }\n}\n\ninterface WebHmrContext {\n file: string\n}\n\ninterface WebDevServer {\n middlewares: {\n use: (middleware: ReturnType<typeof createWebAssetMiddleware>) => void\n }\n}\n\ninterface WeappWebVitePlugin {\n name: string\n enforce?: 'pre' | 'post'\n config?: (this: WebPluginContext, config: WebUserConfig) => WebUserConfig | void\n configResolved?: (this: WebPluginContext, config: WebResolvedConfig) => void | Promise<void>\n configureServer?: (server: WebDevServer) => void\n buildStart?: (this: WebPluginContext) => void | Promise<void>\n resolveId?: (id: string, importer?: string) => string | null | Promise<string | null>\n load?: (id: string) => string | null | Promise<string | null>\n handleHotUpdate?: (this: WebPluginContext, ctx: WebHmrContext) => void | Promise<void>\n transform?: (\n this: WebPluginContext,\n code: string,\n id: string,\n ) => WebTransformResult | Promise<WebTransformResult>\n}\n\nfunction isTemplateFile(id: string) {\n const lower = id.toLowerCase()\n return TEMPLATE_EXTS.some(ext => lower.endsWith(ext))\n}\n\nfunction isWxsFile(id: string) {\n const lower = id.toLowerCase()\n return WXS_EXTS.some(ext => lower.endsWith(ext))\n}\n\nfunction hasWxsQuery(id: string) {\n return id.includes('?wxs') || id.includes('&wxs')\n}\n\nfunction hasQuery(id: string, query: string) {\n return id.includes(`?${query}`) || id.includes(`&${query}`)\n}\n\nfunction isUniAppDependency(id: string, includes: readonly string[]) {\n return includes.some(packageName => id === packageName || id.startsWith(`${packageName}/`))\n}\n\nfunction resolveSfcStyleSourceFilename(id: string) {\n const filename = cleanUrl(id)\n const vueSuffixIndex = filename.lastIndexOf('.vue.')\n return vueSuffixIndex >= 0\n ? filename.slice(0, vueSuffixIndex + '.vue'.length)\n : filename\n}\n\nfunction createWebCssConfig(\n config: WebUserConfig,\n wxssOptions: WeappWebPluginOptions['wxss'],\n warn?: (message: string) => void,\n): WebCssConfig | undefined {\n const postcssConfig = config.css?.postcss\n if (typeof postcssConfig === 'string') {\n warn?.('[@weapp-vite/web] css.postcss 使用配置文件路径时无法注入 WXSS 转换插件。')\n return undefined\n }\n\n const plugins = postcssConfig?.plugins ?? []\n if (plugins.some(plugin => plugin.postcssPlugin === 'weapp-vite-web-wxss')) {\n return undefined\n }\n\n return {\n postcss: {\n ...postcssConfig,\n plugins: [...plugins, createWxssPostcssPlugin(wxssOptions)],\n },\n }\n}\n\nexport function weappWebPlugin(options: WeappWebPluginOptions = {}): WeappWebVitePlugin {\n let root = process.cwd()\n let srcRoot = resolve(root, options.srcDir ?? 'src')\n let enableHmr = false\n let resolveWebModuleId: ResolveWebModuleId | undefined\n let resolveWebAutoImportTag: ResolveWebAutoImportTag | undefined\n const componentImportIdMap = new Map<string, string>()\n\n const state = createEmptyScanState()\n const wxssOptions = options.wxss\n const runtimeProvider = options.__runtimeProvider\n const hmrAcceptCode = runtimeProvider\n ? runtimeProvider.hmrAcceptCode\n : 'if (import.meta.hot) { import.meta.hot.accept() }'\n\n const resolveTemplatePath = (raw: string, importer: string) => resolveTemplatePathSync(raw, importer, srcRoot)\n const resolveWxsPath = (raw: string, importer: string) => resolveWxsPathSync(raw, importer, srcRoot)\n const resolveMetaByTemplate = (filename: string) => {\n const normalized = normalizePath(filename)\n for (const meta of state.moduleMeta.values()) {\n if (meta.templatePath && normalizePath(meta.templatePath) === normalized) {\n return meta\n }\n }\n return undefined\n }\n\n const createAutoImportTagResolver = (): ResolveWebAutoImportTag | undefined => {\n const resolvers = options.__autoImportResolvers\n if (!resolvers?.length) {\n return undefined\n }\n return async (tag, importer) => {\n for (const resolver of resolvers) {\n let matched: WebResolvedComponent | void\n if (typeof resolver === 'function') {\n matched = resolver(tag, importer)\n }\n else if (typeof resolver.resolve === 'function') {\n matched = resolver.resolve(tag, importer)\n }\n else {\n const from = resolver.components?.[tag]\n matched = from ? { name: tag, from } : undefined\n }\n if (!matched) {\n continue\n }\n const request = matched.resolvedId ?? matched.from\n const resolvedId = await resolveWebModuleId?.(request, importer)\n return {\n ...matched,\n resolvedId: resolvedId ?? matched.resolvedId,\n sourceType: matched.sourceType ?? (resolvedId?.endsWith('.vue') ? 'wevu-sfc' : 'native'),\n }\n }\n return undefined\n }\n }\n\n const scan = async (context: WebPluginContext) => {\n await scanProject({\n srcRoot,\n warn: context.warn?.bind(context),\n state,\n resolveId: resolveWebModuleId,\n resolveAutoImportTag: resolveWebAutoImportTag,\n resolveAppConfig: options.__resolveAppConfig,\n uniApp: options.__uniApp,\n })\n componentImportIdMap.clear()\n for (const component of state.scanResult.components) {\n if (component.importId) {\n componentImportIdMap.set(component.importId, component.script)\n }\n }\n }\n\n return {\n name: '@weapp-vite/web',\n enforce: 'pre',\n config(this: WebPluginContext, config: WebUserConfig) {\n const css = createWebCssConfig(config, wxssOptions, this.warn?.bind(this))\n return css ? { css } : undefined\n },\n async configResolved(this: WebPluginContext, config: WebResolvedConfig) {\n root = config.root\n srcRoot = resolve(root, options.srcDir ?? 'src')\n enableHmr = config.command === 'serve'\n resolveWebModuleId = config.createResolver?.()\n resolveWebAutoImportTag = createAutoImportTagResolver()\n await scan(this)\n const componentDependencies = await collectExternalComponentOptimizeDeps(state.scanResult.components)\n const uniAppIncludes = options.__uniApp?.include ?? []\n config.optimizeDeps ??= {}\n config.optimizeDeps.exclude = Array.from(new Set([\n ...(config.optimizeDeps.exclude ?? []),\n ...uniAppIncludes,\n ]))\n config.optimizeDeps.include = Array.from(new Set([\n ...(config.optimizeDeps.include ?? []),\n ...componentDependencies,\n ])).filter(dependency => !isUniAppDependency(dependency, uniAppIncludes))\n },\n configureServer(server: WebDevServer) {\n server.middlewares.use(createWebAssetMiddleware(srcRoot))\n },\n async buildStart(this: WebPluginContext) {\n if (!resolveWebModuleId && this.resolve) {\n resolveWebModuleId = async (source, importer) => {\n const resolved = await this.resolve?.(source, importer, { skipSelf: true })\n return resolved?.id\n }\n }\n resolveWebAutoImportTag = createAutoImportTagResolver()\n await scan(this)\n if (!enableHmr) {\n await emitWebAssets(this, srcRoot)\n }\n },\n resolveId(id: string, importer?: string) {\n if (id === '/@weapp-vite/web/entry' || id === '@weapp-vite/web/entry') {\n return ENTRY_ID\n }\n if (id === AUTO_ROUTES_ID) {\n return RESOLVED_AUTO_ROUTES_ID\n }\n if (id.startsWith(WEB_COMPONENT_PREFIX)) {\n const request = decodeURIComponent(id.slice(WEB_COMPONENT_PREFIX.length))\n const resolvedId = componentImportIdMap.get(request)\n return resolvedId ? `${cleanUrl(resolvedId)}?${WEB_COMPONENT_QUERY}` : null\n }\n if (id.startsWith('.') && importer && cleanUrl(importer).endsWith('.vue') && !extname(id)) {\n const resolvedScript = resolveFileWithExtensionsSync(resolve(dirname(cleanUrl(importer)), id), SCRIPT_EXTS)\n if (resolvedScript?.endsWith('.vue')) {\n return resolvedScript\n }\n }\n if (hasQuery(id, SFC_STYLE_QUERY)) {\n const queryIndex = id.indexOf('?')\n const pathname = queryIndex >= 0 ? id.slice(0, queryIndex) : id\n const query = queryIndex >= 0 ? id.slice(queryIndex) : ''\n if (pathname.startsWith('.') && importer) {\n return `${resolve(dirname(cleanUrl(importer)), pathname)}${query}`\n }\n return id\n }\n return null\n },\n async load(this: WebPluginContext, id: string) {\n if (id === ENTRY_ID) {\n return generateEntryModule(state.scanResult, root, wxssOptions, options)\n }\n if (id === RESOLVED_AUTO_ROUTES_ID) {\n return generateAutoRoutesModule(state.scanResult)\n }\n if (hasQuery(id, TEMPLATE_QUERY)) {\n const filename = cleanUrl(id)\n let source = await readFile(filename, 'utf8')\n const pageMeta = resolveMetaByTemplate(filename)\n if (pageMeta?.kind === 'page' && state.scanResult.layouts.length) {\n source = wrapPageTemplate(source, state.scanResult.layouts)\n }\n const navigationConfig = state.pageNavigationMap.get(normalizePath(filename))\n const componentTags = state.templateComponentMap.get(normalizePath(filename))\n const compiled = compileWxml({\n id: filename,\n source,\n resolveTemplatePath,\n resolveWxsPath,\n navigationBar: navigationConfig ? { config: navigationConfig } : undefined,\n componentTags,\n })\n for (const dependency of compiled.dependencies) {\n this.addWatchFile?.(dependency)\n }\n for (const warning of compiled.warnings ?? []) {\n this.warn?.(warning)\n }\n return compiled.code\n }\n if (hasWxsQuery(id)) {\n const filename = cleanUrl(id)\n const source = await readFile(filename, 'utf8')\n const compiled = transformWxsToEsm(source, filename, {\n resolvePath: resolveWxsPath,\n toImportPath: (resolved, importer) => normalizePath(toRelativeImport(importer, resolved)),\n })\n for (const dependency of compiled.dependencies) {\n this.addWatchFile?.(dependency)\n }\n for (const warning of compiled.warnings ?? []) {\n this.warn?.(warning)\n }\n return compiled.code\n }\n if (hasQuery(id, STYLE_QUERY)) {\n const source = await readFile(cleanUrl(id), 'utf8')\n const { css } = transformWxssToCss(source, wxssOptions)\n return createInlineStyleModule(css)\n }\n if (id.includes(`?${SFC_TEMPLATE_QUERY}`) || id.includes(`&${SFC_TEMPLATE_QUERY}`)) {\n const filename = cleanUrl(id)\n const meta = state.moduleMeta.get(normalizePath(filename))\n if (!meta) {\n return null\n }\n const result = await ensureWebVueSfcResult({\n filename,\n meta,\n srcRoot,\n state,\n resolveId: resolveWebModuleId,\n resolveAutoImportTag: resolveWebAutoImportTag,\n uniApp: options.__uniApp,\n })\n const compiled = generateWebVueSfcTemplate(result, meta, filename, srcRoot)\n for (const dependency of compiled.dependencies) {\n this.addWatchFile?.(dependency)\n }\n for (const warning of compiled.warnings ?? []) {\n this.warn?.(warning)\n }\n return compiled.code\n }\n if (id.includes(`?${SFC_STYLE_QUERY}`) || id.includes(`&${SFC_STYLE_QUERY}`)) {\n const filename = resolveSfcStyleSourceFilename(id)\n const meta = state.moduleMeta.get(normalizePath(filename))\n if (!meta) {\n return null\n }\n const result = await ensureWebVueSfcResult({\n filename,\n meta,\n srcRoot,\n state,\n resolveId: resolveWebModuleId,\n resolveAutoImportTag: resolveWebAutoImportTag,\n uniApp: options.__uniApp,\n })\n return generateWebVueSfcStyle(result)\n }\n return null\n },\n async handleHotUpdate(this: WebPluginContext, ctx: WebHmrContext) {\n const clean = cleanUrl(ctx.file)\n if (clean.endsWith('.json') || isTemplateFile(clean) || isWxsFile(clean) || clean.endsWith('.wxss') || SCRIPT_EXTS.includes(extname(clean))) {\n await scan(this)\n }\n },\n async transform(this: WebPluginContext, code: string, id: string) {\n const clean = cleanUrl(id)\n let uniAppTransformed = false\n\n if (\n options.__uniApp\n && isUniAppCompatibilityFile(clean, srcRoot, options.__uniApp.include)\n && !clean.endsWith('.vue')\n ) {\n const transformed = transformUniAppSource(code, { filename: clean, target: 'h5' })\n if (transformed.changed) {\n code = transformed.code\n uniAppTransformed = true\n }\n }\n\n if (\n hasQuery(id, TEMPLATE_QUERY)\n || hasWxsQuery(id)\n || hasQuery(id, STYLE_QUERY)\n || hasQuery(id, SFC_TEMPLATE_QUERY)\n || hasQuery(id, SFC_STYLE_QUERY)\n ) {\n return null\n }\n\n if (clean.endsWith('.vue')) {\n const normalized = normalizePath(clean)\n const meta = state.moduleMeta.get(normalized) ?? {\n kind: 'component' as const,\n id: getStableWebComponentId(clean, srcRoot),\n scriptPath: clean,\n sourceType: 'vue-sfc' as const,\n }\n state.moduleMeta.set(normalized, meta)\n const result = await ensureWebVueSfcResult({\n filename: clean,\n meta,\n srcRoot,\n state,\n source: code,\n resolveId: resolveWebModuleId,\n resolveAutoImportTag: resolveWebAutoImportTag,\n uniApp: options.__uniApp,\n })\n return transformWebVueSfcScript({\n code: result.script!,\n filename: clean,\n meta,\n runtimeModuleId: runtimeProvider?.moduleId ?? toViteFsImport(resolveRuntimePolyfillPath()),\n styleLanguage: resolveWebVueSfcStyleLanguage(result, clean),\n enableHmr,\n hmrAcceptCode,\n })\n }\n\n if (isTemplateFile(clean)) {\n if (isHtmlEntry(clean, root)) {\n return null\n }\n const normalizedId = normalizePath(clean)\n if (state.templatePathSet.size > 0) {\n if (!isInsideDir(clean, srcRoot)) {\n return null\n }\n if (!state.templatePathSet.has(normalizedId)) {\n return null\n }\n }\n let templateSource = code\n const pageMeta = resolveMetaByTemplate(clean)\n if (pageMeta?.kind === 'page' && state.scanResult.layouts.length) {\n templateSource = wrapPageTemplate(code, state.scanResult.layouts)\n }\n const navigationConfig = state.pageNavigationMap.get(normalizedId)\n const componentTags = state.templateComponentMap.get(normalizedId)\n const { code: compiled, dependencies, warnings } = compileWxml({\n id: clean,\n source: templateSource,\n resolveTemplatePath,\n resolveWxsPath,\n navigationBar: navigationConfig ? { config: navigationConfig } : undefined,\n componentTags,\n })\n const addWatchFile = this.addWatchFile\n if (dependencies.length > 0 && addWatchFile) {\n for (const dep of dependencies) {\n addWatchFile.call(this, dep)\n }\n }\n const warn = this.warn\n if (warnings?.length && warn) {\n for (const warning of warnings) {\n warn.call(this, warning)\n }\n }\n return { code: compiled, map: null }\n }\n\n if (isWxsFile(clean) || hasWxsQuery(id)) {\n const { code: compiled, dependencies, warnings } = transformWxsToEsm(code, clean, {\n resolvePath: resolveWxsPath,\n toImportPath: (resolved, importer) => normalizePath(toRelativeImport(importer, resolved)),\n })\n const addWatchFile = this.addWatchFile\n if (dependencies.length > 0 && addWatchFile) {\n for (const dep of dependencies) {\n addWatchFile.call(this, dep)\n }\n }\n const warn = this.warn\n if (warnings?.length && warn) {\n for (const warning of warnings) {\n warn.call(this, warning)\n }\n }\n return { code: compiled, map: null }\n }\n\n if (TRANSFORM_STYLE_EXTS.some(ext => clean.endsWith(ext))) {\n const { css } = transformWxssToCss(code, wxssOptions)\n return {\n code: createInlineStyleModule(css),\n map: null,\n }\n }\n\n if (STYLE_EXTS.some(ext => clean.endsWith(ext)) && !clean.endsWith('.wxss')) {\n const { css } = transformWxssToCss(code, wxssOptions)\n return { code: css, map: null }\n }\n\n if (!SCRIPT_EXTS.some(ext => clean.endsWith(ext))) {\n return uniAppTransformed ? { code, map: null } : null\n }\n if (clean.includes('node_modules') && !hasQuery(id, WEB_COMPONENT_QUERY)) {\n return options.__uniApp && isUniAppCompatibilityFile(clean, srcRoot, options.__uniApp.include)\n ? { code, map: null }\n : null\n }\n\n const meta = state.moduleMeta.get(normalizePath(clean))\n if (!meta) {\n return null\n }\n\n return transformScriptModule({\n code,\n cleanId: clean,\n meta,\n enableHmr,\n runtimeModuleId: runtimeProvider?.moduleId,\n hmrAcceptCode,\n })\n },\n }\n}\n\nexport type { WeappWebPluginOptions } from './types'\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAmFA,SAAS,eAAe,IAAY;CAClC,MAAM,QAAQ,GAAG,YAAY;CAC7B,OAAO,cAAc,MAAK,QAAO,MAAM,SAAS,GAAG,CAAC;AACtD;AAEA,SAAS,UAAU,IAAY;CAC7B,MAAM,QAAQ,GAAG,YAAY;CAC7B,OAAO,SAAS,MAAK,QAAO,MAAM,SAAS,GAAG,CAAC;AACjD;AAEA,SAAS,YAAY,IAAY;CAC/B,OAAO,GAAG,SAAS,MAAM,KAAK,GAAG,SAAS,MAAM;AAClD;AAEA,SAAS,SAAS,IAAY,OAAe;CAC3C,OAAO,GAAG,SAAS,IAAI,OAAO,KAAK,GAAG,SAAS,IAAI,OAAO;AAC5D;AAEA,SAAS,mBAAmB,IAAY,UAA6B;CACnE,OAAO,SAAS,MAAK,gBAAe,OAAO,eAAe,GAAG,WAAW,GAAG,YAAY,EAAE,CAAC;AAC5F;AAEA,SAAS,8BAA8B,IAAY;CACjD,MAAM,WAAW,SAAS,EAAE;CAC5B,MAAM,iBAAiB,SAAS,YAAY,OAAO;CACnD,OAAO,kBAAkB,IACrB,SAAS,MAAM,GAAG,iBAAiB,CAAa,IAChD;AACN;AAEA,SAAS,mBACP,QACA,aACA,MAC0B;CAC1B,MAAM,gBAAgB,OAAO,KAAK;CAClC,IAAI,OAAO,kBAAkB,UAAU;EACrC,OAAO,wDAAwD;EAC/D;CACF;CAEA,MAAM,UAAU,eAAe,WAAW,CAAC;CAC3C,IAAI,QAAQ,MAAK,WAAU,OAAO,kBAAkB,qBAAqB,GACvE;CAGF,OAAO,EACL,SAAS;EACP,GAAG;EACH,SAAS,CAAC,GAAG,SAAS,wBAAwB,WAAW,CAAC;CAC5D,EACF;AACF;AAEA,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yBAAuB,GACrE,OAAO,QAAQ,YAAY,0BAA0B,OAAO,SAAS,QAAQ,SAAS,OAAO,IACzF;IAAE;IAAM,KAAK;GAAK,IAClB;GAGN,MAAM,OAAO,MAAM,WAAW,IAAI,cAAc,KAAK,CAAC;GACtD,IAAI,CAAC,MACH,OAAO;GAGT,OAAO,sBAAsB;IAC3B;IACA,SAAS;IACT;IACA;IACA,iBAAiB,iBAAiB;IAClC;GACF,CAAC;EACH;CACF;AACF"}
|
package/dist/plugin/path.mjs
CHANGED
|
@@ -24,7 +24,8 @@ function toPosixId(id) {
|
|
|
24
24
|
return normalize(id).split("\\").join("/");
|
|
25
25
|
}
|
|
26
26
|
function toRelativeImport(from, target) {
|
|
27
|
-
const
|
|
27
|
+
const fromDir = dirname(from);
|
|
28
|
+
const rel = relative(fromDir, target);
|
|
28
29
|
if (!rel || rel.startsWith(".")) return normalizePath(rel || `./${posix.basename(target)}`);
|
|
29
30
|
return `./${normalizePath(rel)}`;
|
|
30
31
|
}
|
package/dist/plugin/path.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"path.mjs","names":[],"sources":["../../src/plugin/path.ts"],"sourcesContent":["import { existsSync } from 'node:fs'\nimport { fileURLToPath } from 'node:url'\nimport { dirname, extname, normalize, posix, relative, resolve } from 'pathe'\n\nimport { TEMPLATE_EXTS, WXS_RESOLVE_EXTS } from './constants'\n\nexport function cleanUrl(url: string) {\n const queryIndex = url.indexOf('?')\n if (queryIndex >= 0) {\n return url.slice(0, queryIndex)\n }\n return url\n}\n\nexport function normalizePath(p: string) {\n return posix.normalize(p.split('\\\\').join('/'))\n}\n\nexport function isInsideDir(filePath: string, dir: string) {\n const rel = relative(dir, filePath)\n return rel === '' || (!rel.startsWith('..') && !posix.isAbsolute(rel))\n}\n\nexport function isHtmlEntry(filePath: string, root: string) {\n if (!filePath.toLowerCase().endsWith('.html')) {\n return false\n }\n return normalizePath(filePath) === normalizePath(resolve(root, 'index.html'))\n}\n\nexport function toPosixId(id: string) {\n return normalize(id).split('\\\\').join('/')\n}\n\nexport function toRelativeImport(from: string, target: string) {\n const fromDir = dirname(from)\n const rel = relative(fromDir, target)\n if (!rel || rel.startsWith('.')) {\n return normalizePath(rel || `./${posix.basename(target)}`)\n }\n return `./${normalizePath(rel)}`\n}\n\nexport function appendInlineQuery(id: string) {\n if (id.includes('?')) {\n if (id.includes('?inline') || id.includes('&inline')) {\n return id\n }\n return `${id}&inline`\n }\n return `${id}?inline`\n}\n\nexport function appendQuery(id: string, query: string) {\n return `${id}${id.includes('?') ? '&' : '?'}${query}`\n}\n\nexport function relativeModuleId(root: string, absPath: string) {\n const rel = relative(root, absPath)\n return `/${normalizePath(rel)}`\n}\n\nexport function toViteFsImport(absPath: string) {\n const normalized = normalizePath(absPath)\n return normalized.startsWith('/')\n ? `/@fs${normalized}`\n : `/@fs/${normalized}`\n}\n\nexport function resolveRuntimePolyfillPath() {\n const currentDir = dirname(fileURLToPath(import.meta.url))\n const candidates = [\n resolve(currentDir, '../runtime/index.mjs'),\n resolve(currentDir, './runtime/index.mjs'),\n resolve(currentDir, '../runtime/polyfill.ts'),\n resolve(currentDir, '../runtime/index.ts'),\n ]\n\n for (const candidate of candidates) {\n if (existsSync(candidate)) {\n return candidate\n }\n }\n\n throw new Error('[@weapp-vite/web] Failed to resolve runtime polyfill path.')\n}\n\nexport function resolveImportBase(raw: string, importer: string, srcRoot: string) {\n if (!raw) {\n return undefined\n }\n if (raw.startsWith('.')) {\n return resolve(dirname(importer), raw)\n }\n if (raw.startsWith('/')) {\n return resolve(srcRoot, raw.slice(1))\n }\n return resolve(srcRoot, raw)\n}\n\nexport function resolveFileWithExtensionsSync(basePath: string, extensions: string[]) {\n if (extname(basePath) && existsSync(basePath)) {\n return basePath\n }\n for (const ext of extensions) {\n const candidate = `${basePath}${ext}`\n if (existsSync(candidate)) {\n return candidate\n }\n }\n return undefined\n}\n\nexport function resolveTemplatePathSync(raw: string, importer: string, srcRoot: string) {\n const base = resolveImportBase(raw, importer, srcRoot)\n if (!base) {\n return undefined\n }\n return resolveFileWithExtensionsSync(base, TEMPLATE_EXTS)\n}\n\nexport function resolveWxsPathSync(raw: string, importer: string, srcRoot: string) {\n if (!raw) {\n return undefined\n }\n let base: string | undefined\n if (raw.startsWith('.')) {\n base = resolve(dirname(importer), raw)\n }\n else if (raw.startsWith('/')) {\n base = resolve(srcRoot, raw.slice(1))\n }\n else {\n return undefined\n }\n return resolveFileWithExtensionsSync(base, WXS_RESOLVE_EXTS)\n}\n"],"mappings":";;;;;;AAMA,SAAgB,SAAS,KAAa;CACpC,MAAM,aAAa,IAAI,QAAQ,GAAG;CAClC,IAAI,cAAc,GAChB,OAAO,IAAI,MAAM,GAAG,UAAU;CAEhC,OAAO;AACT;AAEA,SAAgB,cAAc,GAAW;CACvC,OAAO,MAAM,UAAU,EAAE,MAAM,IAAI,CAAC,CAAC,KAAK,GAAG,CAAC;AAChD;AAEA,SAAgB,YAAY,UAAkB,KAAa;CACzD,MAAM,MAAM,SAAS,KAAK,QAAQ;CAClC,OAAO,QAAQ,MAAO,CAAC,IAAI,WAAW,IAAI,KAAK,CAAC,MAAM,WAAW,GAAG;AACtE;AAEA,SAAgB,YAAY,UAAkB,MAAc;CAC1D,IAAI,CAAC,SAAS,YAAY,CAAC,CAAC,SAAS,OAAO,GAC1C,OAAO;CAET,OAAO,cAAc,QAAQ,MAAM,cAAc,QAAQ,MAAM,YAAY,CAAC;AAC9E;AAEA,SAAgB,UAAU,IAAY;CACpC,OAAO,UAAU,EAAE,CAAC,CAAC,MAAM,IAAI,CAAC,CAAC,KAAK,GAAG;AAC3C;AAEA,SAAgB,iBAAiB,MAAc,QAAgB;
|
|
1
|
+
{"version":3,"file":"path.mjs","names":[],"sources":["../../src/plugin/path.ts"],"sourcesContent":["import { existsSync } from 'node:fs'\nimport { fileURLToPath } from 'node:url'\nimport { dirname, extname, normalize, posix, relative, resolve } from 'pathe'\n\nimport { TEMPLATE_EXTS, WXS_RESOLVE_EXTS } from './constants'\n\nexport function cleanUrl(url: string) {\n const queryIndex = url.indexOf('?')\n if (queryIndex >= 0) {\n return url.slice(0, queryIndex)\n }\n return url\n}\n\nexport function normalizePath(p: string) {\n return posix.normalize(p.split('\\\\').join('/'))\n}\n\nexport function isInsideDir(filePath: string, dir: string) {\n const rel = relative(dir, filePath)\n return rel === '' || (!rel.startsWith('..') && !posix.isAbsolute(rel))\n}\n\nexport function isHtmlEntry(filePath: string, root: string) {\n if (!filePath.toLowerCase().endsWith('.html')) {\n return false\n }\n return normalizePath(filePath) === normalizePath(resolve(root, 'index.html'))\n}\n\nexport function toPosixId(id: string) {\n return normalize(id).split('\\\\').join('/')\n}\n\nexport function toRelativeImport(from: string, target: string) {\n const fromDir = dirname(from)\n const rel = relative(fromDir, target)\n if (!rel || rel.startsWith('.')) {\n return normalizePath(rel || `./${posix.basename(target)}`)\n }\n return `./${normalizePath(rel)}`\n}\n\nexport function appendInlineQuery(id: string) {\n if (id.includes('?')) {\n if (id.includes('?inline') || id.includes('&inline')) {\n return id\n }\n return `${id}&inline`\n }\n return `${id}?inline`\n}\n\nexport function appendQuery(id: string, query: string) {\n return `${id}${id.includes('?') ? '&' : '?'}${query}`\n}\n\nexport function relativeModuleId(root: string, absPath: string) {\n const rel = relative(root, absPath)\n return `/${normalizePath(rel)}`\n}\n\nexport function toViteFsImport(absPath: string) {\n const normalized = normalizePath(absPath)\n return normalized.startsWith('/')\n ? `/@fs${normalized}`\n : `/@fs/${normalized}`\n}\n\nexport function resolveRuntimePolyfillPath() {\n const currentDir = dirname(fileURLToPath(import.meta.url))\n const candidates = [\n resolve(currentDir, '../runtime/index.mjs'),\n resolve(currentDir, './runtime/index.mjs'),\n resolve(currentDir, '../runtime/polyfill.ts'),\n resolve(currentDir, '../runtime/index.ts'),\n ]\n\n for (const candidate of candidates) {\n if (existsSync(candidate)) {\n return candidate\n }\n }\n\n throw new Error('[@weapp-vite/web] Failed to resolve runtime polyfill path.')\n}\n\nexport function resolveImportBase(raw: string, importer: string, srcRoot: string) {\n if (!raw) {\n return undefined\n }\n if (raw.startsWith('.')) {\n return resolve(dirname(importer), raw)\n }\n if (raw.startsWith('/')) {\n return resolve(srcRoot, raw.slice(1))\n }\n return resolve(srcRoot, raw)\n}\n\nexport function resolveFileWithExtensionsSync(basePath: string, extensions: string[]) {\n if (extname(basePath) && existsSync(basePath)) {\n return basePath\n }\n for (const ext of extensions) {\n const candidate = `${basePath}${ext}`\n if (existsSync(candidate)) {\n return candidate\n }\n }\n return undefined\n}\n\nexport function resolveTemplatePathSync(raw: string, importer: string, srcRoot: string) {\n const base = resolveImportBase(raw, importer, srcRoot)\n if (!base) {\n return undefined\n }\n return resolveFileWithExtensionsSync(base, TEMPLATE_EXTS)\n}\n\nexport function resolveWxsPathSync(raw: string, importer: string, srcRoot: string) {\n if (!raw) {\n return undefined\n }\n let base: string | undefined\n if (raw.startsWith('.')) {\n base = resolve(dirname(importer), raw)\n }\n else if (raw.startsWith('/')) {\n base = resolve(srcRoot, raw.slice(1))\n }\n else {\n return undefined\n }\n return resolveFileWithExtensionsSync(base, WXS_RESOLVE_EXTS)\n}\n"],"mappings":";;;;;;AAMA,SAAgB,SAAS,KAAa;CACpC,MAAM,aAAa,IAAI,QAAQ,GAAG;CAClC,IAAI,cAAc,GAChB,OAAO,IAAI,MAAM,GAAG,UAAU;CAEhC,OAAO;AACT;AAEA,SAAgB,cAAc,GAAW;CACvC,OAAO,MAAM,UAAU,EAAE,MAAM,IAAI,CAAC,CAAC,KAAK,GAAG,CAAC;AAChD;AAEA,SAAgB,YAAY,UAAkB,KAAa;CACzD,MAAM,MAAM,SAAS,KAAK,QAAQ;CAClC,OAAO,QAAQ,MAAO,CAAC,IAAI,WAAW,IAAI,KAAK,CAAC,MAAM,WAAW,GAAG;AACtE;AAEA,SAAgB,YAAY,UAAkB,MAAc;CAC1D,IAAI,CAAC,SAAS,YAAY,CAAC,CAAC,SAAS,OAAO,GAC1C,OAAO;CAET,OAAO,cAA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