Skip to content
This repository was archived by the owner on Jul 6, 2025. It is now read-only.

Commit 28b8654

Browse files
authored
Merge pull request #62 from soilSpoon/feature/sass
refactor: refactor sass plugin
2 parents fdbd0d8 + 7ef72b6 commit 28b8654

File tree

1 file changed

+3
-18
lines changed

1 file changed

+3
-18
lines changed

plugins/sass.ts

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,9 @@
11
import { Options, renderSync } from 'https://esm.sh/[email protected]'
22

3-
const defaultPlugin = {
3+
const pluginFactory = (opts: Options = {}) => ({
44
name: 'sass-loader',
55
test: /.(sass|scss)$/,
66
acceptHMR: true,
7-
transform(content: Uint8Array, path: string) {
8-
const ret = renderSync({
9-
file: path,
10-
data: (new TextDecoder).decode(content),
11-
sourceMap: true,
12-
indentedSyntax: path.endsWith('.sass')
13-
})
14-
return {
15-
code: (new TextDecoder).decode(ret.css),
16-
map: ret.map ? (new TextDecoder).decode(ret.map) : undefined,
17-
loader: 'css'
18-
}
19-
}
20-
}
21-
22-
const pluginFactory = (opts: Options) => ({
23-
...defaultPlugin,
247
transform(content: Uint8Array, path: string) {
258
const ret = renderSync({
269
indentedSyntax: path.endsWith('.sass'),
@@ -37,6 +20,8 @@ const pluginFactory = (opts: Options) => ({
3720
}
3821
})
3922

23+
const defaultPlugin = pluginFactory()
24+
4025
pluginFactory.displayName = defaultPlugin.name
4126
pluginFactory.test = defaultPlugin.test
4227
pluginFactory.acceptHMR = defaultPlugin.acceptHMR

0 commit comments

Comments
 (0)