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

fix: wxs (question/136633)

上级 13eb8b49
...@@ -79,7 +79,7 @@ export default function vueFactory(exports) { ...@@ -79,7 +79,7 @@ export default function vueFactory(exports) {
} = instance; // ShapeFlags.ARRAY_CHILDREN = 1<<4 } = instance; // ShapeFlags.ARRAY_CHILDREN = 1<<4
if (subTree.shapeFlag & 16) { if (subTree.shapeFlag & 16) {
var elemVNode = subTree.children.find(vnode => isElement(vnode.el)); var elemVNode = subTree.children.find(vnode => vnode.el && isElement(vnode.el));
if (elemVNode) { if (elemVNode) {
return elemVNode.el; return elemVNode.el;
......
...@@ -77,7 +77,7 @@ export default function vueFactory(exports) { ...@@ -77,7 +77,7 @@ export default function vueFactory(exports) {
} = instance; // ShapeFlags.ARRAY_CHILDREN = 1<<4 } = instance; // ShapeFlags.ARRAY_CHILDREN = 1<<4
if (subTree.shapeFlag & 16) { if (subTree.shapeFlag & 16) {
var elemVNode = subTree.children.find(vnode => isElement(vnode.el)); var elemVNode = subTree.children.find(vnode => vnode.el && isElement(vnode.el));
if (elemVNode) { if (elemVNode) {
return elemVNode.el; return elemVNode.el;
......
...@@ -4626,11 +4626,11 @@ const ChooseLocationProtocol = { ...@@ -4626,11 +4626,11 @@ const ChooseLocationProtocol = {
longitude: Number longitude: Number
}; };
const API_GET_LOCATION = "getLocation"; const API_GET_LOCATION = "getLocation";
const coordTypes = ["WGS84", "GCJ02"]; const coordTypes = ["wgs84", "gcj02"];
const GetLocationOptions = { const GetLocationOptions = {
formatArgs: { formatArgs: {
type(value, params) { type(value, params) {
value = (value || "").toUpperCase(); value = (value || "").toLowerCase();
if (coordTypes.indexOf(value) === -1) { if (coordTypes.indexOf(value) === -1) {
params.type = coordTypes[0]; params.type = coordTypes[0];
} else { } else {
......
...@@ -184,7 +184,7 @@ function resolveOwnerEl(instance) { ...@@ -184,7 +184,7 @@ function resolveOwnerEl(instance) {
const { subTree } = instance; const { subTree } = instance;
// ShapeFlags.ARRAY_CHILDREN = 1<<4 // ShapeFlags.ARRAY_CHILDREN = 1<<4
if (subTree.shapeFlag & 16) { if (subTree.shapeFlag & 16) {
const elemVNode = subTree.children.find((vnode) => isElement(vnode.el)); const elemVNode = subTree.children.find((vnode) => vnode.el && isElement(vnode.el));
if (elemVNode) { if (elemVNode) {
return elemVNode.el; return elemVNode.el;
} }
......
...@@ -180,7 +180,7 @@ function resolveOwnerEl(instance) { ...@@ -180,7 +180,7 @@ function resolveOwnerEl(instance) {
const { subTree } = instance; const { subTree } = instance;
// ShapeFlags.ARRAY_CHILDREN = 1<<4 // ShapeFlags.ARRAY_CHILDREN = 1<<4
if (subTree.shapeFlag & 16) { if (subTree.shapeFlag & 16) {
const elemVNode = subTree.children.find((vnode) => isElement(vnode.el)); const elemVNode = subTree.children.find((vnode) => vnode.el && isElement(vnode.el));
if (elemVNode) { if (elemVNode) {
return elemVNode.el; return elemVNode.el;
} }
......
...@@ -30,8 +30,8 @@ export function resolveOwnerEl(instance: ComponentInternalInstance) { ...@@ -30,8 +30,8 @@ export function resolveOwnerEl(instance: ComponentInternalInstance) {
const { subTree } = instance const { subTree } = instance
// ShapeFlags.ARRAY_CHILDREN = 1<<4 // ShapeFlags.ARRAY_CHILDREN = 1<<4
if (subTree.shapeFlag & 16) { if (subTree.shapeFlag & 16) {
const elemVNode = (subTree.children as VNode[]).find((vnode) => const elemVNode = (subTree.children as VNode[]).find(
isElement(vnode.el as Element) (vnode) => vnode.el && isElement(vnode.el as Element)
) )
if (elemVNode) { if (elemVNode) {
return elemVNode.el return elemVNode.el
......
import path from 'path' import path from 'path'
import fs from 'fs-extra' import fs from 'fs-extra'
import { build as buildByVite, BuildOptions, InlineConfig } from 'vite' import { build as buildByVite, BuildOptions, InlineConfig } from 'vite'
import { extend } from '@vue/shared'
import { import {
initPreContext, initPreContext,
normalizeAppManifestJson, normalizeAppManifestJson,
...@@ -11,8 +12,20 @@ import { CliOptions } from '.' ...@@ -11,8 +12,20 @@ import { CliOptions } from '.'
import { addConfigFile, cleanOptions } from './utils' import { addConfigFile, cleanOptions } from './utils'
export async function build(options: CliOptions) { export async function build(options: CliOptions) {
if (options.platform === 'app' && (options as BuildOptions).manifest) { if (options.platform === 'app') {
return buildManifestJson() if ((options as BuildOptions).manifest) {
return buildManifestJson()
}
if (process.env.UNI_RENDERER === 'native') {
return buildByVite(
addConfigFile(
extend(
{ nvue: true },
initBuildOptions(options, cleanOptions(options) as BuildOptions)
)
)
)
}
} }
return buildByVite( return buildByVite(
addConfigFile( addConfigFile(
......
...@@ -10,12 +10,6 @@ export function initNVueEnv() { ...@@ -10,12 +10,6 @@ export function initNVueEnv() {
const manifestJson = parseManifestJsonOnce(process.env.UNI_INPUT_DIR) const manifestJson = parseManifestJsonOnce(process.env.UNI_INPUT_DIR)
if (getAppRenderer(manifestJson) === 'native') { if (getAppRenderer(manifestJson) === 'native') {
process.env.UNI_RENDERER = 'native' process.env.UNI_RENDERER = 'native'
return (
console.error(
`当前项目启用了纯原生渲染,请在manifest.json中切换vue版本为2之后,再重新运行。`
),
process.exit(1)
)
} }
const nvueCompiler = getNVueCompiler(manifestJson) const nvueCompiler = getNVueCompiler(manifestJson)
if (nvueCompiler === 'uni-app') { if (nvueCompiler === 'uni-app') {
......
...@@ -17,7 +17,11 @@ import { ...@@ -17,7 +17,11 @@ import {
import { createConfig } from './config' import { createConfig } from './config'
import { createConfigResolved } from './configResolved' import { createConfigResolved } from './configResolved'
import { uniCopyPlugin } from './plugins/copy' import { uniCopyPlugin } from './plugins/copy'
import { initExtraPlugins, initPluginUniOptions } from './utils' import {
initExtraPlugins,
initPluginUniOptions,
rewriteCompilerSfcParse,
} from './utils'
import { import {
initPluginViteLegacyOptions, initPluginViteLegacyOptions,
initPluginVueJsxOptions, initPluginVueJsxOptions,
...@@ -31,6 +35,8 @@ const pkg = require(path.resolve(__dirname, '../package.json')) ...@@ -31,6 +35,8 @@ const pkg = require(path.resolve(__dirname, '../package.json'))
initModuleAlias() initModuleAlias()
rewriteCompilerSfcParse()
process.env.UNI_COMPILER_VERSION = pkg['uni-app']?.['compilerVersion'] || '' process.env.UNI_COMPILER_VERSION = pkg['uni-app']?.['compilerVersion'] || ''
process.env.UNI_COMPILER_VERSION_TYPE = pkg.version.includes('alpha') process.env.UNI_COMPILER_VERSION_TYPE = pkg.version.includes('alpha')
? 'a' ? 'a'
......
export * from './filter' export * from './filter'
export * from './plugin' export * from './plugin'
export * from './polyfill'
import path from 'path'
import { EXTNAME_VUE, resolveBuiltIn } from '@dcloudio/uni-cli-shared'
import { SFCParseOptions } from '@vue/compiler-sfc'
/**
* TODO 临时重写,解决 @vitejs/plugin-vue 的 Bug
*/
export function rewriteCompilerSfcParse() {
// @ts-ignore
const compilerSfc = require(resolveBuiltIn('@vue/compiler-sfc'))
const { parse } = compilerSfc
compilerSfc.parse = (source: string, options: SFCParseOptions) => {
if (options.filename) {
const extname = path.extname(options.filename)
// wxs、filter、renderjs
if (extname && !EXTNAME_VUE.includes(extname)) {
const tag = extname.slice(1)
source = `<${tag}>` + source + `</${tag}>`
}
}
return parse(source, options)
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册