|
1 |
| -import { ResolvedConfig, TransformResult } from 'vite'; |
| 1 | +import { ResolvedConfig, TransformResult, Plugin } from 'vite'; |
2 | 2 | import MagicString from 'magic-string';
|
3 | 3 | import { Preprocessor, PreprocessorGroup, ResolvedOptions } from './options';
|
4 | 4 | import { TransformPluginContext } from 'rollup';
|
@@ -86,16 +86,58 @@ function buildExtraPreprocessors(options: ResolvedOptions, config: ResolvedConfi
|
86 | 86 | extraPreprocessors.push(createVitePreprocessorGroup(config, options));
|
87 | 87 | }
|
88 | 88 |
|
89 |
| - const pluginsWithPreprocessors = config.plugins.filter((p) => p?.sveltePreprocess); |
90 |
| - if (pluginsWithPreprocessors.length > 0) { |
| 89 | + // @ts-ignore |
| 90 | + const pluginsWithPreprocessorsDeprecated = config.plugins.filter((p) => p?.sveltePreprocess); |
| 91 | + if (pluginsWithPreprocessorsDeprecated.length > 0) { |
| 92 | + log.warn( |
| 93 | + `The following plugins use the deprecated 'plugin.sveltePreprocess' field. Please contact their maintainers and ask them to move it to 'plugin.api.sveltePreprocess': ${pluginsWithPreprocessorsDeprecated |
| 94 | + .map((p) => p.name) |
| 95 | + .join(', ')}` |
| 96 | + ); |
| 97 | + // patch plugin to avoid breaking |
| 98 | + pluginsWithPreprocessorsDeprecated.forEach((p) => { |
| 99 | + if (!p.api) { |
| 100 | + p.api = {}; |
| 101 | + } |
| 102 | + if (p.api.sveltePreprocess === undefined) { |
| 103 | + // @ts-ignore |
| 104 | + p.api.sveltePreprocess = p.sveltePreprocess; |
| 105 | + } else { |
| 106 | + log.error( |
| 107 | + `ignoring plugin.sveltePreprocess of ${p.name} because it already defined plugin.api.sveltePreprocess.` |
| 108 | + ); |
| 109 | + } |
| 110 | + }); |
| 111 | + } |
| 112 | + |
| 113 | + const pluginsWithPreprocessors: Plugin[] = config.plugins.filter((p) => p?.api?.sveltePreprocess); |
| 114 | + const ignored: Plugin[] = [], |
| 115 | + included: Plugin[] = []; |
| 116 | + for (const p of pluginsWithPreprocessors) { |
| 117 | + if ( |
| 118 | + options.ignorePluginPreprocessors === true || |
| 119 | + (Array.isArray(options.ignorePluginPreprocessors) && |
| 120 | + options.ignorePluginPreprocessors?.includes(p.name)) |
| 121 | + ) { |
| 122 | + ignored.push(p); |
| 123 | + } else { |
| 124 | + included.push(p); |
| 125 | + } |
| 126 | + } |
| 127 | + if (ignored.length > 0) { |
91 | 128 | log.debug(
|
92 |
| - `adding preprocessors from other vite plugins: ${pluginsWithPreprocessors |
| 129 | + `Ignoring svelte preprocessors defined by these vite plugins: ${ignored |
93 | 130 | .map((p) => p.name)
|
94 | 131 | .join(', ')}`
|
95 | 132 | );
|
96 |
| - extraPreprocessors.push( |
97 |
| - ...pluginsWithPreprocessors.map((p) => p.sveltePreprocess as PreprocessorGroup) |
| 133 | + } |
| 134 | + if (included.length > 0) { |
| 135 | + log.debug( |
| 136 | + `Adding svelte preprocessors defined by these vite plugins: ${included |
| 137 | + .map((p) => p.name) |
| 138 | + .join(', ')}` |
98 | 139 | );
|
| 140 | + extraPreprocessors.push(...pluginsWithPreprocessors.map((p) => p.api.sveltePreprocess)); |
99 | 141 | }
|
100 | 142 |
|
101 | 143 | if (options.hot && !options.disableCssHmr) {
|
|
0 commit comments