|
1 | | -/** @typedef {import('../types/main').MetaPlugin} MetaPlugin */ |
| 1 | +/** @typedef {import('../types/main').MetaPluginWrapable} MetaPluginWrapable */ |
2 | 2 |
|
3 | 3 | import { executeSetupFunctions } from 'plugins-manager'; |
4 | 4 |
|
5 | 5 | /** |
6 | 6 | * @param {any} config |
7 | | - * @param {MetaPlugin[]} metaPlugins |
| 7 | + * @param {MetaPluginWrapable[]} metaPlugins |
8 | 8 | * @param {object} [options] |
9 | | - * @param {function | null} [options.wrapperFunction] |
| 9 | + * @param {function | null} [options.rollupWrapperFunction] |
10 | 10 | */ |
11 | | -export function metaConfigToWebDevServerConfig(config, metaPlugins, { wrapperFunction = null }) { |
12 | | - const _metaPlugins = executeSetupFunctions(config.setupPlugins, [...metaPlugins]); |
| 11 | +export function metaConfigToWebDevServerConfig( |
| 12 | + config, |
| 13 | + metaPlugins, |
| 14 | + { rollupWrapperFunction = null } = {}, |
| 15 | +) { |
| 16 | + if (config.plugins) { |
| 17 | + delete config.setupPlugins; |
| 18 | + delete config.setupRollupPlugins; |
| 19 | + return config; |
| 20 | + } |
13 | 21 |
|
14 | | - const plugins = _metaPlugins.map(pluginObj => { |
15 | | - const usePlugin = |
16 | | - typeof wrapperFunction === 'function' ? wrapperFunction(pluginObj.plugin) : pluginObj.plugin; |
| 22 | + const metaPluginsNoWrap = metaPlugins.map(pluginObj => { |
| 23 | + pluginObj.__noWrap = true; |
| 24 | + return pluginObj; |
| 25 | + }); |
| 26 | + |
| 27 | + const rollupPlugins = /** @type {MetaPluginWrapable[]} */ (executeSetupFunctions( |
| 28 | + config.setupRollupPlugins, |
| 29 | + [...metaPluginsNoWrap], |
| 30 | + )); |
| 31 | + |
| 32 | + const wrappedRollupPlugins = rollupPlugins.map(pluginObj => { |
| 33 | + if (typeof rollupWrapperFunction === 'function' && pluginObj.__noWrap !== true) { |
| 34 | + pluginObj.plugin = rollupWrapperFunction(pluginObj.plugin); |
| 35 | + } |
| 36 | + return pluginObj; |
| 37 | + }); |
17 | 38 |
|
| 39 | + const _metaPlugins = executeSetupFunctions(config.setupPlugins, [...wrappedRollupPlugins]); |
| 40 | + |
| 41 | + const plugins = _metaPlugins.map(pluginObj => { |
18 | 42 | if (pluginObj.options) { |
19 | | - return usePlugin(pluginObj.options); |
| 43 | + return pluginObj.plugin(pluginObj.options); |
20 | 44 | } else { |
21 | | - return usePlugin(); |
| 45 | + return pluginObj.plugin(); |
22 | 46 | } |
23 | 47 | }); |
24 | 48 | config.plugins = plugins; |
25 | 49 |
|
26 | 50 | delete config.setupPlugins; |
| 51 | + delete config.setupRollupPlugins; |
27 | 52 | return config; |
28 | 53 | } |
0 commit comments