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

wip(nvue): init

上级 e57870f5
......@@ -16,7 +16,7 @@ declare namespace NodeJS {
UNI_COMPILER_VERSION_TYPE: 'a' | 'r'
UNI_HBUILDERX_PLUGINS: string
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_APP_CODE_SPLITING?: 'true'
UNI_AUTOMATOR_WS_ENDPOINT?: string
......
......@@ -2663,6 +2663,20 @@ var serviceContext = (function (vue) {
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';
function backbuttonListener() {
uni.navigateBack({
......@@ -9543,8 +9557,6 @@ var serviceContext = (function (vue) {
var pako_1 = pako;
const TEMP_PATH$1 = '';
const API_UPX2PX = 'upx2px';
const Upx2pxProtocol = [
{
......@@ -10850,7 +10862,7 @@ var serviceContext = (function (vue) {
reject();
return;
}
const dirname = `${TEMP_PATH$1}/canvas`;
const dirname = `${TEMP_PATH}/canvas`;
operateCanvas(canvasId, pageId, 'toTempFilePath', {
x,
y,
......@@ -13466,20 +13478,6 @@ var serviceContext = (function (vue) {
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;
const onCompassChange = (defineOnApi(API_ON_COMPASS, () => {
startCompass();
......
......@@ -21,6 +21,8 @@ import { uniRenderjsPlugin } from './plugins/renderjs'
import { uniStatsPlugin } from './plugins/stats'
import { uniEasycomPlugin } from './plugins/easycom'
import { uniConfusionPlugin } from './plugins/confusion'
import { uniNVuePlugin } from './nvue'
import { uniNVueEntryPlugin } from './nvue/plugins/entry'
function initUniCssScopedPluginFilter(
inputDir: string
......@@ -65,7 +67,10 @@ const filter = initUniCssScopedPluginFilter(process.env.UNI_INPUT_DIR)
if (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)
}
......
// import { rollup, watch, RollupBuild, RollupOutput, RollupWatcher } from 'rollup'
// let nvueCallCounts = 0
// const nvueBuilds: RollupBuild[] = []
// interface NVueBuildOptions {
// watch?: boolean
// }
// 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 { Plugin } from 'vite'
import { createRollupOptions } from './rollup'
export function uniNVuePlugin(pagePath: string): Plugin {
return {
name: 'vite:uni-app-nvue',
config() {
return {
build: {
rollupOptions: createRollupOptions(pagePath),
},
}
},
}
}
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'
import vue from '@vitejs/plugin-vue'
import { EXTNAME_VUE_RE, removeExt } from '@dcloudio/uni-cli-shared'
import { isBuiltInComponent } from '@dcloudio/uni-shared'
import { createUniNVuePagePath } from '../plugins/entry'
export function createRollupOptions(pagePath: string): RollupOptions {
return {
input: pagePath,
input: createUniNVuePagePath(pagePath),
context: 'global',
external: ['vue'],
preserveEntrySignatures: false,
......
......@@ -7,6 +7,7 @@ import {
normalizePath,
parsePagesJsonOnce,
removeExt,
polyfillCode,
} from '@dcloudio/uni-cli-shared'
import { createConfig } from './config'
......@@ -97,20 +98,7 @@ function genNVueEntryCode(route: string) {
import App from '${normalizePath(
path.resolve(process.env.UNI_INPUT_DIR, route)
)}.nvue?mpType=page'
if (typeof Promise !== 'undefined' && !Promise.prototype.finally) {
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
})
})
}
}
${polyfillCode}
App.mpType = 'page'
App.route = '${route}'
App.el = '#root'
......
......@@ -27,6 +27,7 @@
"@vue/compiler-dom": "3.2.23",
"@vue/compiler-sfc": "3.2.23",
"@vue/shared": "3.2.23",
"base64url": "^3.0.1",
"chalk": "^4.1.1",
"chokidar": "^3.5.2",
"compare-versions": "^3.6.0",
......
export * from './fs'
export * from './mp'
export * from './url'
export * from './env'
export * from './hbx'
export * from './ssr'
......
export * from './pages'
export * from './manifest'
export { polyfillCode } from './pages/code'
......@@ -13,6 +13,9 @@ export function getNVueCompiler(manifestJson: Record<string, any>) {
if (nvueCompiler === 'vue') {
return 'vue'
}
if (nvueCompiler === 'vite') {
return 'vite'
}
}
return 'uni-app'
}
......
......@@ -3,7 +3,7 @@ import { getNVueCompiler, getNVueFlexDirection } from './nvue'
interface UniAppOptions {
control: 'uni-v3'
compilerVersion: string
nvueCompiler: 'uni-app' | 'weex'
nvueCompiler: 'uni-app' | 'weex' | 'vite' | 'vue'
renderer: 'auto'
nvue: {
'flex-direction': 'row' | 'row-reverse' | 'column' | 'column-reverse'
......
......@@ -13,7 +13,7 @@ interface AppUniConfig {
pages: string[]
globalStyle: UniApp.PagesJsonPageStyle
nvue: {
compiler: 'uni-app' | 'weex' | 'vue'
compiler: 'uni-app' | 'weex' | 'vue' | 'vite'
styleCompiler: 'weex' | 'uni-app'
'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 @@
"@intlify/shared": "9.1.9",
"@intlify/vue-devtools": "9.1.9",
"@vue/shared": "3.2.23",
"base64url": "^3.0.1",
"debug": "^4.3.2",
"magic-string": "^0.25.7"
},
......
......@@ -4,35 +4,29 @@ import {
normalizeMiniProgramFilename,
normalizePath,
removeExt,
encodeBase64Url,
decodeBase64Url,
} from '@dcloudio/uni-cli-shared'
import { Plugin } from 'vite'
import base64url from 'base64url'
import { UniMiniProgramPluginOptions } from '../plugin'
function encode(str: string) {
return base64url.encode(str)
}
function decode(str: string) {
return base64url.decode(str)
}
import { UniMiniProgramPluginOptions } from '../plugin'
const uniPagePrefix = 'uniPage://'
const uniComponentPrefix = 'uniComponent://'
export function virtualPagePath(filepath: string) {
return uniPagePrefix + encode(filepath)
return uniPagePrefix + encodeBase64Url(filepath)
}
export function virtualComponentPath(filepath: string) {
return uniComponentPrefix + encode(filepath)
return uniComponentPrefix + encodeBase64Url(filepath)
}
export function parseVirtualPagePath(uniPageUrl: string) {
return decode(uniPageUrl.replace(uniPagePrefix, ''))
return decodeBase64Url(uniPageUrl.replace(uniPagePrefix, ''))
}
export function parseVirtualComponentPath(uniComponentUrl: string) {
return decode(uniComponentUrl.replace(uniComponentPrefix, ''))
return decodeBase64Url(uniComponentUrl.replace(uniComponentPrefix, ''))
}
export function isUniPageUrl(id: string) {
......
......@@ -363,6 +363,7 @@ importers:
'@vue/compiler-dom': 3.2.23
'@vue/compiler-sfc': 3.2.23
'@vue/shared': 3.2.23
base64url: ^3.0.1
chalk: ^4.1.1
chokidar: ^3.5.2
compare-versions: ^3.6.0
......@@ -396,6 +397,7 @@ importers:
'@vue/compiler-dom': 3.2.23
'@vue/compiler-sfc': 3.2.23
'@vue/shared': 3.2.23
base64url: 3.0.1
chalk: 4.1.2
chokidar: 3.5.2
compare-versions: 3.6.0
......@@ -686,7 +688,6 @@ importers:
'@types/debug': ^4.1.7
'@vue/compiler-sfc': 3.2.23
'@vue/shared': 3.2.23
base64url: ^3.0.1
debug: ^4.3.2
magic-string: ^0.25.7
dependencies:
......@@ -698,7 +699,6 @@ importers:
'@intlify/shared': 9.1.9
'@intlify/vue-devtools': 9.1.9
'@vue/shared': 3.2.23
base64url: 3.0.1
debug: 4.3.2
magic-string: 0.25.7
devDependencies:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册