|
1 | 1 | import { ResolvedConfig, TransformResult } from 'vite';
|
2 | 2 | import { Preprocessor, PreprocessorGroup, ResolvedOptions } from './options';
|
3 | 3 | import { TransformPluginContext } from 'rollup';
|
4 |
| -// import type { WindiPluginUtils } from '@windicss/plugin-utils' |
| 4 | +import { log } from './log'; |
5 | 5 | const supportedStyleLangs = ['css', 'less', 'sass', 'scss', 'styl', 'stylus', 'postcss'];
|
6 | 6 |
|
7 | 7 | const supportedScriptLangs = ['ts'];
|
@@ -58,63 +58,24 @@ export function createVitePreprocessorGroup(
|
58 | 58 | } as PreprocessorGroup;
|
59 | 59 | }
|
60 | 60 |
|
61 |
| -/* |
62 |
| -function createWindicssStylePreprocessorFromVite( |
63 |
| - windiPlugin: Plugin |
64 |
| -): PreprocessorGroup { |
65 |
| - const cssTransform = windiPlugin.transform!.bind( |
66 |
| - (null as unknown) as TransformPluginContext |
67 |
| - ) |
68 |
| - return { |
69 |
| - style: async ({attributes,content, filename }) => { |
70 |
| - const lang = attributes.lang as string || 'css' |
71 |
| - const transformResult: string = (await cssTransform( |
72 |
| - content, |
73 |
| - `${filename}.${lang}` |
74 |
| - )) as unknown as string |
75 |
| -
|
76 |
| -
|
77 |
| - return { |
78 |
| - code: transformResult |
79 |
| - } |
80 |
| - } |
81 |
| - } as PreprocessorGroup |
82 |
| -} |
83 |
| -
|
84 |
| -
|
85 |
| -
|
86 |
| -function createWindicssApiStylePreprocessorFromVite( |
87 |
| - windiPlugin: Plugin |
88 |
| -): PreprocessorGroup { |
89 |
| - const windiAPI = windiPlugin.api as WindiPluginUtils |
90 |
| -
|
91 |
| - return { |
92 |
| - style: async ({ content, filename }) => { |
93 |
| - windiAPI.extractFile(content,filename,false); |
94 |
| - const transformResult = await windiAPI.transformGroupsWithSourcemap(content) |
95 |
| - if(transformResult) { |
96 |
| - return { |
97 |
| - code: transformResult.code, |
98 |
| - map: transformResult.map as object |
99 |
| - } |
100 |
| - } |
101 |
| - } |
102 |
| - } as PreprocessorGroup |
103 |
| -} |
104 |
| -
|
105 |
| - */ |
106 |
| - |
107 | 61 | export function buildExtraPreprocessors(options: ResolvedOptions, config: ResolvedConfig) {
|
108 | 62 | const extraPreprocessors = [];
|
109 | 63 | if (options.useVitePreprocess) {
|
| 64 | + log.debug('adding vite preprocessor'); |
110 | 65 | extraPreprocessors.push(createVitePreprocessorGroup(config, options));
|
111 | 66 | }
|
112 |
| - // TODO |
113 |
| - /* |
114 |
| - const windiCssPlugin = config.plugins.find(p => p.name === 'vite-plugin-windicss:css'); |
115 |
| - if (windiCssPlugin) { |
116 |
| - extraPreprocessors.unshift(createWindicssStylePreprocessorFromVite(windiCssPlugin)) |
117 |
| - } |
118 |
| - */ |
| 67 | + |
| 68 | + const pluginsWithPreprocessors = config.plugins.filter((p) => p?.sveltePreprocess); |
| 69 | + if (pluginsWithPreprocessors.length > 0) { |
| 70 | + log.debug( |
| 71 | + `adding preprocessors from other vite plugins: ${pluginsWithPreprocessors |
| 72 | + .map((p) => p.name) |
| 73 | + .join(', ')}` |
| 74 | + ); |
| 75 | + extraPreprocessors.push( |
| 76 | + ...pluginsWithPreprocessors.map((p) => p.sveltePreprocess as PreprocessorGroup) |
| 77 | + ); |
| 78 | + } |
| 79 | + |
119 | 80 | return extraPreprocessors;
|
120 | 81 | }
|
0 commit comments