提交 fddbaa7f 编写于 作者: 雪洛's avatar 雪洛

feat: page-meta-head support

上级 ecef394d
import { isNativeTag, isCustomElement } from '@dcloudio/uni-shared'
import { compileI18nJsonStr } from '@dcloudio/uni-i18n'
import { UniVitePlugin, initI18nOptions } from '@dcloudio/uni-cli-shared'
import {
UniVitePlugin,
initI18nOptions,
transformPageHead,
} from '@dcloudio/uni-cli-shared'
export function uniOptions(): UniVitePlugin['uni'] {
return {
......@@ -28,6 +32,7 @@ export function uniOptions(): UniVitePlugin['uni'] {
compilerOptions: {
isNativeTag,
isCustomElement,
nodeTransforms: [transformPageHead],
},
transformEvent: {
tap: 'click',
......
......@@ -7,11 +7,23 @@ export { default as hash } from 'hash-sum'
import { PAGE_EXTNAME, PAGE_EXTNAME_APP } from './constants'
import { SFCTemplateCompileOptions } from '@vue/compiler-sfc'
import { NodeTypes, ElementNode, Node } from '@vue/compiler-core'
export const isWindows = os.platform() === 'win32'
export function normalizePath(id: string): string {
return isWindows ? id.replace(/\\/g, '/') : id
}
export function checkElementNodeTag(
node: Node | null | undefined,
tag: string
): node is ElementNode {
return (
!!node &&
node.type === NodeTypes.ELEMENT &&
(node as ElementNode).tag === tag
)
}
export const resolveMainPathOnce = once((inputDir: string) => {
const mainTsPath = path.resolve(inputDir, 'main.ts')
if (fs.existsSync(mainTsPath)) {
......
import { NodeTransform } from '@vue/compiler-core'
import { checkElementNodeTag } from '../../utils'
export const transformPageHead: NodeTransform = (_node, _context) => {
// 发现是page-meta下的page-head,直接remove该节点
export const transformPageHead: NodeTransform = (node, context) => {
// 发现是page-meta下的page-meta-head,直接remove该节点
checkElementNodeTag(node, 'page-meta-head') &&
checkElementNodeTag(context.parent, 'page-meta') &&
context.removeNode(node)
}
<template>
<teleport to="__head__">
<slot />
</teleport>
</template>
<script>
export default {
}
</script>
......@@ -4,6 +4,7 @@ import {
CopyOptions,
UniVitePlugin,
MiniProgramCompilerOptions,
transformPageHead,
} from '@dcloudio/uni-cli-shared'
import { TemplateCompiler } from '@vue/compiler-sfc'
import type { CompilerOptions } from '@dcloudio/uni-mp-compiler'
......@@ -26,6 +27,10 @@ export function uniOptions({
isNativeTag,
isCustomElement,
...compilerOptions,
nodeTransforms: [
transformPageHead,
...(compilerOptions?.nodeTransforms || []),
],
} as any,
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册