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

fix(app): TextNode

上级 1c13206d
......@@ -14179,8 +14179,9 @@
}
}
class UniTextNode extends UniNode {
constructor(id2, parentNodeId) {
constructor(id2, parentNodeId, nodeJson) {
super(id2, "#text", parentNodeId, document.createTextNode(""));
this.init(nodeJson);
}
}
var view = "uni-view {\n display: block;\n}\nuni-view[hidden] {\n display: none;\n}\n";
......
import { UniNodeJSON } from '@dcloudio/uni-shared'
import { UniNode } from './UniNode'
export class UniTextNode extends UniNode {
constructor(id: number, parentNodeId: number) {
constructor(
id: number,
parentNodeId: number,
nodeJson: Partial<UniNodeJSON>
) {
super(id, '#text', parentNodeId, document.createTextNode(''))
this.init(nodeJson)
}
}
export const PUBLIC_DIR = 'static'
export const EXTNAME_JS = ['.js', '.ts']
export const EXTNAME_VUE = ['.vue', '.nvue', '.fvue']
export const EXTNAME_VUE_RE = /\.(vue|nvue|fvue)$/
export const EXTNAME_VUE = ['.vue', '.nvue']
export const EXTNAME_VUE_RE = /\.(vue|nvue)$/
// APP 平台解析页面后缀的优先级
export const PAGE_EXTNAME_APP = ['.nvue', '.vue']
// 其他平台解析页面后缀的优先级
export const PAGE_EXTNAME = ['.vue', '.nvue']
export const H5_API_STYLE_PATH = '@dcloudio/uni-h5/style/api/'
export const H5_FRAMEWORK_STYLE_PATH = '@dcloudio/uni-h5/style/framework/'
......
function typof(v: unknown) {
var s = Object.prototype.toString.call(v)
return s.substring(8, s.length - 1)
}
function isDebugMode() {
// @ts-expect-error
return typeof __channelId__ === 'string' && __channelId__
}
function jsonStringifyReplacer(key: string, value: unknown) {
switch (typof(value)) {
case 'Function':
return 'function() { [native code] }'
default:
return value
}
}
type LogType = 'log' | 'info' | 'warn' | 'error'
// export function log(type: LogType) {
// for (
// var _len = arguments.length,
// args = new Array(_len > 1 ? _len - 1 : 0),
// _key = 1;
// _key < _len;
// _key++
// ) {
// args[_key - 1] = arguments[_key]
// }
// console[type].apply(console, args)
// }
export default function formatLog() {
for (
var _len = arguments.length, args = new Array(_len), _key = 0;
_key < _len;
_key++
) {
args[_key] = arguments[_key]
}
var type = args.shift() as LogType
if (isDebugMode()) {
args.push(args.pop().replace('at ', 'uni-app:///'))
return console[type].apply(console, args)
}
var msgs = args.map(function (v) {
var type = Object.prototype.toString.call(v).toLowerCase()
if (type === '[object object]' || type === '[object array]') {
try {
v =
'---BEGIN:JSON---' +
JSON.stringify(v, jsonStringifyReplacer) +
'---END:JSON---'
} catch (e) {
v = type
}
} else {
if (v === null) {
v = '---NULL---'
} else if (v === undefined) {
v = '---UNDEFINED---'
} else {
var vType = typof(v).toUpperCase()
if (vType === 'NUMBER' || vType === 'BOOLEAN') {
v = '---BEGIN:' + vType + '---' + v + '---END:' + vType + '---'
} else {
v = String(v)
}
}
}
return v
})
var msg = ''
if (msgs.length > 1) {
var lastMsg = msgs.pop()
msg = msgs.join('---COMMA---')
if (lastMsg.indexOf(' at ') === 0) {
msg += lastMsg
} else {
msg += '---COMMA---' + lastMsg
}
} else {
msg = msgs[0]
}
console[type](msg)
}
import { normalizeIdentifier } from '../../../utils'
import { normalizeIdentifier, normalizePagePath } from '../../../utils'
export function definePageCode(pagesJson: Record<string, any>) {
const importPagesCode: string[] = []
......@@ -6,10 +6,13 @@ export function definePageCode(pagesJson: Record<string, any>) {
pagesJson.pages.forEach((page: UniApp.UniRoute) => {
const pagePath = page.path
const pageIdentifier = normalizeIdentifier(pagePath)
importPagesCode.push(
`import ${pageIdentifier} from './${pagePath}.vue?mpType=page'`
)
definePagesCode.push(`__definePage('${pagePath}',${pageIdentifier})`)
const pagePathWithExtname = normalizePagePath(pagePath, 'app')
if (pagePathWithExtname) {
importPagesCode.push(
`import ${pageIdentifier} from './${pagePathWithExtname}?mpType=page'`
)
definePagesCode.push(`__definePage('${pagePath}',${pageIdentifier})`)
}
})
return importPagesCode.join('\n') + '\n' + definePagesCode.join('\n')
}
......@@ -4,6 +4,7 @@ import path from 'path'
import slash from 'slash'
import { camelize, capitalize } from '@vue/shared'
import { once } from '@dcloudio/uni-shared'
import { PAGE_EXTNAME, PAGE_EXTNAME_APP } from './constants'
const isWindows = os.platform() === 'win32'
export function normalizePath(id: string): string {
return path.posix.normalize(isWindows ? slash(id) : id)
......@@ -24,3 +25,18 @@ export function resolveBuiltIn(path: string) {
export function normalizeIdentifier(str: string) {
return capitalize(camelize(str.replace(/\//g, '-')))
}
export function normalizePagePath(pagePath: string, platform: UniApp.PLATFORM) {
const absoltePagePath = path.resolve(process.env.UNI_INPUT_DIR, pagePath)
let extnames = PAGE_EXTNAME
if (platform === 'app') {
extnames = PAGE_EXTNAME_APP
}
for (let i = 0; i < extnames.length; i++) {
const extname = extnames[i]
if (fs.existsSync(absoltePagePath + extname)) {
return pagePath + extname
}
}
console.error(`${pagePath} not found`)
}
// import path from 'path'
// import slash from 'slash'
import { Plugin } from 'vite'
import { createFilter, FilterPattern } from '@rollup/pluginutils'
export interface ConsoleOptions {
include?: FilterPattern
exclude?: FilterPattern
}
export function uniConsolePlugin(options: ConsoleOptions): Plugin {
const filter = createFilter(options.include, options.exclude)
return {
name: 'vite:uni-app-console',
transform(code, id) {
if (!filter(id)) return null
if (!code.includes('console.')) {
return null
}
},
}
}
......@@ -137,8 +137,12 @@ function generateLayoutComponentsCode(globalName, pagesJson) {
};
}
function generatePageDefineCode(pageOptions) {
const pagePathWithExtname = uni_cli_shared_1.normalizePagePath(pageOptions.path, 'h5');
if (!pagePathWithExtname) {
return '';
}
const pageIdent = uni_cli_shared_1.normalizeIdentifier(pageOptions.path);
return `const ${pageIdent}Loader = ()=>import('./${pageOptions.path}?mpType=page')
return `const ${pageIdent}Loader = ()=>import('./${pagePathWithExtname}?mpType=page')
const ${pageIdent} = defineAsyncComponent(extend({loader:${pageIdent}Loader},AsyncComponentOptions))`;
}
function generatePagesDefineCode(pagesJson, _config) {
......
......@@ -10,6 +10,7 @@ import {
normalizePagesJson,
defineUniPagesJsonPlugin,
normalizePagesRoute,
normalizePagePath,
} from '@dcloudio/uni-cli-shared'
const pkg = require('@dcloudio/vite-plugin-uni/package.json')
......@@ -164,8 +165,12 @@ function generateLayoutComponentsCode(
}
function generatePageDefineCode(pageOptions: UniApp.PagesJsonPageOptions) {
const pagePathWithExtname = normalizePagePath(pageOptions.path, 'h5')
if (!pagePathWithExtname) {
return ''
}
const pageIdent = normalizeIdentifier(pageOptions.path)
return `const ${pageIdent}Loader = ()=>import('./${pageOptions.path}?mpType=page')
return `const ${pageIdent}Loader = ()=>import('./${pagePathWithExtname}?mpType=page')
const ${pageIdent} = defineAsyncComponent(extend({loader:${pageIdent}Loader},AsyncComponentOptions))`
}
......
import path from 'path'
import { Plugin, UserConfig } from 'vite'
import { normalizePath, parseManifestJsonOnce } from '@dcloudio/uni-cli-shared'
import {
initPreContext,
normalizePath,
parseManifestJsonOnce,
} from '@dcloudio/uni-cli-shared'
import { VitePluginUniResolvedOptions } from '..'
import { createCss } from './css'
......@@ -32,6 +36,9 @@ export function createConfig(
options.command = env.command
options.platform = (process.env.UNI_PLATFORM as UniApp.PLATFORM) || 'h5'
options.inputDir = normalizeInputDir(config)
initPreContext(options.platform)
let base = config.base
if (!base) {
const { h5 } = parseManifestJsonOnce(options.inputDir)
......
import { Plugin } from 'vite'
import { initPreContext /*,checkUpdate*/ } from '@dcloudio/uni-cli-shared'
import { VitePluginUniResolvedOptions } from '..'
import { initEnv } from './env'
......@@ -12,7 +11,6 @@ export function createConfigResolved(options: VitePluginUniResolvedOptions) {
initOptions(options, config)
initPlugins(config, options)
initCheckUpdate()
initPreContext(options.platform)
}) as Plugin['configResolved']
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册