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

wip(app): nvue

上级 4828c8b7
......@@ -23,9 +23,9 @@ export function initNVuePlugins() {
uniAppCssPlugin(),
uniEasycomPlugin({ exclude: UNI_EASYCOM_EXCLUDE }),
uniHBuilderXConsolePlugin(),
uniMainJsPlugin({ appService }),
...(appService ? [uniManifestJsonPlugin()] : []),
uniPagesJsonPlugin({ appService }),
uniMainJsPlugin({ renderer, appService }),
uniManifestJsonPlugin(),
uniPagesJsonPlugin({ renderer, appService }),
uniViteInjectPlugin('uni:app-inject', initAppProvide()),
uniStatsPlugin(),
uniAppNVuePlugin({ appService }),
......
......@@ -73,7 +73,7 @@ export function uniAppNVuePlugin({
},
outDir: nvueOutDir(appService),
rollupOptions: {
external,
external: external(appService),
output: {
entryFileNames(chunk) {
if (chunk.name === 'main') {
......@@ -83,8 +83,8 @@ export function uniAppNVuePlugin({
},
assetFileNames: '[name][extname]',
chunkFileNames: createChunkFileNames(inputDir),
plugins: [dynamicImportPolyfill()],
globals,
plugins: [dynamicImportPolyfill(true)],
globals: globals(appService),
},
},
},
......
......@@ -37,7 +37,7 @@ export function uniEsbuildPlugin({
},
bundle: true,
write: false,
plugins: [esbuildGlobalPlugin(esbuildGlobals)],
plugins: [esbuildGlobalPlugin(esbuildGlobals(appService))],
}
},
async writeBundle(_, bundle) {
......
import { defineUniMainJsPlugin, PAGES_JSON_JS } from '@dcloudio/uni-cli-shared'
import { APP_CSS_JS } from './appCss'
export function uniMainJsPlugin({ appService }: { appService: boolean }) {
export function uniMainJsPlugin({
renderer,
appService,
}: {
renderer?: 'native'
appService: boolean
}) {
return defineUniMainJsPlugin((opts) => {
return {
name: 'uni:app-nvue-main-js',
enforce: 'pre',
transform(code, id) {
if (opts.filter(id)) {
if (appService) {
code = code.includes('createSSRApp')
? createApp(code)
: createLegacyApp(code)
if (renderer) {
if (appService) {
code = code.includes('createSSRApp')
? createApp(code)
: createLegacyApp(code)
return {
code,
map: { mappings: '' },
}
}
return {
code,
code: `import './${PAGES_JSON_JS}';`,
map: { mappings: '' },
}
}
......@@ -31,7 +43,7 @@ function createApp(code: string) {
return `${code.replace(
'createSSRApp',
'createVueApp as createSSRApp'
)};const __app__=createApp().app;__app__._component.mpType='app';__app__._component.render=()=>{};__app__.mount("#app");`
)};const {app:__app__,Vuex:__Vuex__,Pinia:__Pinia__}=createApp();uni.Vuex=__Vuex__;uni.Pinia=__Pinia__;__app__._component.mpType='app';__app__._component.render=()=>{};__app__.mount("#app");`
}
function createLegacyApp(code: string) {
......
......@@ -12,8 +12,10 @@ import {
} from '@dcloudio/uni-cli-shared'
export function uniPagesJsonPlugin({
renderer,
appService,
}: {
renderer?: 'native'
appService: boolean
}): Plugin {
return defineUniPagesJsonPlugin((opts) => {
......@@ -38,7 +40,7 @@ export function uniPagesJsonPlugin({
)
}
})
if (appService) {
if (renderer === 'native' && !appService) {
this.emitFile({
fileName: `app-config-service.js`,
type: 'asset',
......
export const external = ['vue', 'vuex']
export const globals = {
vue: 'Vue',
vuex: 'Vuex',
pinia: 'Pinia',
export function external(appService: boolean) {
return appService ? ['vue'] : ['vue', 'vuex']
}
export const esbuildGlobals = {
vue: 'Vue',
vuex: 'uni.Vuex',
pinia: 'uni.Pinia',
export function globals(appService: boolean): { [name: string]: string } {
return appService
? { vue: 'Vue' }
: {
vue: 'Vue',
vuex: 'Vuex',
pinia: 'Pinia',
}
}
export function esbuildGlobals(appService: boolean): {
[name: string]: string
} {
return appService
? { vue: 'Vue' }
: {
vue: 'Vue',
vuex: 'uni.Vuex',
pinia: 'uni.Pinia',
}
}
import type { Plugin } from 'vite'
export function dynamicImportPolyfill(): Plugin {
export function dynamicImportPolyfill(promise: boolean = false): Plugin {
return {
name: 'dynamic-import-polyfill',
renderDynamicImport() {
return {
left: '(',
left: promise ? 'Promise.resolve(' : '(',
right: ')',
}
},
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册