Closed rmariuzzo closed 1 year ago
Does this work for you?
function replaceTsConfigPaths(plugins, options) {
const plugin = tsConfigPaths(options)
return [
...plugins.filter(p => p.name !== plugin.name),
plugin,
]
}
Thank you for the idea, I ended up with something similar but more verbose because Vite's PluginOption
is a union of many types:
// node_modules/vite/dist/node/index.d.ts
export declare type PluginOption = Plugin_2 | false | null | undefined | PluginOption[] | Promise<Plugin_2 | false | null | undefined | PluginOption[]>;
Solution:
const plugin = tsConfigPaths(options)
return mergeConfig(config, {
plugins: [
...(config.plugins
// πNeeded because `PluginOption` can be a value or a promise.
? (await Promise.all(config.plugins)).filter((p) => {
// π Needed because `PluginOption` can be `false | null | undefined | PluginOption[]`
return p && !Array.isArray(p) && p.name !== plugin.name;
})
: []),
plugin,
],
});
I would like to filter this plugin when merging multiple vite config. I can do the filtering using its name as follow:
However, instead of using a hard coded name, I would prefer to have access to its defined name: https://github.com/aleclarson/vite-tsconfig-paths/blob/44a9f7765c4072deaee0c5b1392445c64fb21a94/src/index.ts#L26
One idea would be to export the name as a props of the function and we would be able to access it as:
Or you could export the plugin name as: