@@ -20,25 +20,27 @@ import type { VitePluginFederationOptions } from 'types'
2020import type { PluginHooks } from '../../types/pluginHooks'
2121import { UserConfig , ViteDevServer } from 'vite'
2222import { importShared } from './import-shared'
23- import { config } from 'process'
2423
2524export function devExposePlugin (
2625 options : VitePluginFederationOptions
2726) : PluginHooks {
2827 parsedOptions . devExpose = parseExposeOptions ( options )
2928 let moduleMap = ''
30- let baseDir = '/'
29+ let remoteFile : string | null = null
3130
32- // exposes module
33- for ( const item of parsedOptions . devExpose ) {
34- const moduleName = getModuleMarker ( `\${${ item [ 0 ] } }` , SHARED )
35- EXTERNALS . push ( moduleName )
36- const importPath = normalizePath ( item [ 1 ] . import )
37- const exposeFilepath = normalizePath ( resolve ( item [ 1 ] . import ) )
38- moduleMap += `\n"${ item [ 0 ] } ":() => {
39- return __federation_import('/${ importPath } ', '${ baseDir } @fs/${ exposeFilepath } ').then(module =>Object.keys(module).every(item => exportSet.has(item)) ? () => module.default : () => module)},`
31+ const exposeModules = ( baseDir ) => {
32+ for ( const item of parsedOptions . devExpose ) {
33+ const moduleName = getModuleMarker ( `\${${ item [ 0 ] } }` , SHARED )
34+ EXTERNALS . push ( moduleName )
35+ const importPath = normalizePath ( item [ 1 ] . import )
36+ const exposeFilepath = normalizePath ( resolve ( item [ 1 ] . import ) )
37+ moduleMap += `\n"${ item [ 0 ] } ":() => {
38+ return __federation_import('/${ importPath } ', '${ baseDir } @fs/${ exposeFilepath } ').then(module =>Object.keys(module).every(item => exportSet.has(item)) ? () => module.default : () => module)},`
39+ }
4040 }
41- const remoteFile = `(${ importShared } )();
41+
42+ const buildRemoteFile = ( baseDir ) => {
43+ return `(${ importShared } )();
4244 import RefreshRuntime from "${ baseDir } @react-refresh"
4345 RefreshRuntime.injectIntoGlobalHook(window)
4446 window.$RefreshReg$ = () => {}
@@ -72,12 +74,14 @@ export function devExposePlugin(
7274 });
7375 }
7476 `
77+ }
7578
7679 return {
7780 name : 'originjs:expose-development' ,
7881 config : ( config : UserConfig ) => {
7982 if ( config . base ) {
80- baseDir = config . base
83+ exposeModules ( config . base )
84+ remoteFile = buildRemoteFile ( config . base )
8185 }
8286 } ,
8387 configureServer : ( server : ViteDevServer ) => {
0 commit comments