MCPcopy
hub / github.com/vitejs/vite / createWorkerPlugins

Function createWorkerPlugins

packages/vite/src/node/config.ts:1827–1894  ·  view source on GitHub ↗
(bundleChain: string[])

Source from the content-addressed store, hash-verified

1825 }
1826
1827 const createWorkerPlugins = async function (bundleChain: string[]) {
1828 // Some plugins that aren't intended to work in the bundling of workers (doing post-processing at build time for example).
1829 // And Plugins may also have cached that could be corrupted by being used in these extra rollup calls.
1830 // So we need to separate the worker plugin from the plugin that vite needs to run.
1831 const rawWorkerUserPlugins = (
1832 await asyncFlatten(createUserWorkerPlugins?.() || [])
1833 ).filter(filterPlugin)
1834
1835 // resolve worker
1836 let workerConfig = mergeConfig({}, config)
1837 const [workerPrePlugins, workerNormalPlugins, workerPostPlugins] =
1838 sortUserPlugins(rawWorkerUserPlugins)
1839
1840 // run config hooks
1841 const workerUserPlugins = [
1842 ...workerPrePlugins,
1843 ...workerNormalPlugins,
1844 ...workerPostPlugins,
1845 ]
1846 workerConfig = await runConfigHook(
1847 workerConfig,
1848 workerUserPlugins,
1849 configEnv,
1850 )
1851
1852 const workerResolved: ResolvedConfig = {
1853 ...workerConfig,
1854 ...resolved,
1855 isWorker: true,
1856 mainConfig: resolved,
1857 bundleChain,
1858 }
1859
1860 // Plugins resolution needs the resolved config (minus plugins) so we need to mutate here
1861 ;(workerResolved.plugins as Plugin[]) = await resolvePlugins(
1862 workerResolved,
1863 workerPrePlugins,
1864 workerNormalPlugins,
1865 workerPostPlugins,
1866 )
1867
1868 // run configResolved hooks
1869 await Promise.all(
1870 createPluginHookUtils(workerResolved.plugins)
1871 .getSortedPluginHooks('configResolved')
1872 .map((hook) => hook.call(resolvedConfigContext, workerResolved)),
1873 )
1874
1875 // Resolve environment plugins after configResolved because there are
1876 // downstream projects modifying the plugins in it. This may change
1877 // once the ecosystem is ready.
1878 // During Build the client environment is used to bundle the worker
1879 // Avoid overriding the mainConfig (resolved.environments.client)
1880 ;(workerResolved.environments as Record<
1881 string,
1882 ResolvedEnvironmentOptions
1883 >) = {
1884 ...workerResolved.environments,

Callers

nothing calls this directly

Calls 7

asyncFlattenFunction · 0.90
mergeConfigFunction · 0.90
resolvePluginsFunction · 0.90
createPluginHookUtilsFunction · 0.90
sortUserPluginsFunction · 0.85
runConfigHookFunction · 0.85

Tested by

no test coverage detected