From 00a544ebb4ee41720ff3d8c16402b9a77d08710f Mon Sep 17 00:00:00 2001 From: Eduardo San Martin Morote Date: Wed, 12 Apr 2023 16:35:11 +0200 Subject: [PATCH 1/3] feat: allow vite plugins to be prepended --- packages/kit/src/build.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/packages/kit/src/build.ts b/packages/kit/src/build.ts index e5678da2e6a7..e6c6ff073881 100644 --- a/packages/kit/src/build.ts +++ b/packages/kit/src/build.ts @@ -32,7 +32,14 @@ export interface ExtendConfigOptions { export interface ExtendWebpackConfigOptions extends ExtendConfigOptions { } -export interface ExtendViteConfigOptions extends ExtendConfigOptions {} +export interface ExtendViteConfigOptions extends ExtendConfigOptions { + /** + * Prepends the plugin to the array with `unshit()` instead of `push()`. In practice this shouldn't be necessary, but + * it's needed by unplugin-vue-router until vue exposes an API to parse files. + * @internal + */ + prepend?: boolean +} /** * Extend webpack config @@ -119,11 +126,12 @@ export function addWebpackPlugin (plugin: WebpackPluginInstance | WebpackPluginI */ export function addVitePlugin (plugin: VitePlugin | VitePlugin[], options?: ExtendViteConfigOptions) { extendViteConfig((config) => { + const method: 'push' | 'unshift' = options?.prepend ? 'unshift' : 'push' config.plugins = config.plugins || [] if (Array.isArray(plugin)) { - config.plugins.push(...plugin) + config.plugins[method](...plugin) } else { - config.plugins.push(plugin) + config.plugins[method](plugin) } }, options) } From 57436f11098b2b7cf536f856d751b47fc178892f Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Wed, 19 Apr 2023 23:17:22 +0100 Subject: [PATCH 2/3] feat: add parallel webpack option --- packages/kit/src/build.ts | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/packages/kit/src/build.ts b/packages/kit/src/build.ts index e6c6ff073881..dd963bd7d571 100644 --- a/packages/kit/src/build.ts +++ b/packages/kit/src/build.ts @@ -30,13 +30,15 @@ export interface ExtendConfigOptions { } export interface ExtendWebpackConfigOptions extends ExtendConfigOptions { + /** + * Prepends the plugin to the array with `unshit()` instead of `push()`. + */ + prepend?: boolean } export interface ExtendViteConfigOptions extends ExtendConfigOptions { /** - * Prepends the plugin to the array with `unshit()` instead of `push()`. In practice this shouldn't be necessary, but - * it's needed by unplugin-vue-router until vue exposes an API to parse files. - * @internal + * Prepends the plugin to the array with `unshit()` instead of `push()`. */ prepend?: boolean } @@ -111,12 +113,13 @@ export function extendViteConfig ( * Append webpack plugin to the config. */ export function addWebpackPlugin (plugin: WebpackPluginInstance | WebpackPluginInstance[], options?: ExtendWebpackConfigOptions) { + const method: 'push' | 'unshift' = options?.prepend ? 'unshift' : 'push' extendWebpackConfig((config) => { config.plugins = config.plugins || [] if (Array.isArray(plugin)) { - config.plugins.push(...plugin) + config.plugins[method](...plugin) } else { - config.plugins.push(plugin) + config.plugins[method](plugin) } }, options) } @@ -125,8 +128,8 @@ export function addWebpackPlugin (plugin: WebpackPluginInstance | WebpackPluginI * Append Vite plugin to the config. */ export function addVitePlugin (plugin: VitePlugin | VitePlugin[], options?: ExtendViteConfigOptions) { + const method: 'push' | 'unshift' = options?.prepend ? 'unshift' : 'push' extendViteConfig((config) => { - const method: 'push' | 'unshift' = options?.prepend ? 'unshift' : 'push' config.plugins = config.plugins || [] if (Array.isArray(plugin)) { config.plugins[method](...plugin) From 0c208eee8b43e8f2e8cb6314ddeb1b6ce47fc541 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Sat, 29 Apr 2023 23:23:02 +0100 Subject: [PATCH 3/3] refactor: make prepend a shared option --- packages/kit/src/build.ts | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/packages/kit/src/build.ts b/packages/kit/src/build.ts index dd963bd7d571..1ad1ad8b4f76 100644 --- a/packages/kit/src/build.ts +++ b/packages/kit/src/build.ts @@ -27,21 +27,15 @@ export interface ExtendConfigOptions { * @default true */ client?: boolean -} - -export interface ExtendWebpackConfigOptions extends ExtendConfigOptions { /** * Prepends the plugin to the array with `unshit()` instead of `push()`. */ prepend?: boolean } -export interface ExtendViteConfigOptions extends ExtendConfigOptions { - /** - * Prepends the plugin to the array with `unshit()` instead of `push()`. - */ - prepend?: boolean -} +export interface ExtendWebpackConfigOptions extends ExtendConfigOptions {} + +export interface ExtendViteConfigOptions extends ExtendConfigOptions {} /** * Extend webpack config