Skip to content

Commit 5127edf

Browse files
Add support for a non-root base directory
1 parent 8017628 commit 5127edf

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

packages/lib/src/dev/expose-development.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,16 @@ import { getModuleMarker, normalizePath, parseExposeOptions } from '../utils'
1818
import { EXTERNALS, SHARED, builderInfo, parsedOptions } from '../public'
1919
import type { VitePluginFederationOptions } from 'types'
2020
import type { PluginHooks } from '../../types/pluginHooks'
21-
import { ViteDevServer } from 'vite'
21+
import { UserConfig, ViteDevServer } from 'vite'
2222
import { importShared } from './import-shared'
23+
import { config } from 'process'
2324

2425
export function devExposePlugin(
2526
options: VitePluginFederationOptions
2627
): PluginHooks {
2728
parsedOptions.devExpose = parseExposeOptions(options)
2829
let moduleMap = ''
30+
let baseDir = '/'
2931

3032
// exposes module
3133
for (const item of parsedOptions.devExpose) {
@@ -37,7 +39,7 @@ export function devExposePlugin(
3739
return __federation_import('/${importPath}', '/@fs/${exposeFilepath}').then(module =>Object.keys(module).every(item => exportSet.has(item)) ? () => module.default : () => module)},`
3840
}
3941
const remoteFile = `(${importShared})();
40-
import RefreshRuntime from "/@react-refresh"
42+
import RefreshRuntime from "${baseDir}@react-refresh"
4143
RefreshRuntime.injectIntoGlobalHook(window)
4244
window.$RefreshReg$ = () => {}
4345
window.$RefreshSig$ = () => (type) => type
@@ -73,6 +75,11 @@ export function devExposePlugin(
7375

7476
return {
7577
name: 'originjs:expose-development',
78+
config: (config: UserConfig) => {
79+
if (config.base) {
80+
baseDir = config.base
81+
}
82+
},
7683
configureServer: (server: ViteDevServer) => {
7784
const remoteFilePath = `${builderInfo.assetsDir}/${options.filename}`
7885
server.middlewares.use((req, res, next) => {

0 commit comments

Comments
 (0)