|
1 | 1 | import { createFilter } from '@rollup/pluginutils' |
2 | | -import { createUnplugin } from 'unplugin' |
| 2 | +import { createUnplugin, type UnpluginInstance } from 'unplugin' |
3 | 3 | import { transformStyle } from './core/style' |
4 | 4 | import { |
5 | 5 | getLocaleRE, |
@@ -29,39 +29,45 @@ const defaultOptions: Options = { |
29 | 29 | sourceMap: false, |
30 | 30 | } |
31 | 31 |
|
32 | | -export default createUnplugin<Partial<Options>>((userOptions = {}) => { |
33 | | - const options: Options = Object.assign(defaultOptions, userOptions) |
34 | | - const filter = createFilter(options.include, options.exclude) |
| 32 | +const unplugin: UnpluginInstance<Partial<Options>, false> = createUnplugin( |
| 33 | + (userOptions = {}) => { |
| 34 | + const options: Options = { |
| 35 | + ...defaultOptions, |
| 36 | + ...userOptions, |
| 37 | + } |
| 38 | + const filter = createFilter(options.include, options.exclude) |
35 | 39 |
|
36 | | - return { |
37 | | - name: 'unplugin-element-plus', |
38 | | - enforce: 'post', |
| 40 | + return { |
| 41 | + name: 'unplugin-element-plus', |
| 42 | + enforce: 'post', |
39 | 43 |
|
40 | | - transformInclude(id) { |
41 | | - return getLocaleRE(options).test(id) || filter(id) |
42 | | - }, |
| 44 | + transformInclude(id) { |
| 45 | + return getLocaleRE(options).test(id) || filter(id) |
| 46 | + }, |
43 | 47 |
|
44 | | - transform(source, id) { |
45 | | - if (options.defaultLocale) { |
46 | | - const result = transformDefaultLocale(options, source, id) |
47 | | - if (result) return result |
48 | | - } |
| 48 | + transform(source, id) { |
| 49 | + if (options.defaultLocale) { |
| 50 | + const result = transformDefaultLocale(options, source, id) |
| 51 | + if (result) return result |
| 52 | + } |
49 | 53 |
|
50 | | - return transformStyle(source, options) |
51 | | - }, |
| 54 | + return transformStyle(source, options) |
| 55 | + }, |
52 | 56 |
|
53 | | - vite: { |
54 | | - config() { |
55 | | - if (options.defaultLocale) { |
56 | | - return { |
57 | | - optimizeDeps: { |
58 | | - esbuildOptions: { |
59 | | - plugins: [getViteDepPlugin(options) as any], |
| 57 | + vite: { |
| 58 | + config() { |
| 59 | + if (options.defaultLocale) { |
| 60 | + return { |
| 61 | + optimizeDeps: { |
| 62 | + esbuildOptions: { |
| 63 | + plugins: [getViteDepPlugin(options) as any], |
| 64 | + }, |
60 | 65 | }, |
61 | | - }, |
| 66 | + } |
62 | 67 | } |
63 | | - } |
| 68 | + }, |
64 | 69 | }, |
65 | | - }, |
| 70 | + } |
66 | 71 | } |
67 | | -}) |
| 72 | +) |
| 73 | +export default unplugin |
0 commit comments