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

wip(app): uni-app-vite

上级 09db687b
......@@ -4,5 +4,6 @@ declare namespace NodeJS {
UNI_INPUT_DIR: string
UNI_OUTPUT_DIR: string
UNI_CLI_CONTEXT: string
UNI_COMPILER_VERSION: string
}
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const uni_shared_1 = require("@dcloudio/uni-shared");
const uni_cli_shared_1 = require("@dcloudio/uni-cli-shared");
const plugin_1 = require("./plugin");
const mainJs_1 = require("./plugins/mainJs");
const manifestJson_1 = require("./plugins/manifestJson");
const pagesJson_1 = require("./plugins/pagesJson");
const UniAppPlugin = {
name: 'vite:uni-app',
uni: {
compilerOptions: {
isNativeTag: uni_shared_1.isServiceNativeTag,
isCustomElement: uni_shared_1.isServiceCustomElement,
},
transformEvent: {
tap: 'click',
},
},
config() {
return {
build: {
lib: {
name: 'AppService',
entry: uni_cli_shared_1.resolveMainPathOnce(process.env.UNI_INPUT_DIR),
formats: ['iife'],
},
rollupOptions: {
external: ['vue'],
output: {
entryFileNames: 'app-service.js',
globals: {
vue: 'Vue',
},
},
},
},
};
},
};
exports.default = [
mainJs_1.uniMainJsPlugin(),
manifestJson_1.uniManifestJsonPlugin(),
pagesJson_1.uniPagesJsonPlugin(),
UniAppPlugin,
plugin_1.UniAppPlugin,
];
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.UniAppPlugin = void 0;
const uni_shared_1 = require("@dcloudio/uni-shared");
const uni_cli_shared_1 = require("@dcloudio/uni-cli-shared");
exports.UniAppPlugin = {
name: 'vite:uni-app',
uni: {
compilerOptions: {
isNativeTag: uni_shared_1.isServiceNativeTag,
isCustomElement: uni_shared_1.isServiceCustomElement,
},
transformEvent: {
tap: 'click',
},
},
config() {
return {
build: {
lib: {
name: 'AppService',
entry: uni_cli_shared_1.resolveMainPathOnce(process.env.UNI_INPUT_DIR),
formats: ['iife'],
},
rollupOptions: {
external: ['vue'],
output: {
entryFileNames: 'app-service.js',
globals: {
vue: 'Vue',
},
},
},
},
};
},
configResolved() {
const manifestJson = uni_cli_shared_1.parseManifestJsonOnce(process.env.UNI_INPUT_DIR);
if (uni_cli_shared_1.getNVueCompiler(manifestJson) === 'uni-app') {
process.env.UNI_USING_NVUE_COMPILER = 'uni-app';
}
if (uni_cli_shared_1.getNVueStyleCompiler(manifestJson) === 'uni-app') {
process.env.UNI_USING_NVUE_STYLE_COMPILER = 'uni-app';
}
},
};
......@@ -12,7 +12,7 @@ function uniManifestJsonPlugin() {
if (!opts.filter(id)) {
return;
}
manifestJson = uni_cli_shared_1.normalizeAppManifestJson(JSON.parse(code));
manifestJson = uni_cli_shared_1.normalizeAppManifestJson(JSON.parse(code), uni_cli_shared_1.parsePagesJsonOnce(process.env.UNI_INPUT_DIR, process.env.UNI_PLATFORM));
return '';
},
generateBundle() {
......
......@@ -19,7 +19,7 @@ function uniPagesJsonPlugin() {
this.emitFile({
fileName: `app-config-service.js`,
type: 'asset',
source: uni_cli_shared_1.normalizeAppConfigService(pagesJson),
source: uni_cli_shared_1.normalizeAppConfigService(pagesJson, uni_cli_shared_1.parseManifestJsonOnce(process.env.UNI_INPUT_DIR)),
});
},
};
......
import {
isServiceNativeTag,
isServiceCustomElement,
} from '@dcloudio/uni-shared'
import { resolveMainPathOnce, UniVitePlugin } from '@dcloudio/uni-cli-shared'
import { UniAppPlugin } from './plugin'
import { uniMainJsPlugin } from './plugins/mainJs'
import { uniManifestJsonPlugin } from './plugins/manifestJson'
import { uniPagesJsonPlugin } from './plugins/pagesJson'
const UniAppPlugin: UniVitePlugin = {
name: 'vite:uni-app',
uni: {
compilerOptions: {
isNativeTag: isServiceNativeTag,
isCustomElement: isServiceCustomElement,
},
transformEvent: {
tap: 'click',
},
},
config() {
return {
build: {
lib: {
name: 'AppService',
entry: resolveMainPathOnce(process.env.UNI_INPUT_DIR),
formats: ['iife'],
},
rollupOptions: {
external: ['vue'],
output: {
entryFileNames: 'app-service.js',
globals: {
vue: 'Vue',
},
},
},
},
}
},
}
export default [
uniMainJsPlugin(),
uniManifestJsonPlugin(),
......
import {
isServiceNativeTag,
isServiceCustomElement,
} from '@dcloudio/uni-shared'
import {
parseManifestJsonOnce,
resolveMainPathOnce,
UniVitePlugin,
getNVueCompiler,
getNVueStyleCompiler,
} from '@dcloudio/uni-cli-shared'
export const UniAppPlugin: UniVitePlugin = {
name: 'vite:uni-app',
uni: {
compilerOptions: {
isNativeTag: isServiceNativeTag,
isCustomElement: isServiceCustomElement,
},
transformEvent: {
tap: 'click',
},
},
config() {
return {
build: {
lib: {
name: 'AppService',
entry: resolveMainPathOnce(process.env.UNI_INPUT_DIR),
formats: ['iife'],
},
rollupOptions: {
external: ['vue'],
output: {
entryFileNames: 'app-service.js',
globals: {
vue: 'Vue',
},
},
},
},
}
},
configResolved() {
const manifestJson = parseManifestJsonOnce(process.env.UNI_INPUT_DIR)
if (getNVueCompiler(manifestJson) === 'uni-app') {
process.env.UNI_USING_NVUE_COMPILER = 'uni-app'
}
if (getNVueStyleCompiler(manifestJson) === 'uni-app') {
process.env.UNI_USING_NVUE_STYLE_COMPILER = 'uni-app'
}
},
}
......@@ -3,6 +3,7 @@ import { Plugin } from 'vite'
import {
defineUniManifestJsonPlugin,
normalizeAppManifestJson,
parsePagesJsonOnce,
} from '@dcloudio/uni-cli-shared'
export function uniManifestJsonPlugin(): Plugin {
......@@ -15,7 +16,13 @@ export function uniManifestJsonPlugin(): Plugin {
if (!opts.filter(id)) {
return
}
manifestJson = normalizeAppManifestJson(JSON.parse(code))
manifestJson = normalizeAppManifestJson(
JSON.parse(code),
parsePagesJsonOnce(
process.env.UNI_INPUT_DIR,
process.env.UNI_PLATFORM
)
)
return ''
},
generateBundle() {
......
......@@ -5,6 +5,7 @@ import {
normalizeAppPagesJson,
normalizeAppConfigService,
normalizePagesJson,
parseManifestJsonOnce,
} from '@dcloudio/uni-cli-shared'
export function uniPagesJsonPlugin(): Plugin {
......@@ -26,7 +27,10 @@ export function uniPagesJsonPlugin(): Plugin {
this.emitFile({
fileName: `app-config-service.js`,
type: 'asset',
source: normalizeAppConfigService(pagesJson),
source: normalizeAppConfigService(
pagesJson,
parseManifestJsonOnce(process.env.UNI_INPUT_DIR)
),
})
},
}
......
export function initArguments(
manifestJson: Record<string, any>,
pagesJson: Record<string, any>
) {
if (process.env.NODE_ENV !== 'development') {
return
}
const condition = pagesJson.condition
if (condition && Array.isArray(condition.list) && condition.list.length) {
const list = condition.list
let current = parseInt(condition.current) || 0
if (current < 0) {
current = 0
}
if (current >= list.length) {
current = 0
}
manifestJson.plus.arguments = JSON.stringify(list[current])
}
}
import { recursive } from 'merge'
export function normalizeAppManifestJson(
userManifestJson: Record<string, any>
) {
const manifestJson = getDefaultManifestJson()
recursive(
true,
manifestJson,
{
id: userManifestJson.appid || '',
name: userManifestJson.name || '',
description: userManifestJson.description || '',
version: {
name: userManifestJson.versionName,
code: userManifestJson.versionCode,
},
},
{ plus: userManifestJson['app-plus'] }
)
return manifestJson
export function initDefaultManifestJson() {
return JSON.parse(defaultManifestJson)
}
const defaultManifestJson = `{
......@@ -55,7 +37,3 @@ const defaultManifestJson = `{
"launchwebview": {}
}
}`
function getDefaultManifestJson() {
return JSON.parse(defaultManifestJson)
}
import { initRecursiveMerge } from './merge'
import { initDefaultManifestJson } from './defaultManifestJson'
import { initAppStatusbar } from './statusbar'
import { initPlus } from './plus'
import { initNVue } from './nvue'
import { initArguments } from './arguments'
import { initSafearea } from './safearea'
import { initSplashscreen } from './splashscreen'
export function normalizeAppManifestJson(
userManifestJson: Record<string, any>,
pagesJson: Record<string, any>
) {
const manifestJson = initDefaultManifestJson()
initAppStatusbar(manifestJson, pagesJson)
initRecursiveMerge(manifestJson, userManifestJson)
initArguments(manifestJson, pagesJson)
initPlus(manifestJson, userManifestJson)
initNVue(manifestJson, pagesJson)
initSafearea(manifestJson, pagesJson)
initSplashscreen(manifestJson, userManifestJson)
return manifestJson
}
export {
getNVueCompiler,
getNVueStyleCompiler,
getNVueFlexDirection,
} from './nvue'
import { recursive } from 'merge'
export function initRecursiveMerge(
manifestJson: Record<string, any>,
userManifestJson: Record<string, any>
) {
recursive(
true,
manifestJson,
{
id: userManifestJson.appid || '',
name: userManifestJson.name || '',
description: userManifestJson.description || '',
version: {
name: userManifestJson.versionName,
code: userManifestJson.versionCode,
},
},
{ plus: userManifestJson['app-plus'] }
)
}
export function initNVue(
manifestJson: Record<string, any>,
pagesJson: Record<string, any>
) {}
export function getNVueCompiler(manifestJson: Record<string, any>) {
const platformOptions = manifestJson['app-plus']
if (platformOptions && platformOptions.nvueCompiler === 'weex') {
return 'weex'
}
return 'uni-app'
}
export function getNVueStyleCompiler(manifestJson: Record<string, any>) {
const platformOptions = manifestJson['app-plus']
if (platformOptions && platformOptions.nvueStyleCompiler === 'uni-app') {
return 'uni-app'
}
return 'weex'
}
const flexDirs = ['row', 'row-reverse', 'column', 'column-reverse'] as const
type FlexDir = typeof flexDirs[number]
export function getNVueFlexDirection(manifestJson: Record<string, any>) {
let flexDir: FlexDir = 'column'
if (manifestJson['app-plus']?.nvue?.['flex-direction']) {
flexDir = manifestJson['app-plus'].nvue['flex-direction'] as FlexDir
if (flexDirs.indexOf(flexDir) === -1) {
flexDir = 'column'
}
}
return flexDir
}
const wxPageOrientationMapping = {
auto: [
'portrait-primary',
'portrait-secondary',
'landscape-primary',
'landscape-secondary',
],
portrait: ['portrait-primary', 'portrait-secondary'],
landscape: ['landscape-primary', 'landscape-secondary'],
}
export function initPlus(
manifestJson: Record<string, any>,
pagesJson: Record<string, any>
) {
// 转换为老版本配置
if (manifestJson.plus.modules) {
manifestJson.permissions = manifestJson.plus.modules
delete manifestJson.plus.modules
}
const distribute = manifestJson.plus.distribute
if (distribute) {
if (distribute.android) {
manifestJson.plus.distribute.google = distribute.android
delete manifestJson.plus.distribute.android
}
if (distribute.ios) {
manifestJson.plus.distribute.apple = distribute.ios
delete manifestJson.plus.distribute.ios
}
if (distribute.sdkConfigs) {
manifestJson.plus.distribute.plugins = distribute.sdkConfigs
delete manifestJson.plus.distribute.sdkConfigs
}
}
// 屏幕启动方向
if (manifestJson.plus.screenOrientation) {
// app平台优先使用 manifest 配置
manifestJson.screenOrientation = manifestJson.plus.screenOrientation
delete manifestJson.plus.screenOrientation
} else if (pagesJson.globalStyle && pagesJson.globalStyle.pageOrientation) {
// 兼容微信小程序
const pageOrientationValue =
wxPageOrientationMapping[
pagesJson.globalStyle
.pageOrientation as keyof typeof wxPageOrientationMapping
]
if (pageOrientationValue) {
manifestJson.screenOrientation = pageOrientationValue
}
}
// 全屏配置
manifestJson.fullscreen = manifestJson.plus.fullscreen
// 地图坐标系
if (manifestJson.permissions && manifestJson.permissions.Maps) {
manifestJson.permissions.Maps.coordType = 'gcj02'
}
if (!manifestJson.permissions) {
manifestJson.permissions = {}
}
manifestJson.permissions.UniNView = {
description: 'UniNView原生渲染',
}
// 允许内联播放视频
manifestJson.plus.allowsInlineMediaPlayback = true
}
export function initSafearea(
manifestJson: Record<string, any>,
pagesJson: Record<string, any>
) {
if (
pagesJson.tabBar &&
pagesJson.tabBar.list &&
pagesJson.tabBar.list.length
) {
// 安全区配置 仅包含 tabBar 的时候才配置
if (!manifestJson.plus.safearea) {
manifestJson.plus.safearea = {
background: pagesJson.tabBar.backgroundColor || '#FFFFFF',
bottom: {
offset: 'auto',
},
}
}
} else {
if (!manifestJson.plus.launchwebview) {
manifestJson.plus.launchwebview = {
render: 'always',
}
} else if (!manifestJson.plus.launchwebview.render) {
manifestJson.plus.launchwebview.render = 'always'
}
}
}
import { hasOwn } from '@vue/shared'
export function initSplashscreen(
manifestJson: Record<string, any>,
userManifestJson: Record<string, any>
) {
if (!manifestJson.plus.splashscreen) {
return
}
// 强制白屏检测
const splashscreenOptions =
userManifestJson['app-plus'] && userManifestJson['app-plus'].splashscreen
const hasAlwaysShowBeforeRender =
splashscreenOptions && hasOwn(splashscreenOptions, 'alwaysShowBeforeRender')
if (
!hasAlwaysShowBeforeRender &&
manifestJson.plus.splashscreen.autoclose === false
) {
// 兼容旧版本仅配置了 autoclose 为 false
manifestJson.plus.splashscreen.alwaysShowBeforeRender = false
}
if (manifestJson.plus.splashscreen.alwaysShowBeforeRender) {
// 白屏检测
if (!manifestJson.plus.splashscreen.target) {
manifestJson.plus.splashscreen.target = 'id:1'
}
manifestJson.plus.splashscreen.autoclose = true
manifestJson.plus.splashscreen.delay = 0
// 简单起见,直接设置环境变量,这样生成uniConfig时,直接读取判断
process.env.UNI_SPLASHSCREEN_ALWAYSSHOWBEFORERENDER = 'true'
} else {
// 不启用白屏检测
delete manifestJson.plus.splashscreen.target
if (manifestJson.plus.splashscreen.autoclose) {
// 启用 uni-app 框架关闭 splash
manifestJson.plus.splashscreen.autoclose = false // 原 5+ autoclose 改为 false
// 简单起见,直接设置环境变量,这样生成uniConfig时,直接读取判断
process.env.UNI_SPLASHSCREEN_AUTOCLOSE = 'true'
}
}
delete manifestJson.plus.splashscreen.alwaysShowBeforeRender
}
export function initAppStatusbar(
manifestJson: Record<string, any>,
pagesJson: Record<string, any>
) {
const {
navigationBarTextStyle = 'white',
navigationBarBackgroundColor = '#000000',
} = pagesJson.globalStyle || {}
manifestJson.plus.statusbar = {
immersed: 'supportedDevice',
style: navigationBarTextStyle === 'black' ? 'dark' : 'light',
background: navigationBarBackgroundColor,
}
}
import { normalizeIdentifier } from '../../utils'
import { normalizePagesRoute } from '../pages'
export function normalizeAppPagesJson(pagesJson: Record<string, any>) {
return polyfillCode + restoreGlobalCode + definePageCode(pagesJson)
}
function definePageCode(pagesJson: Record<string, any>) {
const importPagesCode: string[] = []
const definePagesCode: string[] = []
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})`)
})
return importPagesCode.join('\n') + '\n' + definePagesCode.join('\n')
}
const polyfillCode = `
if (typeof Promise !== 'undefined' && !Promise.prototype.finally) {
Promise.prototype.finally = function(callback) {
const promise = this.constructor
return this.then(
value => promise.resolve(callback()).then(() => value),
reason => promise.resolve(callback()).then(() => {
throw reason
})
)
}
}
`
const restoreGlobalCode = `
if(uni.restoreGlobal){
uni.restoreGlobal(weex,plus,setTimeout,clearTimeout,setInterval,clearInterval)
}
`
export function normalizeAppConfigService(pagesJson: UniApp.PagesJson) {
return `
;(function(){
const u=void 0,isReady=false,onReadyCallbacks=[],isServiceReady=false,onServiceReadyCallbacks=[];
const __uniConfig = ${normalizeAppUniConfig(pagesJson)};
const __uniRoutes = ${normalizeAppUniRoutes(pagesJson)};
__uniConfig.onReady=function(callback){if(__uniConfig.ready){callback()}else{onReadyCallbacks.push(callback)}};Object.defineProperty(__uniConfig,"ready",{get:function(){return isReady},set:function(val){isReady=val;if(!isReady){return}const callbacks=onReadyCallbacks.slice(0);onReadyCallbacks.length=0;callbacks.forEach(function(callback){callback()})}});
__uniConfig.onServiceReady=function(callback){if(__uniConfig.serviceReady){callback()}else{onServiceReadyCallbacks.push(callback)}};Object.defineProperty(__uniConfig,"serviceReady",{get:function(){return isServiceReady},set:function(val){isServiceReady=val;if(!isServiceReady){return}const callbacks=onServiceReadyCallbacks.slice(0);onServiceReadyCallbacks.length=0;callbacks.forEach(function(callback){callback()})}});
service.register("uni-app-config",{create(a,b,c){if(!__uniConfig.viewport){var d=b.weex.config.env.scale,e=b.weex.config.env.deviceWidth,f=Math.ceil(e/d);Object.assign(__uniConfig,{viewport:f,defaultFontSize:Math.round(f/20)})}return{instance:{__uniConfig:__uniConfig,__uniRoutes:__uniRoutes,${normalizeGlobalStatement(
GLOBALS
)}}}}});
})();
`
}
function normalizeAppUniConfig(pagesJson: UniApp.PagesJson) {
return JSON.stringify(pagesJson.globalStyle)
}
function normalizeAppUniRoutes(pagesJson: UniApp.PagesJson) {
return JSON.stringify(normalizePagesRoute(pagesJson))
}
function normalizeGlobalStatement(globals: string[]) {
return globals.map((g) => `${g}:u`).join(',')
}
const GLOBALS = [
'global',
'window',
'document',
'frames',
'self',
'location',
'navigator',
'localStorage',
'history',
'Caches',
'screen',
'alert',
'confirm',
'prompt',
'fetch',
'XMLHttpRequest',
'WebSocket',
'webkit',
'print',
]
export const polyfillCode = `
if (typeof Promise !== 'undefined' && !Promise.prototype.finally) {
Promise.prototype.finally = function(callback) {
const promise = this.constructor
return this.then(
value => promise.resolve(callback()).then(() => value),
reason => promise.resolve(callback()).then(() => {
throw reason
})
)
}
}
`
export const restoreGlobalCode = `
if(uni.restoreGlobal){
uni.restoreGlobal(weex,plus,setTimeout,clearTimeout,setInterval,clearInterval)
}
`
const GLOBALS = [
'global',
'window',
'document',
'frames',
'self',
'location',
'navigator',
'localStorage',
'history',
'Caches',
'screen',
'alert',
'confirm',
'prompt',
'fetch',
'XMLHttpRequest',
'WebSocket',
'webkit',
'print',
]
export const globalCode = GLOBALS.map((g) => `${g}:u`).join(',')
import { normalizeIdentifier } from '../../../utils'
export function definePageCode(pagesJson: Record<string, any>) {
const importPagesCode: string[] = []
const definePagesCode: string[] = []
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})`)
})
return importPagesCode.join('\n') + '\n' + definePagesCode.join('\n')
}
import { globalCode, polyfillCode, restoreGlobalCode } from './code'
import { definePageCode } from './definePage'
import { normalizeAppUniConfig } from './uniConfig'
import { normalizeAppUniRoutes } from './uniRoutes'
export function normalizeAppPagesJson(pagesJson: Record<string, any>) {
return polyfillCode + restoreGlobalCode + definePageCode(pagesJson)
}
export function normalizeAppConfigService(
pagesJson: UniApp.PagesJson,
manifestJson: Record<string, any>
) {
return `
;(function(){
const u=void 0,isReady=false,onReadyCallbacks=[],isServiceReady=false,onServiceReadyCallbacks=[];
const __uniConfig = ${normalizeAppUniConfig(pagesJson, manifestJson)};
const __uniRoutes = ${normalizeAppUniRoutes(
pagesJson
)}.map(uniRoute=>(uniRoute.meta.route=uniRoute.path,__uniConfig.pages.push(uniRoute.path),uniRoute.path='/'+uniRoute.path,uniRoute));
__uniConfig.onReady=function(callback){if(__uniConfig.ready){callback()}else{onReadyCallbacks.push(callback)}};Object.defineProperty(__uniConfig,"ready",{get:function(){return isReady},set:function(val){isReady=val;if(!isReady){return}const callbacks=onReadyCallbacks.slice(0);onReadyCallbacks.length=0;callbacks.forEach(function(callback){callback()})}});
__uniConfig.onServiceReady=function(callback){if(__uniConfig.serviceReady){callback()}else{onServiceReadyCallbacks.push(callback)}};Object.defineProperty(__uniConfig,"serviceReady",{get:function(){return isServiceReady},set:function(val){isServiceReady=val;if(!isServiceReady){return}const callbacks=onServiceReadyCallbacks.slice(0);onServiceReadyCallbacks.length=0;callbacks.forEach(function(callback){callback()})}});
service.register("uni-app-config",{create(a,b,c){if(!__uniConfig.viewport){var d=b.weex.config.env.scale,e=b.weex.config.env.deviceWidth,f=Math.ceil(e/d);Object.assign(__uniConfig,{viewport:f,defaultFontSize:Math.round(f/20)})}return{instance:{__uniConfig:__uniConfig,__uniRoutes:__uniRoutes,${globalCode}}}}});
})();
`
}
import { normalizeNetworkTimeout } from '../../manifest'
import {
getNVueCompiler,
getNVueFlexDirection,
getNVueStyleCompiler,
} from '../manifest'
interface AppUniConfig {
pages: string[]
window: UniApp.PagesJsonPageStyle
nvue: {
compiler: 'uni-app' | 'weex'
styleCompiler: 'weex' | 'uni-app'
'flex-direction': 'row' | 'row-reverse' | 'column' | 'column-reverse'
}
renderer: 'auto' | 'native'
splashscreen: {
alwaysShowBeforeRender: boolean
autoclose: boolean
}
appname: string
compilerVersion: string
entryPagePath: string
networkTimeout: {
request: number
connectSocket: number
uploadFile: number
downloadFile: number
}
}
export function normalizeAppUniConfig(
pagesJson: UniApp.PagesJson,
manifestJson: Record<string, any>
) {
const config: AppUniConfig = {
pages: [],
window: pagesJson.globalStyle,
nvue: {
compiler: getNVueCompiler(manifestJson),
styleCompiler: getNVueStyleCompiler(manifestJson),
'flex-direction': getNVueFlexDirection(manifestJson),
},
renderer:
manifestJson['app-plus']?.renderer === 'native' ? 'native' : 'auto',
appname: manifestJson.name || '',
splashscreen: {
alwaysShowBeforeRender: process.env
.UNI_SPLASHSCREEN_ALWAYSSHOWBEFORERENDER
? true
: false,
autoclose: process.env.UNI_SPLASHSCREEN_AUTOCLOSE ? true : false,
},
compilerVersion: process.env.UNI_COMPILER_VERSION,
entryPagePath: '', //TODO
networkTimeout: normalizeNetworkTimeout(manifestJson.networkTimeout),
}
return JSON.stringify(config)
}
import { normalizePagesRoute } from '../../pages'
export function normalizeAppUniRoutes(pagesJson: UniApp.PagesJson) {
return JSON.stringify(normalizePagesRoute(pagesJson))
}
......@@ -26,3 +26,19 @@ function parseCompatConfig(inputDir: string): CompilerCompatConfig {
}
export const parseCompatConfigOnce = once(parseCompatConfig)
const defaultNetworkTimeout = {
request: 60000,
connectSocket: 60000,
uploadFile: 60000,
downloadFile: 60000,
}
export function normalizeNetworkTimeout(
networkTimeout?: Partial<typeof defaultNetworkTimeout>
) {
return {
...defaultNetworkTimeout,
...networkTimeout,
}
}
......@@ -300,16 +300,15 @@ export function normalizePagesRoute(
let windowTop = 0
const meta = extend(
{
route: pageOptions.path,
isNVue: isNVue ? true : undefined,
isNVue: isNVue || undefined,
isQuit: isEntry || isTabBar ? true : undefined,
isEntry,
isTabBar,
tabBarIndex,
windowTop,
isEntry: isEntry || undefined,
isTabBar: isTabBar || undefined,
tabBarIndex: isTabBar ? tabBarIndex : undefined,
windowTop: windowTop || undefined,
},
pageOptions.style
)
) as UniApp.PageRouteMeta
return {
path: pageOptions.path,
meta,
......
......@@ -13,12 +13,6 @@ const defaultAsync = {
timeout: 60000,
suspensible: true,
};
const defaultNetworkTimeout = {
request: 60000,
connectSocket: 60000,
uploadFile: 60000,
downloadFile: 60000,
};
const defaultQQMapKey = 'XVXBZ-NDMC4-JOGUS-XGIEE-QVHDZ-AMFV2';
function uniManifestJsonPlugin() {
return uni_cli_shared_1.defineUniManifestJsonPlugin((opts) => {
......@@ -37,7 +31,7 @@ function uniManifestJsonPlugin() {
router.base = '/';
}
const async = Object.assign(Object.assign({}, defaultAsync), ((h5 && h5.async) || {}));
const networkTimeout = Object.assign(Object.assign({}, defaultNetworkTimeout), (manifest.networkTimeout || {}));
const networkTimeout = uni_cli_shared_1.normalizeNetworkTimeout(manifest.networkTimeout);
const sdkConfigs = (h5 && h5.sdkConfigs) || {};
const qqMapKey = (sdkConfigs.maps &&
sdkConfigs.maps.qqmap &&
......
......@@ -150,7 +150,7 @@ function generatePagesDefineCode(pagesJson, _config) {
}
` + pages.map((pageOptions) => generatePageDefineCode(pageOptions)).join('\n'));
}
function generatePageRoute({ path, meta }, config) {
function generatePageRoute({ path, meta }, _config) {
const { isEntry } = meta;
const alias = isEntry ? `\n alias:'/${path}',` : '';
return `{
......@@ -170,7 +170,7 @@ function renderPage(component){
}
${globalName}.__uniRoutes=[${[
...generatePagesRoute(uni_cli_shared_1.normalizePagesRoute(pagesJson), config),
].join(',')}]`;
].join(',')}].map(uniRoute=>(uniRoute.meta.route = (uniRoute.alias || uniRoute.path).substr(1),uniRoute))`;
}
function generateConfig(globalName, pagesJson, config) {
delete pagesJson.pages;
......
import { Plugin } from 'vite'
import { defineUniManifestJsonPlugin } from '@dcloudio/uni-cli-shared'
import {
defineUniManifestJsonPlugin,
normalizeNetworkTimeout,
} from '@dcloudio/uni-cli-shared'
const defaultRouter = {
mode: 'hash',
......@@ -15,13 +18,6 @@ const defaultAsync = {
suspensible: true,
}
const defaultNetworkTimeout = {
request: 60000,
connectSocket: 60000,
uploadFile: 60000,
downloadFile: 60000,
}
const defaultQQMapKey = 'XVXBZ-NDMC4-JOGUS-XGIEE-QVHDZ-AMFV2'
export function uniManifestJsonPlugin(): Plugin {
......@@ -42,10 +38,7 @@ export function uniManifestJsonPlugin(): Plugin {
}
const async = { ...defaultAsync, ...((h5 && h5.async) || {}) }
const networkTimeout = {
...defaultNetworkTimeout,
...(manifest.networkTimeout || {}),
}
const networkTimeout = normalizeNetworkTimeout(manifest.networkTimeout)
const sdkConfigs = (h5 && h5.sdkConfigs) || {}
......
......@@ -185,7 +185,7 @@ function generatePagesDefineCode(
function generatePageRoute(
{ path, meta }: UniApp.UniRoute,
config: ResolvedConfig
_config: ResolvedConfig
) {
const { isEntry } = meta
const alias = isEntry ? `\n alias:'/${path}',` : ''
......@@ -217,7 +217,9 @@ function renderPage(component){
}
${globalName}.__uniRoutes=[${[
...generatePagesRoute(normalizePagesRoute(pagesJson), config),
].join(',')}]`
].join(
','
)}].map(uniRoute=>(uniRoute.meta.route = (uniRoute.alias || uniRoute.path).substr(1),uniRoute))`
}
function generateConfig(
......
......@@ -4801,6 +4801,7 @@ const ShowActionSheetProtocol = {
type: Array,
required: true
},
title: String,
itemColor: String,
popover: Object
};
......
......@@ -14,6 +14,10 @@ import { createTransformIndexHtml } from './transformIndexHtml'
const debugUni = debug('vite:uni:plugin')
const pkg = require('@dcloudio/vite-plugin-uni/package.json')
process.env.UNI_COMPILER_VERSION = pkg['uni-app']?.['compilerVersion'] || ''
export interface VitePluginUniOptions {
inputDir?: string
outputDir?: string
......
......@@ -1786,9 +1786,9 @@
integrity sha512-pMCcqU2zT4TjqYFrWtYHKal7Sl30Ims6ulZ4UFXxI4xbtQqK/qqKwkDoBFCfooRqqmRu9vY3xaJRwxSh673aYg==
"@types/node@^14.14.20":
version "14.17.3"
resolved "https://registry.yarnpkg.com/@types/node/-/node-14.17.3.tgz#6d327abaa4be34a74e421ed6409a0ae2f47f4c3d"
integrity sha512-e6ZowgGJmTuXa3GyaPbTGxX17tnThl2aSSizrFthQ7m9uLGZBXiGhgE55cjRZTF5kjZvYn9EOPOMljdjwbflxw==
version "14.17.4"
resolved "https://registry.yarnpkg.com/@types/node/-/node-14.17.4.tgz#218712242446fc868d0e007af29a4408c7765bc0"
integrity sha512-8kQ3+wKGRNN0ghtEn7EGps/B8CzuBz1nXZEIGGLP2GnwbqYn4dbTs7k+VKLTq1HvZLRCIDtN3Snx1Ege8B7L5A==
"@types/normalize-package-data@^2.4.0":
version "2.4.0"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册