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

Commit 77571e3

Browse files
feat: you can also customize rendering settings
1 parent ce06e42 commit 77571e3

File tree

1 file changed

+40
-2
lines changed

1 file changed

+40
-2
lines changed

plugins/sass.ts

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

3-
export default {
3+
const defaultOptions = {
44
name: 'sass-loader',
55
test: /.(sass|scss)$/,
66
acceptHMR: true,
@@ -31,3 +31,41 @@ export default {
3131
}
3232
}
3333
}
34+
35+
let plugin: any = (opts: Options) => ({
36+
name: 'sass-loader',
37+
test: /.(sass|scss)$/,
38+
acceptHMR: true,
39+
transform(content: Uint8Array, path: string) {
40+
if (path.endsWith('.sass')) {
41+
const ret = renderSync({
42+
...opts,
43+
file: path,
44+
data: (new TextDecoder).decode(content),
45+
sourceMap: true,
46+
indentedSyntax: true
47+
})
48+
return {
49+
code: (new TextDecoder).decode(ret.css),
50+
map: ret.map ? (new TextDecoder).decode(ret.map) : undefined,
51+
loader: 'css'
52+
}
53+
} else {
54+
const ret = renderSync({
55+
...opts,
56+
file: path,
57+
data: (new TextDecoder).decode(content),
58+
sourceMap: true
59+
})
60+
return {
61+
code: (new TextDecoder).decode(ret.css),
62+
map: ret.map ? (new TextDecoder).decode(ret.map) : undefined,
63+
loader: 'css'
64+
}
65+
}
66+
}
67+
})
68+
69+
plugin = { ...plugin, ...defaultOptions }
70+
71+
export default plugin;

0 commit comments

Comments
 (0)