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

wip(app): uni-app-vite

上级 cb81e195
......@@ -148,6 +148,7 @@ declare namespace UniApp {
navigationBar: PageNavigationBar
refreshOptions?: PageRefreshOptions
onReachBottomDistance?: number
pageOrientation?: 'auto' | 'portrait' | 'landscape'
}
interface PageRouteMeta extends PagesJsonPageStyle {
id?: number
......@@ -194,6 +195,10 @@ declare namespace UniApp {
[name: string]: string
}
}
condition?: {
current?: number
list?: { name?: string; path: string; query?: string }[]
}
}
interface TabBarItemBaseOptions {
......
......@@ -705,7 +705,7 @@
}
};
}
const ServiceJSBridge = /* @__PURE__ */ extend(initBridge("service"), {
/* @__PURE__ */ extend(initBridge("service"), {
invokeOnCallback(name, res) {
return UniServiceJSBridge.emit("api." + name, res);
}
......@@ -1489,20 +1489,8 @@
resetSize
};
}
const canvasEventCallbacks = createCallbacks("canvasEvent");
ServiceJSBridge.subscribe("onCanvasMethodCallback", ({ callbackId, data }) => {
const callback = canvasEventCallbacks.pop(callbackId);
if (callback) {
callback(data);
}
});
const getSelectedTextRangeEventCallbacks = createCallbacks("getSelectedTextRangeEvent");
ServiceJSBridge.subscribe && ServiceJSBridge.subscribe("onGetSelectedTextRange", ({ callbackId, data }) => {
const callback = getSelectedTextRangeEventCallbacks.pop(callbackId);
if (callback) {
callback(data);
}
});
createCallbacks("canvasEvent");
createCallbacks("getSelectedTextRangeEvent");
function _isSlot(s) {
return typeof s === "function" || Object.prototype.toString.call(s) === "[object Object]" && !vue.isVNode(s);
}
......
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const plugin_1 = require("./plugin");
const copy_1 = require("./plugins/copy");
const mainJs_1 = require("./plugins/mainJs");
const manifestJson_1 = require("./plugins/manifestJson");
const pagesJson_1 = require("./plugins/pagesJson");
exports.default = [
copy_1.uniCopyPlugin(),
mainJs_1.uniMainJsPlugin(),
manifestJson_1.uniManifestJsonPlugin(),
pagesJson_1.uniPagesJsonPlugin(),
......
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.uniCopyPlugin = void 0;
const path_1 = __importDefault(require("path"));
const slash_1 = __importDefault(require("slash"));
const uni_cli_shared_1 = require("@dcloudio/uni-cli-shared");
function uniCopyPlugin() {
return uni_cli_shared_1.uniViteCopyPlugin({
targets: [
{
src: slash_1.default(path_1.default.resolve(__dirname, '../../lib/template/')),
dest: process.env.UNI_OUTPUT_DIR,
},
{
src: slash_1.default(require.resolve('@dcloudio/uni-app-plus/dist/style.css')),
dest: process.env.UNI_OUTPUT_DIR,
},
{
src: slash_1.default(require.resolve('@dcloudio/uni-app-plus/dist/uni-app-view.umd.js')),
dest: process.env.UNI_OUTPUT_DIR,
},
],
hook: 'writeBundle',
verbose: process.env.DEBUG ? true : false,
});
}
exports.uniCopyPlugin = uniCopyPlugin;
此差异已折叠。
此差异已折叠。
此差异已折叠。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>View</title>
<link rel="stylesheet" href="style.css" />
</head>
<body>
<div id="app"></div>
<script src="uni-app-view.umd.js"></script>
</body>
</html>
......@@ -6,7 +6,8 @@
"types": "dist/index.d.ts",
"files": [
"dist/**/*.js",
"dist/**/*.d.ts"
"dist/**/*.d.ts",
"lib"
],
"repository": {
"type": "git",
......
import { UniAppPlugin } from './plugin'
import { uniCopyPlugin } from './plugins/copy'
import { uniMainJsPlugin } from './plugins/mainJs'
import { uniManifestJsonPlugin } from './plugins/manifestJson'
import { uniPagesJsonPlugin } from './plugins/pagesJson'
export default [
uniCopyPlugin(),
uniMainJsPlugin(),
uniManifestJsonPlugin(),
uniPagesJsonPlugin(),
......
import path from 'path'
import slash from 'slash'
import { uniViteCopyPlugin } from '@dcloudio/uni-cli-shared'
export function uniCopyPlugin() {
return uniViteCopyPlugin({
targets: [
{
src: slash(path.resolve(__dirname, '../../lib/template/')),
dest: process.env.UNI_OUTPUT_DIR,
},
{
src: slash(require.resolve('@dcloudio/uni-app-plus/dist/style.css')),
dest: process.env.UNI_OUTPUT_DIR,
},
{
src: slash(
require.resolve('@dcloudio/uni-app-plus/dist/uni-app-view.umd.js')
),
dest: process.env.UNI_OUTPUT_DIR,
},
],
hook: 'writeBundle',
verbose: process.env.DEBUG ? true : false,
})
}
......@@ -25,6 +25,7 @@
"estree-walker": "^2.0.2",
"jsonc-parser": "^3.0.0",
"merge": "^2.1.1",
"rollup-plugin-copy": "^3.4.0",
"slash": "^3.0.0",
"tapable": "^2.2.0",
"xregexp": "3.1.0"
......
export function initArguments(
manifestJson: Record<string, any>,
pagesJson: Record<string, any>
pagesJson: UniApp.PagesJson
) {
if (process.env.NODE_ENV !== 'development') {
return
}
// 指定了入口
if (process.env.UNI_CLI_LAUNCH_PAGE_PATH) {
manifestJson.plus.arguments = JSON.stringify({
path: process.env.UNI_CLI_LAUNCH_PAGE_PATH,
query: process.env.UNI_CLI_LAUNCH_PAGE_QUERY,
})
return
}
const condition = pagesJson.condition
if (condition && Array.isArray(condition.list) && condition.list.length) {
if (condition && condition.list?.length) {
const list = condition.list
let current = parseInt(condition.current) || 0
let current = condition.current || 0
if (current < 0) {
current = 0
}
......
import path from 'path'
export function initConfusion(manifestJson: Record<string, any>) {
if (!manifestJson.plus.confusion?.resources) {
return
}
const resources = manifestJson.plus.confusion.resources as Record<
string,
string
>
manifestJson.plus.confusion.resources = Object.keys(resources).reduce(
(res, name) => {
const extname = path.extname(name)
if (extname === '.nvue') {
res[name.replace('.nvue', '.js')] = resources[name]
} else if (extname === '.js') {
// 仅指定目录的js允许加密
if (
name.indexOf('hybrid/html') === 0 ||
name.indexOf('static/') === 0 ||
name.indexOf('/static/') !== -1 // subpackages, uni_modules 中的 static 目录
) {
res[name] = resources[name]
}
} else {
throw new Error(`原生混淆仅支持 nvue 页面,错误的页面路径:${name}`)
}
// TODO 旧编译器会检查要加密的 nvue 页面(包括subnvue)是否被使用?后续有时间再考虑支持吧,意义不太大
return res
},
{} as Record<string, string>
)
}
......@@ -15,7 +15,6 @@ const defaultManifestJson = `{
"code": ""
},
"description": "",
"launch_path": "__uniappservice.html",
"developer": {
"name": "",
"email": "",
......
......@@ -6,20 +6,29 @@ import { initNVue } from './nvue'
import { initArguments } from './arguments'
import { initSafearea } from './safearea'
import { initSplashscreen } from './splashscreen'
import { initConfusion } from './confusion'
import { initUniApp } from './uniApp'
import { initLaunchwebview } from './launchwebview'
import { initTabBar } from './tabBar'
export function normalizeAppManifestJson(
userManifestJson: Record<string, any>,
pagesJson: Record<string, any>
pagesJson: UniApp.PagesJson
) {
const manifestJson = initDefaultManifestJson()
const manifestJson = initRecursiveMerge(
initAppStatusbar(initDefaultManifestJson(), pagesJson),
userManifestJson
)
initAppStatusbar(manifestJson, pagesJson)
initRecursiveMerge(manifestJson, userManifestJson)
initArguments(manifestJson, pagesJson)
initPlus(manifestJson, userManifestJson)
initPlus(manifestJson, pagesJson)
initNVue(manifestJson, pagesJson)
initSafearea(manifestJson, pagesJson)
initSplashscreen(manifestJson, userManifestJson)
initConfusion(manifestJson)
initUniApp(manifestJson)
initLaunchwebview(manifestJson, pagesJson) // 依赖 initArguments 先执行
initTabBar(manifestJson, pagesJson) // 依赖 initLaunchwebview 先执行
return manifestJson
}
......
import { extend } from '@vue/shared'
export function initLaunchwebview(
manifestJson: Record<string, any>,
pagesJson: UniApp.PagesJson
) {
let entryPagePath = pagesJson.pages[0].path
// 依赖前置执行initArguments
if (manifestJson.plus.arguments) {
try {
const args = JSON.parse(manifestJson.plus.arguments)
if (args.path) {
entryPagePath = args.path
}
} catch (e) {}
}
// 标记入口页,方便后边的 initTabBar 使用
process.env.UNI_ENTRY_PAGE_PATH = entryPagePath
manifestJson.plus.useragent.value = 'uni-app'
manifestJson.launch_path = '__uniappview.html'
extend(manifestJson.plus.launchwebview, {
id: '1',
kernel: 'WKWebview',
})
// TODO 纯原生渲染
// TODO 首页为nvue
// manifestJson.plus.launchwebview.uniNView = {path:'.js'}
// manifestJson.plus.launchwebview.id = '2'
}
......@@ -3,8 +3,8 @@ import { recursive } from 'merge'
export function initRecursiveMerge(
manifestJson: Record<string, any>,
userManifestJson: Record<string, any>
) {
recursive(
): Record<string, any> {
return recursive(
true,
manifestJson,
{
......
export function initNVue(
manifestJson: Record<string, any>,
pagesJson: Record<string, any>
pagesJson: UniApp.PagesJson
) {}
export function getNVueCompiler(manifestJson: Record<string, any>) {
......
......@@ -11,7 +11,7 @@ const wxPageOrientationMapping = {
export function initPlus(
manifestJson: Record<string, any>,
pagesJson: Record<string, any>
pagesJson: UniApp.PagesJson
) {
// 转换为老版本配置
if (manifestJson.plus.modules) {
......@@ -39,7 +39,7 @@ export function initPlus(
// app平台优先使用 manifest 配置
manifestJson.screenOrientation = manifestJson.plus.screenOrientation
delete manifestJson.plus.screenOrientation
} else if (pagesJson.globalStyle && pagesJson.globalStyle.pageOrientation) {
} else if (pagesJson.globalStyle?.pageOrientation) {
// 兼容微信小程序
const pageOrientationValue =
wxPageOrientationMapping[
......@@ -69,4 +69,26 @@ export function initPlus(
// 允许内联播放视频
manifestJson.plus.allowsInlineMediaPlayback = true
if (!manifestJson.plus.distribute) {
manifestJson.plus.distribute = {
plugins: {},
}
}
if (!manifestJson.plus.distribute.plugins) {
manifestJson.plus.distribute.plugins = {}
}
// 录音支持 mp3
manifestJson.plus.distribute.plugins.audio = {
mp3: {
description: 'Android平台录音支持MP3格式文件',
},
}
// 有效值为 close,none
if (!['close', 'none'].includes(manifestJson.plus.popGesture)) {
manifestJson.plus.popGesture = 'close'
}
}
export function initSafearea(
manifestJson: Record<string, any>,
pagesJson: Record<string, any>
pagesJson: UniApp.PagesJson
) {
if (
pagesJson.tabBar &&
pagesJson.tabBar.list &&
pagesJson.tabBar.list.length
) {
if (pagesJson.tabBar?.list?.length) {
// 安全区配置 仅包含 tabBar 的时候才配置
if (!manifestJson.plus.safearea) {
manifestJson.plus.safearea = {
......
export function initAppStatusbar(
manifestJson: Record<string, any>,
pagesJson: Record<string, any>
pagesJson: UniApp.PagesJson
) {
const {
navigationBarTextStyle = 'white',
navigationBarBackgroundColor = '#000000',
} = pagesJson.globalStyle || {}
const { titleColor = '#000', backgroundColor = '#000000' } =
pagesJson.globalStyle?.navigationBar || {}
manifestJson.plus.statusbar = {
immersed: 'supportedDevice',
style: navigationBarTextStyle === 'black' ? 'dark' : 'light',
background: navigationBarBackgroundColor,
style: titleColor === '#000' ? 'dark' : 'light',
background: backgroundColor,
}
return manifestJson
}
此差异已折叠。
此差异已折叠。
......@@ -55,5 +55,6 @@ export function normalizeAppUniConfig(
entryPagePath: '', //TODO
networkTimeout: normalizeNetworkTimeout(manifestJson.networkTimeout),
}
// TODO 待支持分包
return JSON.stringify(config)
}
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册