( options: VitePluginFederationOptions )
| 34 | import { devExposePlugin } from './dev/expose-development' |
| 35 | |
| 36 | export default function federation( |
| 37 | options: VitePluginFederationOptions |
| 38 | ): Plugin { |
| 39 | options.filename = options.filename |
| 40 | ? options.filename |
| 41 | : DEFAULT_ENTRY_FILENAME |
| 42 | |
| 43 | let pluginList: PluginHooks[] = [] |
| 44 | let virtualMod |
| 45 | let registerCount = 0 |
| 46 | |
| 47 | function registerPlugins(mode: string, command: string) { |
| 48 | if (mode === 'production' || command === 'build') { |
| 49 | pluginList = [ |
| 50 | prodSharedPlugin(options), |
| 51 | prodExposePlugin(options), |
| 52 | prodRemotePlugin(options) |
| 53 | ] |
| 54 | } else if (mode === 'development' || command === 'serve') { |
| 55 | pluginList = [ |
| 56 | devSharedPlugin(options), |
| 57 | devExposePlugin(options), |
| 58 | devRemotePlugin(options) |
| 59 | ] |
| 60 | } else { |
| 61 | pluginList = [] |
| 62 | } |
| 63 | builderInfo.isHost = !!( |
| 64 | parsedOptions.prodRemote.length || parsedOptions.devRemote.length |
| 65 | ) |
| 66 | builderInfo.isRemote = !!( |
| 67 | parsedOptions.prodExpose.length || parsedOptions.devExpose.length |
| 68 | ) |
| 69 | builderInfo.isShared = !!( |
| 70 | parsedOptions.prodShared.length || parsedOptions.devShared.length |
| 71 | ) |
| 72 | |
| 73 | let virtualFiles = {} |
| 74 | pluginList.forEach((plugin) => { |
| 75 | if (plugin.virtualFile) { |
| 76 | virtualFiles = Object.assign(virtualFiles, plugin.virtualFile) |
| 77 | } |
| 78 | }) |
| 79 | virtualMod = virtual(virtualFiles) |
| 80 | } |
| 81 | |
| 82 | return { |
| 83 | name: 'originjs:federation', |
| 84 | // for scenario vite.config.js build.cssCodeSplit: false |
| 85 | // vite:css-post plugin will summarize all the styles in the style.xxxxxx.css file |
| 86 | // so, this plugin need run after vite:css-post in post plugin list |
| 87 | enforce: 'post', |
| 88 | // apply:'build', |
| 89 | options(_options) { |
| 90 | // rollup doesnt has options.mode and options.command |
| 91 | if (!registerCount++) { |
| 92 | registerPlugins((options.mode = options.mode ?? 'production'), '') |
| 93 | } |
no outgoing calls
no test coverage detected
searching dependent graphs…