提交 ce278bc1 编写于 作者: fxy060608's avatar fxy060608

refactor: customElements

上级 18504553
......@@ -24,8 +24,10 @@
"@dcloudio/uni-i18n": "3.0.0-alpha-3021320211115001",
"@dcloudio/uni-shared": "3.0.0-alpha-3021320211115001",
"@rollup/pluginutils": "^4.1.1",
"@vitejs/plugin-vue": "^1.9.4",
"debug": "^4.3.2",
"fs-extra": "^10.0.0"
"fs-extra": "^10.0.0",
"rollup": "^2.57.0"
},
"devDependencies": {
"@types/debug": "^4.1.7",
......
import { RollupOptions } from 'rollup'
import vue from '@vitejs/plugin-vue'
import { EXTNAME_VUE_RE, removeExt } from '@dcloudio/uni-cli-shared'
import { isBuiltInComponent } from '@dcloudio/uni-shared'
export function createRollupOptions(pagePath: string): RollupOptions {
return {
input: pagePath,
context: 'global',
external: ['vue'],
preserveEntrySignatures: false,
output: {
dir: process.env.UNI_OUTPUT_DIR,
file: removeExt(pagePath) + '.js',
format: 'iife',
exports: 'auto',
sourcemap: false,
globals: { vue: 'Vue' },
},
plugins: [
vue({
include: [EXTNAME_VUE_RE],
ssr: false,
isProduction: process.env.NODE_ENV === 'production',
refTransform: true,
template: {
compilerOptions: {
// TODO
isNativeTag: isBuiltInComponent,
},
},
}),
],
}
}
import { isNativeTag, isCustomElement } from '@dcloudio/uni-shared'
import { isAppNativeTag as isNativeTag } from '@dcloudio/uni-shared'
import { compileI18nJsonStr } from '@dcloudio/uni-i18n'
import {
UniVitePlugin,
......@@ -33,7 +33,6 @@ export function uniOptions(): UniVitePlugin['uni'] {
},
compilerOptions: {
isNativeTag,
isCustomElement,
nodeTransforms: [
transformTapToClick,
transformMatchMedia,
......
......@@ -18,8 +18,8 @@ interface UniVitePluginUniOptions {
miniProgram?: {
emitFile?: (emittedFile: EmittedAsset) => string
}
isNativeTag: ParserOptions['isNativeTag']
isCustomElement: ParserOptions['isCustomElement']
isNativeTag?: ParserOptions['isNativeTag']
isCustomElement?: ParserOptions['isCustomElement']
directiveTransforms?: CompilerOptions['directiveTransforms']
nodeTransforms?: CompilerOptions['nodeTransforms']
}
......
import { tags } from '../src/compiler/options'
import { customElements } from '../src/compiler/options'
import { assert } from './testUtils'
describe('mp-alipay: transform component', () => {
test(`built-in component`, () => {
const code = tags.map((tag) => `<${tag}/>`).join('')
const code = customElements.map((tag) => `<${tag}/>`).join('')
assert(
code,
code,
......
import {
createIsCustomElement,
isMiniProgramNativeTag as isNativeTag,
} from '@dcloudio/uni-shared'
import { compile, CompilerOptions } from '@dcloudio/uni-mp-compiler'
import { compilerOptions, miniProgram } from '../src/compiler/options'
import {
customElements,
compilerOptions,
miniProgram,
} from '../src/compiler/options'
export function assert(
template: string,
......@@ -16,6 +24,8 @@ export function assert(
generatorOpts: {
concise: true,
},
isNativeTag,
isCustomElement: createIsCustomElement(customElements),
miniProgram: {
...miniProgram,
emitFile({ source }) {
......
......@@ -11,61 +11,6 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
var initMiniProgramPlugin__default = /*#__PURE__*/_interopDefaultLegacy(initMiniProgramPlugin);
var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
const BUILT_IN_TAGS = [
'ad',
'ad-content-page',
'ad-draw',
'audio',
'button',
'camera',
'canvas',
'checkbox',
'checkbox-group',
'cover-image',
'cover-view',
'editor',
'form',
'functional-page-navigator',
'icon',
'image',
'input',
'label',
'live-player',
'live-pusher',
'map',
'movable-area',
'movable-view',
'navigator',
'official-account',
'open-data',
'picker',
'picker-view',
'picker-view-column',
'progress',
'radio',
'radio-group',
'rich-text',
'scroll-view',
'slider',
'swiper',
'swiper-item',
'switch',
'text',
'textarea',
'video',
'view',
'web-view',
].map((tag) => 'uni-' + tag);
function isBuiltInComponent(tag) {
return BUILT_IN_TAGS.indexOf('uni-' + tag) !== -1;
}
function isNativeTag(tag) {
return shared.isHTMLTag(tag) || shared.isSVGTag(tag) || isBuiltInComponent(tag);
}
function isCustomElement$1(_tag) {
return false;
}
var component2 = true;
var enableAppxNg = true;
var source = {
......@@ -200,11 +145,9 @@ const nodeTransforms = [
uniCliShared.createTransformComponentLink(uniCliShared.COMPONENT_ON_LINK, 6 /* ATTRIBUTE */),
];
const compilerOptions = {
isNativeTag,
isCustomElement,
nodeTransforms,
};
const tags = [
const customElements = [
'lifestyle',
'life-follow',
'contact-button',
......@@ -217,9 +160,6 @@ const tags = [
'ix-native-list',
'mkt',
];
function isCustomElement(tag) {
return tags.includes(tag) || isCustomElement$1();
}
const options = {
vite: {
inject: {
......@@ -268,7 +208,7 @@ const options = {
filename: projectConfigFilename,
source,
},
template: Object.assign(Object.assign({}, miniProgram), { filter: {
template: Object.assign(Object.assign({}, miniProgram), { customElements, filter: {
extname: '.sjs',
lang: 'sjs',
generate(filter, filename) {
......
import path from 'path'
import { CompilerOptions, NodeTypes } from '@vue/compiler-core'
import {
isNativeTag,
isCustomElement as baseIsCustomElement,
} from '@dcloudio/uni-shared'
import {
COMPONENT_ON_LINK,
createTransformComponentLink,
......@@ -38,12 +34,10 @@ const nodeTransforms = [
createTransformComponentLink(COMPONENT_ON_LINK, NodeTypes.ATTRIBUTE),
]
export const compilerOptions: CompilerOptions = {
isNativeTag,
isCustomElement,
nodeTransforms,
}
export const tags = [
export const customElements = [
'lifestyle',
'life-follow',
'contact-button',
......@@ -57,10 +51,6 @@ export const tags = [
'mkt',
]
function isCustomElement(tag: string) {
return tags.includes(tag) || baseIsCustomElement(tag)
}
export const options: UniMiniProgramPluginOptions = {
vite: {
inject: {
......@@ -112,6 +102,7 @@ export const options: UniMiniProgramPluginOptions = {
template: {
/* eslint-disable no-restricted-syntax */
...miniProgram,
customElements,
filter: {
extname: '.sjs',
lang: 'sjs',
......
import { assert } from './testUtils'
import { customElements } from '../src/compiler/options'
describe('mp-baidu: transform component', () => {
test(`built-in component`, () => {
const code = customElements.map((tag) => `<${tag}/>`).join('')
assert(
code,
code,
`(_ctx, _cache) => {
return {}
}`
)
})
test(`match-media`, () => {
assert(
`<match-media/>`,
......
import { isCustomElement, isNativeTag } from '@dcloudio/uni-shared'
import {
createIsCustomElement,
isMiniProgramNativeTag as isNativeTag,
} from '@dcloudio/uni-shared'
import { compile, CompilerOptions } from '@dcloudio/uni-mp-compiler'
import { miniProgram, compilerOptions } from '../src/compiler/options'
import {
customElements,
miniProgram,
compilerOptions,
} from '../src/compiler/options'
export function assert(
template: string,
......@@ -14,7 +21,7 @@ export function assert(
prefixIdentifiers: true,
inline: true,
isNativeTag,
isCustomElement,
isCustomElement: createIsCustomElement(customElements),
generatorOpts: {
concise: true,
},
......
......@@ -2,7 +2,6 @@
var initMiniProgramPlugin = require('@dcloudio/uni-mp-vite');
var path = require('path');
var uniShared = require('@dcloudio/uni-shared');
var uniCliShared = require('@dcloudio/uni-cli-shared');
var uniMpCompiler = require('@dcloudio/uni-mp-compiler');
......@@ -65,6 +64,7 @@ const transformOn = uniCliShared.createTransformOn(uniMpCompiler.transformOn);
*/
const transformModel = uniCliShared.createTransformModel(uniMpCompiler.transformModel);
const customElements = ['follow-swan', 'login', 'inline-payment-panel'];
const nodeTransforms = [uniCliShared.transformRef, transformFor, uniCliShared.transformMatchMedia];
const directiveTransforms = {
on: transformOn,
......@@ -82,8 +82,6 @@ const miniProgram = {
directive: 's-',
};
const compilerOptions = {
isNativeTag: uniShared.isNativeTag,
isCustomElement: uniShared.isCustomElement,
nodeTransforms,
directiveTransforms,
};
......@@ -109,7 +107,7 @@ const options = {
filename: projectConfigFilename,
source,
},
template: Object.assign(Object.assign({}, miniProgram), { filter: {
template: Object.assign(Object.assign({}, miniProgram), { customElements, filter: {
extname: '.sjs',
lang: 'sjs',
generate(filter, filename) {
......
import path from 'path'
import type { CompilerOptions } from '@vue/compiler-core'
import { isCustomElement, isNativeTag } from '@dcloudio/uni-shared'
import {
MiniProgramCompilerOptions,
transformMatchMedia,
......@@ -13,6 +12,7 @@ import { transformFor } from './transforms/vFor'
import { transformOn } from './transforms/vOn'
import { transformModel } from './transforms/vModel'
export const customElements = ['follow-swan', 'login', 'inline-payment-panel']
const nodeTransforms = [transformRef, transformFor, transformMatchMedia]
const directiveTransforms = {
on: transformOn,
......@@ -31,8 +31,6 @@ export const miniProgram: MiniProgramCompilerOptions = {
}
export const compilerOptions: CompilerOptions = {
isNativeTag,
isCustomElement,
nodeTransforms,
directiveTransforms,
}
......@@ -63,6 +61,7 @@ export const options: UniMiniProgramPluginOptions = {
template: {
/* eslint-disable no-restricted-syntax */
...miniProgram,
customElements,
filter: {
extname: '.sjs',
lang: 'sjs',
......
import { MiniProgramCompilerOptions } from '@dcloudio/uni-cli-shared'
import { isCustomElement, isNativeTag } from '@dcloudio/uni-shared'
import {
createIsCustomElement,
isMiniProgramNativeTag as isNativeTag,
} from '@dcloudio/uni-shared'
import { compile } from '../src/index'
import { CompilerOptions } from '../src/options'
......@@ -30,7 +33,7 @@ export function assert(
prefixIdentifiers: true,
inline: true,
isNativeTag,
isCustomElement,
isCustomElement: createIsCustomElement([]),
generatorOpts: {
concise: true,
},
......
import { isNativeTag } from '@dcloudio/uni-shared'
import { isMiniProgramNativeTag as isNativeTag } from '@dcloudio/uni-shared'
import { compile, CompilerOptions } from '@dcloudio/uni-mp-compiler'
import { compilerOptions, miniProgram } from '../src/compiler/options'
......
......@@ -3,7 +3,6 @@
var uniCliShared = require('@dcloudio/uni-cli-shared');
var initMiniProgramPlugin = require('@dcloudio/uni-mp-vite');
var path = require('path');
var uniShared = require('@dcloudio/uni-shared');
var uniMpCompiler = require('@dcloudio/uni-mp-compiler');
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
......@@ -135,8 +134,6 @@ const directiveTransforms = {
model: transformModel,
};
const compilerOptions = {
isNativeTag: uniShared.isNativeTag,
isCustomElement: uniShared.isCustomElement,
nodeTransforms,
directiveTransforms,
};
......
import path from 'path'
import type { CompilerOptions } from '@vue/compiler-core'
import { isNativeTag, isCustomElement } from '@dcloudio/uni-shared'
import {
MiniProgramCompilerOptions,
transformComponentLink,
......@@ -17,9 +16,8 @@ const directiveTransforms = {
on: transformOn,
model: transformModel,
}
export const compilerOptions: CompilerOptions = {
isNativeTag,
isCustomElement,
nodeTransforms,
directiveTransforms,
}
......
......@@ -3,7 +3,6 @@
var initMiniProgramPlugin = require('@dcloudio/uni-mp-vite');
var uniCliShared = require('@dcloudio/uni-cli-shared');
var path = require('path');
var uniShared = require('@dcloudio/uni-shared');
var uniMpCompiler = require('@dcloudio/uni-mp-compiler');
var compilerCore = require('@vue/compiler-core');
......@@ -71,8 +70,6 @@ const nodeTransforms = [
uniCliShared.transformComponentLink,
];
const compilerOptions = {
isNativeTag: uniShared.isNativeTag,
isCustomElement: uniShared.isCustomElement,
nodeTransforms,
};
const miniProgram = {
......
import { isNativeTag } from '@dcloudio/uni-shared'
import { isMiniProgramNativeTag as isNativeTag } from '@dcloudio/uni-shared'
import { compile, CompilerOptions } from '@dcloudio/uni-mp-compiler'
import { compilerOptions, miniProgram } from '../src/compiler/options'
......
......@@ -4,7 +4,6 @@ var uniCliShared = require('@dcloudio/uni-cli-shared');
var initMiniProgramPlugin = require('@dcloudio/uni-mp-vite');
var path = require('path');
var fs = require('fs-extra');
var uniShared = require('@dcloudio/uni-shared');
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
......@@ -89,8 +88,6 @@ const nodeTransforms = [
uniCliShared.transformComponentLink,
];
const compilerOptions = {
isNativeTag: uniShared.isNativeTag,
isCustomElement: uniShared.isCustomElement,
nodeTransforms,
};
const miniProgram = {
......
import path from 'path'
import type { CompilerOptions } from '@vue/compiler-core'
import { isCustomElement, isNativeTag } from '@dcloudio/uni-shared'
import {
MiniProgramCompilerOptions,
transformComponentLink,
......@@ -18,8 +17,6 @@ const nodeTransforms = [
]
export const compilerOptions: CompilerOptions = {
isNativeTag,
isCustomElement,
nodeTransforms,
}
......
import { isMiniProgramNativeTag as isNativeTag } from '@dcloudio/uni-shared'
import { compile, CompilerOptions } from '@dcloudio/uni-mp-compiler'
import { miniProgram, compilerOptions } from '../src/compiler/options'
......@@ -16,6 +17,7 @@ export function assert(
generatorOpts: {
concise: true,
},
isNativeTag,
miniProgram: {
...miniProgram,
emitFile({ source }) {
......
......@@ -2,7 +2,6 @@
var initMiniProgramPlugin = require('@dcloudio/uni-mp-vite');
var path = require('path');
var uniShared = require('@dcloudio/uni-shared');
var uniCliShared = require('@dcloudio/uni-cli-shared');
var uniMpCompiler = require('@dcloudio/uni-mp-compiler');
var compilerCore = require('@vue/compiler-core');
......@@ -71,8 +70,6 @@ const nodeTransforms = [
uniCliShared.transformComponentLink,
];
const compilerOptions = {
isNativeTag: uniShared.isNativeTag,
isCustomElement: uniShared.isCustomElement,
nodeTransforms,
};
const miniProgram = {
......
import path from 'path'
import type { CompilerOptions } from '@vue/compiler-core'
import { isCustomElement, isNativeTag } from '@dcloudio/uni-shared'
import {
MiniProgramCompilerOptions,
transformComponentLink,
......@@ -22,8 +21,6 @@ const nodeTransforms = [
]
export const compilerOptions: CompilerOptions = {
isNativeTag,
isCustomElement,
nodeTransforms,
}
export const miniProgram: MiniProgramCompilerOptions = {
......
......@@ -52,6 +52,7 @@ export interface UniMiniProgramPluginOptions {
class: MiniProgramCompilerOptions['class']
slot: MiniProgramCompilerOptions['slot']
lazyElement?: MiniProgramCompilerOptions['lazyElement']
customElements?: string[]
filter?: {
lang: string
extname: string
......@@ -80,6 +81,7 @@ export function uniMiniProgramPlugin(
name: 'vite:uni-mp',
uni: uniOptions({
copyOptions,
customElements: template.customElements,
miniProgram: {
event: template.event,
class: template.class,
......
import { isNativeTag, isCustomElement } from '@dcloudio/uni-shared'
import {
isMiniProgramNativeTag as isNativeTag,
createIsCustomElement,
} from '@dcloudio/uni-shared'
import {
CopyOptions,
......@@ -13,8 +16,10 @@ import * as compiler from '@dcloudio/uni-mp-compiler'
export function uniOptions({
copyOptions,
miniProgram,
customElements,
compilerOptions,
}: {
customElements?: string[]
copyOptions: CopyOptions
miniProgram: MiniProgramCompilerOptions
compilerOptions?: CompilerOptions
......@@ -25,7 +30,7 @@ export function uniOptions({
compilerOptions: {
miniProgram,
isNativeTag,
isCustomElement,
isCustomElement: createIsCustomElement(customElements),
...compilerOptions,
nodeTransforms: [
transformPageHead,
......
import { assert } from './testUtils'
import { customElements } from '../src/compiler/options'
describe('mp-weixin: transform component', () => {
test(`built-in component`, () => {
const code = customElements.map((tag) => `<${tag}/>`).join('')
assert(
code,
code,
`(_ctx, _cache) => {
return {}
}`
)
})
test('lazy element', () => {
assert(
`<editor/>`,
......@@ -14,15 +24,6 @@ describe('mp-weixin: transform component', () => {
`<block wx:if="{{r0}}"><editor bindready="{{a}}"/></block>`,
`(_ctx, _cache) => {
return { a: _o(_ctx.ready) }
}`
)
})
test(`match-media`, () => {
assert(
`<match-media/>`,
`<match-media/>`,
`(_ctx, _cache) => {
return {}
}`
)
})
......
import { isNativeTag } from '@dcloudio/uni-shared'
import {
createIsCustomElement,
isMiniProgramNativeTag as isNativeTag,
} from '@dcloudio/uni-shared'
import { compile, CompilerOptions } from '@dcloudio/uni-mp-compiler'
import { compilerOptions, miniProgram } from '../src/compiler/options'
import {
customElements,
compilerOptions,
miniProgram,
} from '../src/compiler/options'
export function assert(
template: string,
......@@ -15,6 +22,7 @@ export function assert(
prefixIdentifiers: true,
inline: true,
isNativeTag,
isCustomElement: createIsCustomElement(customElements),
generatorOpts: {
concise: true,
},
......
......@@ -3,7 +3,6 @@
var uniCliShared = require('@dcloudio/uni-cli-shared');
var initMiniProgramPlugin = require('@dcloudio/uni-mp-vite');
var path = require('path');
var uniShared = require('@dcloudio/uni-shared');
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
......@@ -59,12 +58,8 @@ var source = {
condition: condition
};
const customElements = ['page-meta', 'navigation-bar', 'match-media'];
const compilerOptions = {
isNativeTag: uniShared.isNativeTag,
isCustomElement: (tag) => {
return (['page-meta', 'navigation-bar', 'match-media'].includes(tag) ||
uniShared.isCustomElement(tag));
},
nodeTransforms: [uniCliShared.transformRef, uniCliShared.transformComponentLink],
};
const miniProgram = {
......@@ -117,7 +112,7 @@ const options = {
filename: projectConfigFilename,
source,
},
template: Object.assign(Object.assign({}, miniProgram), { filter: {
template: Object.assign(Object.assign({}, miniProgram), { customElements, filter: {
extname: '.wxs',
lang: 'wxs',
generate(filter, filename) {
......
import path from 'path'
import type { CompilerOptions } from '@vue/compiler-core'
import {
isNativeTag,
isCustomElement as baseIsCustomElement,
} from '@dcloudio/uni-shared'
import {
MiniProgramCompilerOptions,
transformComponentLink,
......@@ -13,14 +9,9 @@ import { UniMiniProgramPluginOptions } from '@dcloudio/uni-mp-vite'
import source from './project.config.json'
export const customElements = ['page-meta', 'navigation-bar', 'match-media']
export const compilerOptions: CompilerOptions = {
isNativeTag,
isCustomElement: (tag) => {
return (
['page-meta', 'navigation-bar', 'match-media'].includes(tag) ||
baseIsCustomElement(tag)
)
},
nodeTransforms: [transformRef, transformComponentLink],
}
......@@ -78,6 +69,7 @@ export const options: UniMiniProgramPluginOptions = {
template: {
/* eslint-disable no-restricted-syntax */
...miniProgram,
customElements,
filter: {
extname: '.wxs',
lang: 'wxs',
......
......@@ -3,7 +3,6 @@
var uniCliShared = require('@dcloudio/uni-cli-shared');
var initMiniProgramPlugin = require('@dcloudio/uni-mp-vite');
var path = require('path');
var uniShared = require('@dcloudio/uni-shared');
var shared = require('@vue/shared');
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
......@@ -57,8 +56,6 @@ function formatAppJson(_appJson, manifestJson, _pagesJson) {
}
const compilerOptions = {
isNativeTag: uniShared.isNativeTag,
isCustomElement: uniShared.isCustomElement,
nodeTransforms: [uniCliShared.transformRef, uniCliShared.transformComponentLink],
};
const miniProgram = {
......
import path from 'path'
import type { CompilerOptions } from '@vue/compiler-core'
import { isNativeTag, isCustomElement } from '@dcloudio/uni-shared'
import {
MiniProgramCompilerOptions,
transformComponentLink,
......@@ -12,8 +11,6 @@ import source from './jsconfig.json'
import { formatAppJson } from './utils'
export const compilerOptions: CompilerOptions = {
isNativeTag,
isCustomElement,
nodeTransforms: [transformRef, transformComponentLink],
}
......
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"resolveJsonModule": true,
"paths": {
"@dcloudio/*": ["packages/*/src"],
"@dcloudio/uni-platform": [
......
......@@ -80,11 +80,16 @@ function isH5NativeTag(tag) {
(shared.isHTMLTag(tag) || shared.isSVGTag(tag)) &&
!isBuiltInComponent(tag));
}
function isNativeTag(tag) {
function isAppNativeTag(tag) {
return shared.isHTMLTag(tag) || shared.isSVGTag(tag) || isBuiltInComponent(tag);
}
function isCustomElement(_tag) {
return false;
function isMiniProgramNativeTag(tag) {
return isBuiltInComponent(tag);
}
function createIsCustomElement(tags = []) {
return function isCustomElement(tag) {
return tags.includes(tag);
};
}
function isComponentTag(tag) {
return tag[0].toLowerCase() + tag.slice(1) === 'component';
......@@ -1281,6 +1286,7 @@ exports.addFont = addFont;
exports.cache = cache;
exports.cacheStringFunction = cacheStringFunction;
exports.callOptions = callOptions;
exports.createIsCustomElement = createIsCustomElement;
exports.createRpx2Unit = createRpx2Unit;
exports.createUniEvent = createUniEvent;
exports.debounce = debounce;
......@@ -1300,12 +1306,12 @@ exports.getLen = getLen;
exports.getValueByDataPath = getValueByDataPath;
exports.initCustomDataset = initCustomDataset;
exports.invokeArrayFns = invokeArrayFns;
exports.isAppNativeTag = isAppNativeTag;
exports.isBuiltInComponent = isBuiltInComponent;
exports.isComponentTag = isComponentTag;
exports.isCustomElement = isCustomElement;
exports.isH5CustomElement = isH5CustomElement;
exports.isH5NativeTag = isH5NativeTag;
exports.isNativeTag = isNativeTag;
exports.isMiniProgramNativeTag = isMiniProgramNativeTag;
exports.isRootHook = isRootHook;
exports.normalizeDataset = normalizeDataset;
exports.normalizeEventType = normalizeEventType;
......
......@@ -112,6 +112,8 @@ number,
Partial<UniNodeJSON | UniNodeJSONMinify>?
];
export declare function createIsCustomElement(tags?: string[]): (tag: string) => boolean;
export declare function createRpx2Unit(unit: string, unitRatio: number, unitPrecision: number): (val: string) => string;
export declare function createUniEvent(evt: Record<string, any>): UniEvent;
......@@ -214,17 +216,17 @@ export declare type InsertAction = [typeof ACTION_TYPE_INSERT, number, number, n
export declare const invokeArrayFns: (fns: Function[], arg?: any) => any;
export declare function isAppNativeTag(tag: string): boolean;
export declare function isBuiltInComponent(tag: string): boolean;
export declare function isComponentTag(tag: string): boolean;
export declare function isCustomElement(_tag: string): boolean;
export declare function isH5CustomElement(tag: string): boolean;
export declare function isH5NativeTag(tag: string): boolean;
export declare function isNativeTag(tag: string): boolean;
export declare function isMiniProgramNativeTag(tag: string): boolean;
export declare function isRootHook(name: string): boolean;
......
......@@ -76,11 +76,16 @@ function isH5NativeTag(tag) {
(isHTMLTag(tag) || isSVGTag(tag)) &&
!isBuiltInComponent(tag));
}
function isNativeTag(tag) {
function isAppNativeTag(tag) {
return isHTMLTag(tag) || isSVGTag(tag) || isBuiltInComponent(tag);
}
function isCustomElement(_tag) {
return false;
function isMiniProgramNativeTag(tag) {
return isBuiltInComponent(tag);
}
function createIsCustomElement(tags = []) {
return function isCustomElement(tag) {
return tags.includes(tag);
};
}
function isComponentTag(tag) {
return tag[0].toLowerCase() + tag.slice(1) === 'component';
......@@ -1179,4 +1184,4 @@ function getEnvLocale() {
return (lang && lang.replace(/[.:].*/, '')) || 'en';
}
export { ACTION_TYPE_ADD_EVENT, ACTION_TYPE_ADD_WXS_EVENT, ACTION_TYPE_CREATE, ACTION_TYPE_EVENT, ACTION_TYPE_INSERT, ACTION_TYPE_PAGE_CREATE, ACTION_TYPE_PAGE_CREATED, ACTION_TYPE_PAGE_SCROLL, ACTION_TYPE_REMOVE, ACTION_TYPE_REMOVE_ATTRIBUTE, ACTION_TYPE_REMOVE_EVENT, ACTION_TYPE_SET_ATTRIBUTE, ACTION_TYPE_SET_TEXT, ATTR_CHANGE_PREFIX, ATTR_CLASS, ATTR_INNER_HTML, ATTR_STYLE, ATTR_TEXT_CONTENT, ATTR_V_OWNER_ID, ATTR_V_RENDERJS, ATTR_V_SHOW, BACKGROUND_COLOR, BUILT_IN_TAGS, COMPONENT_NAME_PREFIX, COMPONENT_PREFIX, COMPONENT_SELECTOR_PREFIX, DATA_RE, EventChannel, EventModifierFlags, I18N_JSON_DELIMITERS, JSON_PROTOCOL, LINEFEED, NAVBAR_HEIGHT, NODE_TYPE_COMMENT, NODE_TYPE_ELEMENT, NODE_TYPE_PAGE, NODE_TYPE_TEXT, NVueTextNode, ON_ADD_TO_FAVORITES, ON_APP_ENTER_BACKGROUND, ON_APP_ENTER_FOREGROUND, ON_BACK_PRESS, ON_ERROR, ON_HIDE, ON_KEYBOARD_HEIGHT_CHANGE, ON_LAUNCH, ON_LOAD, ON_NAVIGATION_BAR_BUTTON_TAP, ON_NAVIGATION_BAR_SEARCH_INPUT_CHANGED, ON_NAVIGATION_BAR_SEARCH_INPUT_CLICKED, ON_NAVIGATION_BAR_SEARCH_INPUT_CONFIRMED, ON_NAVIGATION_BAR_SEARCH_INPUT_FOCUS_CHANGED, ON_PAGE_NOT_FOUND, ON_PAGE_SCROLL, ON_PULL_DOWN_REFRESH, ON_REACH_BOTTOM, ON_REACH_BOTTOM_DISTANCE, ON_READY, ON_RESIZE, ON_SHARE_APP_MESSAGE, ON_SHARE_TIMELINE, ON_SHOW, ON_TAB_ITEM_TAP, ON_THEME_CHANGE, ON_UNHANDLE_REJECTION, ON_UNLOAD, ON_WEB_INVOKE_APP_SERVICE, ON_WXS_INVOKE_CALL_METHOD, PLUS_RE, PRIMARY_COLOR, RENDERJS_MODULES, RESPONSIVE_MIN_WIDTH, SCHEME_RE, SELECTED_COLOR, SLOT_DEFAULT_NAME, TABBAR_HEIGHT, TAGS, UNI_SSR, UNI_SSR_DATA, UNI_SSR_GLOBAL_DATA, UNI_SSR_STORE, UNI_SSR_TITLE, UniBaseNode, UniCommentNode, UniElement, UniEvent, UniInputElement, UniLifecycleHooks, UniNode, UniTextAreaElement, UniTextNode, WEB_INVOKE_APPSERVICE, WXS_MODULES, WXS_PROTOCOL, addFont, cache, cacheStringFunction, callOptions, createRpx2Unit, createUniEvent, debounce, decode, decodedQuery, defaultMiniProgramRpx2Unit, defaultRpx2Unit, dynamicSlotName, forcePatchProp, formatAppLog, formatDateTime, formatLog, getCustomDataset, getDataByPath, getEnvLocale, getLen, getValueByDataPath, initCustomDataset, invokeArrayFns, isBuiltInComponent, isComponentTag, isCustomElement, isH5CustomElement, isH5NativeTag, isNativeTag, isRootHook, normalizeDataset, normalizeEventType, normalizeTarget, once, parseEventName, parseQuery, parseUrl, passive, plusReady, removeLeadingSlash, resolveOwnerEl, resolveOwnerVm, sanitise, scrollTo, stringifyQuery, updateElementStyle };
export { ACTION_TYPE_ADD_EVENT, ACTION_TYPE_ADD_WXS_EVENT, ACTION_TYPE_CREATE, ACTION_TYPE_EVENT, ACTION_TYPE_INSERT, ACTION_TYPE_PAGE_CREATE, ACTION_TYPE_PAGE_CREATED, ACTION_TYPE_PAGE_SCROLL, ACTION_TYPE_REMOVE, ACTION_TYPE_REMOVE_ATTRIBUTE, ACTION_TYPE_REMOVE_EVENT, ACTION_TYPE_SET_ATTRIBUTE, ACTION_TYPE_SET_TEXT, ATTR_CHANGE_PREFIX, ATTR_CLASS, ATTR_INNER_HTML, ATTR_STYLE, ATTR_TEXT_CONTENT, ATTR_V_OWNER_ID, ATTR_V_RENDERJS, ATTR_V_SHOW, BACKGROUND_COLOR, BUILT_IN_TAGS, COMPONENT_NAME_PREFIX, COMPONENT_PREFIX, COMPONENT_SELECTOR_PREFIX, DATA_RE, EventChannel, EventModifierFlags, I18N_JSON_DELIMITERS, JSON_PROTOCOL, LINEFEED, NAVBAR_HEIGHT, NODE_TYPE_COMMENT, NODE_TYPE_ELEMENT, NODE_TYPE_PAGE, NODE_TYPE_TEXT, NVueTextNode, ON_ADD_TO_FAVORITES, ON_APP_ENTER_BACKGROUND, ON_APP_ENTER_FOREGROUND, ON_BACK_PRESS, ON_ERROR, ON_HIDE, ON_KEYBOARD_HEIGHT_CHANGE, ON_LAUNCH, ON_LOAD, ON_NAVIGATION_BAR_BUTTON_TAP, ON_NAVIGATION_BAR_SEARCH_INPUT_CHANGED, ON_NAVIGATION_BAR_SEARCH_INPUT_CLICKED, ON_NAVIGATION_BAR_SEARCH_INPUT_CONFIRMED, ON_NAVIGATION_BAR_SEARCH_INPUT_FOCUS_CHANGED, ON_PAGE_NOT_FOUND, ON_PAGE_SCROLL, ON_PULL_DOWN_REFRESH, ON_REACH_BOTTOM, ON_REACH_BOTTOM_DISTANCE, ON_READY, ON_RESIZE, ON_SHARE_APP_MESSAGE, ON_SHARE_TIMELINE, ON_SHOW, ON_TAB_ITEM_TAP, ON_THEME_CHANGE, ON_UNHANDLE_REJECTION, ON_UNLOAD, ON_WEB_INVOKE_APP_SERVICE, ON_WXS_INVOKE_CALL_METHOD, PLUS_RE, PRIMARY_COLOR, RENDERJS_MODULES, RESPONSIVE_MIN_WIDTH, SCHEME_RE, SELECTED_COLOR, SLOT_DEFAULT_NAME, TABBAR_HEIGHT, TAGS, UNI_SSR, UNI_SSR_DATA, UNI_SSR_GLOBAL_DATA, UNI_SSR_STORE, UNI_SSR_TITLE, UniBaseNode, UniCommentNode, UniElement, UniEvent, UniInputElement, UniLifecycleHooks, UniNode, UniTextAreaElement, UniTextNode, WEB_INVOKE_APPSERVICE, WXS_MODULES, WXS_PROTOCOL, addFont, cache, cacheStringFunction, callOptions, createIsCustomElement, createRpx2Unit, createUniEvent, debounce, decode, decodedQuery, defaultMiniProgramRpx2Unit, defaultRpx2Unit, dynamicSlotName, forcePatchProp, formatAppLog, formatDateTime, formatLog, getCustomDataset, getDataByPath, getEnvLocale, getLen, getValueByDataPath, initCustomDataset, invokeArrayFns, isAppNativeTag, isBuiltInComponent, isComponentTag, isH5CustomElement, isH5NativeTag, isMiniProgramNativeTag, isRootHook, normalizeDataset, normalizeEventType, normalizeTarget, once, parseEventName, parseQuery, parseUrl, passive, plusReady, removeLeadingSlash, resolveOwnerEl, resolveOwnerVm, sanitise, scrollTo, stringifyQuery, updateElementStyle };
......@@ -83,12 +83,18 @@ export function isH5NativeTag(tag: string) {
)
}
export function isNativeTag(tag: string) {
export function isAppNativeTag(tag: string) {
return isHTMLTag(tag) || isSVGTag(tag) || isBuiltInComponent(tag)
}
export function isCustomElement(_tag: string) {
return false
export function isMiniProgramNativeTag(tag: string) {
return isBuiltInComponent(tag)
}
export function createIsCustomElement(tags: string[] = []) {
return function isCustomElement(tag: string) {
return tags.includes(tag)
}
}
export function isComponentTag(tag: string) {
......
import path from 'path'
import type { Plugin } from 'vite'
import { extend, isArray, isString, isFunction } from '@vue/shared'
import { isCustomElement, isNativeTag } from '@dcloudio/uni-shared'
import type {
CopyOptions,
UniViteCopyPluginTarget,
......@@ -24,10 +23,7 @@ export function initPluginUniOptions(UniVitePlugins: UniVitePlugin[]) {
const assets: string[] = []
const targets: UniViteCopyPluginTarget[] = []
const transformEvent: Record<string, string> = Object.create(null)
const compilerOptions: Required<UniVitePlugin>['uni']['compilerOptions'] = {
isNativeTag,
isCustomElement,
}
const compilerOptions: Required<UniVitePlugin>['uni']['compilerOptions'] = {}
let compiler: TemplateCompiler | undefined
UniVitePlugins.forEach((plugin) => {
const {
......
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册