|
1 | 1 | import { Buffer } from 'node:buffer' |
2 | | -import { createUnplugin } from 'unplugin' |
3 | 2 | import { createFilter } from '@rollup/pluginutils' |
4 | 3 | import { transform } from 'lightningcss' |
5 | | -import { type Options, resolveOption } from './core/options' |
| 4 | +import { createUnplugin, type UnpluginInstance } from 'unplugin' |
| 5 | +import { resolveOption, type Options } from './core/options' |
6 | 6 |
|
7 | 7 | const postfixRE = /[#?].*$/s |
8 | 8 | function cleanUrl(url: string): string { |
9 | 9 | return url.replace(postfixRE, '') |
10 | 10 | } |
11 | 11 |
|
12 | | -export default createUnplugin<Options | undefined, false>((rawOptions = {}) => { |
13 | | - const options = resolveOption(rawOptions) |
14 | | - const filter = createFilter(options.include, options.exclude) |
| 12 | +const plugin: UnpluginInstance<Options | undefined, false> = createUnplugin( |
| 13 | + (rawOptions = {}) => { |
| 14 | + const options = resolveOption(rawOptions) |
| 15 | + const filter = createFilter(options.include, options.exclude) |
15 | 16 |
|
16 | | - const name = 'unplugin-lightningcss' |
17 | | - return { |
18 | | - name, |
19 | | - enforce: options.enforce, |
| 17 | + const name = 'unplugin-lightningcss' |
| 18 | + return { |
| 19 | + name, |
| 20 | + enforce: options.enforce, |
20 | 21 |
|
21 | | - transformInclude(id) { |
22 | | - return filter(id) |
23 | | - }, |
| 22 | + transformInclude(id) { |
| 23 | + return filter(id) |
| 24 | + }, |
24 | 25 |
|
25 | | - transform(code, id) { |
26 | | - return transformCss(id, code, options.options) |
27 | | - }, |
28 | | - } |
29 | | -}) |
| 26 | + transform(code, id) { |
| 27 | + return transformCss(id, code, options.options) |
| 28 | + }, |
| 29 | + } |
| 30 | + }, |
| 31 | +) |
| 32 | + |
| 33 | +export default plugin |
30 | 34 |
|
31 | 35 | function transformCss(id: string, code: string, options: Options['options']) { |
32 | 36 | const filename = cleanUrl(id) |
|
0 commit comments