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

wip(nvue): init

上级 e57870f5
...@@ -16,7 +16,7 @@ declare namespace NodeJS { ...@@ -16,7 +16,7 @@ declare namespace NodeJS {
UNI_COMPILER_VERSION_TYPE: 'a' | 'r' UNI_COMPILER_VERSION_TYPE: 'a' | 'r'
UNI_HBUILDERX_PLUGINS: string UNI_HBUILDERX_PLUGINS: string
UNI_RENDERER?: 'native' UNI_RENDERER?: 'native'
UNI_NVUE_COMPILER: 'uni-app' | 'weex' | 'vue' UNI_NVUE_COMPILER: 'uni-app' | 'weex' | 'vue' | 'vite'
UNI_NVUE_STYLE_COMPILER: 'uni-app' | 'weex' UNI_NVUE_STYLE_COMPILER: 'uni-app' | 'weex'
UNI_APP_CODE_SPLITING?: 'true' UNI_APP_CODE_SPLITING?: 'true'
UNI_AUTOMATOR_WS_ENDPOINT?: string UNI_AUTOMATOR_WS_ENDPOINT?: string
......
...@@ -2663,6 +2663,20 @@ var serviceContext = (function (vue) { ...@@ -2663,6 +2663,20 @@ var serviceContext = (function (vue) {
UniServiceJSBridge.unsubscribe(getEventName(reqId)); UniServiceJSBridge.unsubscribe(getEventName(reqId));
} }
const DEVICE_FREQUENCY = 200;
const NETWORK_TYPES = [
'unknown',
'none',
'ethernet',
'wifi',
'2g',
'3g',
'4g',
'5g',
];
const TEMP_PATH_BASE = '_doc/uniapp_temp';
const TEMP_PATH = `${TEMP_PATH_BASE}_${Date.now()}`;
const EVENT_BACKBUTTON = 'backbutton'; const EVENT_BACKBUTTON = 'backbutton';
function backbuttonListener() { function backbuttonListener() {
uni.navigateBack({ uni.navigateBack({
...@@ -9543,8 +9557,6 @@ var serviceContext = (function (vue) { ...@@ -9543,8 +9557,6 @@ var serviceContext = (function (vue) {
var pako_1 = pako; var pako_1 = pako;
const TEMP_PATH$1 = '';
const API_UPX2PX = 'upx2px'; const API_UPX2PX = 'upx2px';
const Upx2pxProtocol = [ const Upx2pxProtocol = [
{ {
...@@ -10850,7 +10862,7 @@ var serviceContext = (function (vue) { ...@@ -10850,7 +10862,7 @@ var serviceContext = (function (vue) {
reject(); reject();
return; return;
} }
const dirname = `${TEMP_PATH$1}/canvas`; const dirname = `${TEMP_PATH}/canvas`;
operateCanvas(canvasId, pageId, 'toTempFilePath', { operateCanvas(canvasId, pageId, 'toTempFilePath', {
x, x,
y, y,
...@@ -13466,20 +13478,6 @@ var serviceContext = (function (vue) { ...@@ -13466,20 +13478,6 @@ var serviceContext = (function (vue) {
return resolve(getSystemInfoSync()); return resolve(getSystemInfoSync());
}); });
const DEVICE_FREQUENCY = 200;
const NETWORK_TYPES = [
'unknown',
'none',
'ethernet',
'wifi',
'2g',
'3g',
'4g',
'5g',
];
const TEMP_PATH_BASE = '_doc/uniapp_temp';
const TEMP_PATH = `${TEMP_PATH_BASE}_${Date.now()}`;
let listener$1 = null; let listener$1 = null;
const onCompassChange = (defineOnApi(API_ON_COMPASS, () => { const onCompassChange = (defineOnApi(API_ON_COMPASS, () => {
startCompass(); startCompass();
......
...@@ -21,6 +21,8 @@ import { uniRenderjsPlugin } from './plugins/renderjs' ...@@ -21,6 +21,8 @@ import { uniRenderjsPlugin } from './plugins/renderjs'
import { uniStatsPlugin } from './plugins/stats' import { uniStatsPlugin } from './plugins/stats'
import { uniEasycomPlugin } from './plugins/easycom' import { uniEasycomPlugin } from './plugins/easycom'
import { uniConfusionPlugin } from './plugins/confusion' import { uniConfusionPlugin } from './plugins/confusion'
import { uniNVuePlugin } from './nvue'
import { uniNVueEntryPlugin } from './nvue/plugins/entry'
function initUniCssScopedPluginFilter( function initUniCssScopedPluginFilter(
inputDir: string inputDir: string
...@@ -65,7 +67,10 @@ const filter = initUniCssScopedPluginFilter(process.env.UNI_INPUT_DIR) ...@@ -65,7 +67,10 @@ const filter = initUniCssScopedPluginFilter(process.env.UNI_INPUT_DIR)
if (filter) { if (filter) {
plugins.unshift(uniCssScopedPlugin({ filter })) plugins.unshift(uniCssScopedPlugin({ filter }))
} }
if (process.env.UNI_NVUE_COMPILER !== 'vue') { if (process.env.UNI_NVUE_COMPILER === 'vite') {
plugins.push(uniNVuePlugin('pages/demo/demo'))
plugins.push(uniNVueEntryPlugin())
} else if (process.env.UNI_NVUE_COMPILER !== 'vue') {
plugins.push(...nvuePlugins) plugins.push(...nvuePlugins)
} }
......
// import { rollup, watch, RollupBuild, RollupOutput, RollupWatcher } from 'rollup' import { Plugin } from 'vite'
import { createRollupOptions } from './rollup'
// let nvueCallCounts = 0 export function uniNVuePlugin(pagePath: string): Plugin {
return {
// const nvueBuilds: RollupBuild[] = [] name: 'vite:uni-app-nvue',
config() {
// interface NVueBuildOptions { return {
// watch?: boolean build: {
// } rollupOptions: createRollupOptions(pagePath),
},
// export async function build( }
// options: NVueBuildOptions },
// ): Promise<RollupOutput | RollupOutput[] | RollupWatcher> { }
// nvueCallCounts++ }
// try {
// return await doBuild()
// } finally {
// nvueCallCounts--
// if (nvueCallCounts <= 0) {
// await Promise.all(nvueBuilds.map((bundle) => bundle.close()))
// nvueBuilds.length = 0
// }
// }
// }
// async function doBuild() {}
import path from 'path'
import type { Plugin } from 'vite'
import {
decodeBase64Url,
encodeBase64Url,
normalizePath,
polyfillCode,
} from '@dcloudio/uni-cli-shared'
const uniNVuePagePrefix = 'uniNVuePage://'
function isUniNVuePageUrl(id: string) {
return id.startsWith(uniNVuePagePrefix)
}
export function createUniNVuePagePath(pagePath: string) {
return uniNVuePagePrefix + encodeBase64Url(pagePath + '.nvue')
}
function parseUniNvuePagePath(uniNVuePageUrl: string) {
return decodeBase64Url(uniNVuePageUrl.replace(uniNVuePagePrefix, ''))
}
export function uniNVueEntryPlugin(): Plugin {
const inputDir = process.env.UNI_INPUT_DIR
return {
name: 'vite:uni-app-nvue-entry',
enforce: 'pre',
resolveId(id) {
if (isUniNVuePageUrl(id)) {
return id
}
},
load(id) {
if (isUniNVuePageUrl(id)) {
const filepath = normalizePath(
path.resolve(inputDir, parseUniNvuePagePath(id))
)
this.addWatchFile(filepath)
return {
code: `import { createApp } from 'vue'
import App from '${filepath}'
${polyfillCode}
createApp(App).mount('#app')
`,
}
}
},
}
}
...@@ -2,10 +2,11 @@ import { RollupOptions } from 'rollup' ...@@ -2,10 +2,11 @@ import { RollupOptions } from 'rollup'
import vue from '@vitejs/plugin-vue' import vue from '@vitejs/plugin-vue'
import { EXTNAME_VUE_RE, removeExt } from '@dcloudio/uni-cli-shared' import { EXTNAME_VUE_RE, removeExt } from '@dcloudio/uni-cli-shared'
import { isBuiltInComponent } from '@dcloudio/uni-shared' import { isBuiltInComponent } from '@dcloudio/uni-shared'
import { createUniNVuePagePath } from '../plugins/entry'
export function createRollupOptions(pagePath: string): RollupOptions { export function createRollupOptions(pagePath: string): RollupOptions {
return { return {
input: pagePath, input: createUniNVuePagePath(pagePath),
context: 'global', context: 'global',
external: ['vue'], external: ['vue'],
preserveEntrySignatures: false, preserveEntrySignatures: false,
......
...@@ -7,6 +7,7 @@ import { ...@@ -7,6 +7,7 @@ import {
normalizePath, normalizePath,
parsePagesJsonOnce, parsePagesJsonOnce,
removeExt, removeExt,
polyfillCode,
} from '@dcloudio/uni-cli-shared' } from '@dcloudio/uni-cli-shared'
import { createConfig } from './config' import { createConfig } from './config'
...@@ -97,20 +98,7 @@ function genNVueEntryCode(route: string) { ...@@ -97,20 +98,7 @@ function genNVueEntryCode(route: string) {
import App from '${normalizePath( import App from '${normalizePath(
path.resolve(process.env.UNI_INPUT_DIR, route) path.resolve(process.env.UNI_INPUT_DIR, route)
)}.nvue?mpType=page' )}.nvue?mpType=page'
if (typeof Promise !== 'undefined' && !Promise.prototype.finally) { ${polyfillCode}
Promise.prototype.finally = function(callback) {
var promise = this.constructor
return this.then(function(value) {
return promise.resolve(callback()).then(function() {
return value
})
}, function(reason) {
return promise.resolve(callback()).then(function() {
throw reason
})
})
}
}
App.mpType = 'page' App.mpType = 'page'
App.route = '${route}' App.route = '${route}'
App.el = '#root' App.el = '#root'
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
"@vue/compiler-dom": "3.2.23", "@vue/compiler-dom": "3.2.23",
"@vue/compiler-sfc": "3.2.23", "@vue/compiler-sfc": "3.2.23",
"@vue/shared": "3.2.23", "@vue/shared": "3.2.23",
"base64url": "^3.0.1",
"chalk": "^4.1.1", "chalk": "^4.1.1",
"chokidar": "^3.5.2", "chokidar": "^3.5.2",
"compare-versions": "^3.6.0", "compare-versions": "^3.6.0",
......
export * from './fs' export * from './fs'
export * from './mp' export * from './mp'
export * from './url'
export * from './env' export * from './env'
export * from './hbx' export * from './hbx'
export * from './ssr' export * from './ssr'
......
export * from './pages' export * from './pages'
export * from './manifest' export * from './manifest'
export { polyfillCode } from './pages/code'
...@@ -13,6 +13,9 @@ export function getNVueCompiler(manifestJson: Record<string, any>) { ...@@ -13,6 +13,9 @@ export function getNVueCompiler(manifestJson: Record<string, any>) {
if (nvueCompiler === 'vue') { if (nvueCompiler === 'vue') {
return 'vue' return 'vue'
} }
if (nvueCompiler === 'vite') {
return 'vite'
}
} }
return 'uni-app' return 'uni-app'
} }
......
...@@ -3,7 +3,7 @@ import { getNVueCompiler, getNVueFlexDirection } from './nvue' ...@@ -3,7 +3,7 @@ import { getNVueCompiler, getNVueFlexDirection } from './nvue'
interface UniAppOptions { interface UniAppOptions {
control: 'uni-v3' control: 'uni-v3'
compilerVersion: string compilerVersion: string
nvueCompiler: 'uni-app' | 'weex' nvueCompiler: 'uni-app' | 'weex' | 'vite' | 'vue'
renderer: 'auto' renderer: 'auto'
nvue: { nvue: {
'flex-direction': 'row' | 'row-reverse' | 'column' | 'column-reverse' 'flex-direction': 'row' | 'row-reverse' | 'column' | 'column-reverse'
......
...@@ -13,7 +13,7 @@ interface AppUniConfig { ...@@ -13,7 +13,7 @@ interface AppUniConfig {
pages: string[] pages: string[]
globalStyle: UniApp.PagesJsonPageStyle globalStyle: UniApp.PagesJsonPageStyle
nvue: { nvue: {
compiler: 'uni-app' | 'weex' | 'vue' compiler: 'uni-app' | 'weex' | 'vue' | 'vite'
styleCompiler: 'weex' | 'uni-app' styleCompiler: 'weex' | 'uni-app'
'flex-direction': 'row' | 'row-reverse' | 'column' | 'column-reverse' 'flex-direction': 'row' | 'row-reverse' | 'column' | 'column-reverse'
} }
......
import base64url from 'base64url'
export function encodeBase64Url(str: string) {
return base64url.encode(str)
}
export function decodeBase64Url(str: string) {
return base64url.decode(str)
}
...@@ -26,7 +26,6 @@ ...@@ -26,7 +26,6 @@
"@intlify/shared": "9.1.9", "@intlify/shared": "9.1.9",
"@intlify/vue-devtools": "9.1.9", "@intlify/vue-devtools": "9.1.9",
"@vue/shared": "3.2.23", "@vue/shared": "3.2.23",
"base64url": "^3.0.1",
"debug": "^4.3.2", "debug": "^4.3.2",
"magic-string": "^0.25.7" "magic-string": "^0.25.7"
}, },
......
...@@ -4,35 +4,29 @@ import { ...@@ -4,35 +4,29 @@ import {
normalizeMiniProgramFilename, normalizeMiniProgramFilename,
normalizePath, normalizePath,
removeExt, removeExt,
encodeBase64Url,
decodeBase64Url,
} from '@dcloudio/uni-cli-shared' } from '@dcloudio/uni-cli-shared'
import { Plugin } from 'vite' import { Plugin } from 'vite'
import base64url from 'base64url'
import { UniMiniProgramPluginOptions } from '../plugin'
function encode(str: string) {
return base64url.encode(str)
}
function decode(str: string) { import { UniMiniProgramPluginOptions } from '../plugin'
return base64url.decode(str)
}
const uniPagePrefix = 'uniPage://' const uniPagePrefix = 'uniPage://'
const uniComponentPrefix = 'uniComponent://' const uniComponentPrefix = 'uniComponent://'
export function virtualPagePath(filepath: string) { export function virtualPagePath(filepath: string) {
return uniPagePrefix + encode(filepath) return uniPagePrefix + encodeBase64Url(filepath)
} }
export function virtualComponentPath(filepath: string) { export function virtualComponentPath(filepath: string) {
return uniComponentPrefix + encode(filepath) return uniComponentPrefix + encodeBase64Url(filepath)
} }
export function parseVirtualPagePath(uniPageUrl: string) { export function parseVirtualPagePath(uniPageUrl: string) {
return decode(uniPageUrl.replace(uniPagePrefix, '')) return decodeBase64Url(uniPageUrl.replace(uniPagePrefix, ''))
} }
export function parseVirtualComponentPath(uniComponentUrl: string) { export function parseVirtualComponentPath(uniComponentUrl: string) {
return decode(uniComponentUrl.replace(uniComponentPrefix, '')) return decodeBase64Url(uniComponentUrl.replace(uniComponentPrefix, ''))
} }
export function isUniPageUrl(id: string) { export function isUniPageUrl(id: string) {
......
...@@ -363,6 +363,7 @@ importers: ...@@ -363,6 +363,7 @@ importers:
'@vue/compiler-dom': 3.2.23 '@vue/compiler-dom': 3.2.23
'@vue/compiler-sfc': 3.2.23 '@vue/compiler-sfc': 3.2.23
'@vue/shared': 3.2.23 '@vue/shared': 3.2.23
base64url: ^3.0.1
chalk: ^4.1.1 chalk: ^4.1.1
chokidar: ^3.5.2 chokidar: ^3.5.2
compare-versions: ^3.6.0 compare-versions: ^3.6.0
...@@ -396,6 +397,7 @@ importers: ...@@ -396,6 +397,7 @@ importers:
'@vue/compiler-dom': 3.2.23 '@vue/compiler-dom': 3.2.23
'@vue/compiler-sfc': 3.2.23 '@vue/compiler-sfc': 3.2.23
'@vue/shared': 3.2.23 '@vue/shared': 3.2.23
base64url: 3.0.1
chalk: 4.1.2 chalk: 4.1.2
chokidar: 3.5.2 chokidar: 3.5.2
compare-versions: 3.6.0 compare-versions: 3.6.0
...@@ -686,7 +688,6 @@ importers: ...@@ -686,7 +688,6 @@ importers:
'@types/debug': ^4.1.7 '@types/debug': ^4.1.7
'@vue/compiler-sfc': 3.2.23 '@vue/compiler-sfc': 3.2.23
'@vue/shared': 3.2.23 '@vue/shared': 3.2.23
base64url: ^3.0.1
debug: ^4.3.2 debug: ^4.3.2
magic-string: ^0.25.7 magic-string: ^0.25.7
dependencies: dependencies:
...@@ -698,7 +699,6 @@ importers: ...@@ -698,7 +699,6 @@ importers:
'@intlify/shared': 9.1.9 '@intlify/shared': 9.1.9
'@intlify/vue-devtools': 9.1.9 '@intlify/vue-devtools': 9.1.9
'@vue/shared': 3.2.23 '@vue/shared': 3.2.23
base64url: 3.0.1
debug: 4.3.2 debug: 4.3.2
magic-string: 0.25.7 magic-string: 0.25.7
devDependencies: devDependencies:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册