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

Commit ce06e42

Browse files
feat: sass support for sass plugin
1 parent 88c8929 commit ce06e42

File tree

2 files changed

+39
-11
lines changed

2 files changed

+39
-11
lines changed

plugins/sass.ts

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,29 @@ export default {
55
test: /.(sass|scss)$/,
66
acceptHMR: true,
77
transform(content: Uint8Array, path: string) {
8-
const ret = renderSync({
9-
file: path,
10-
data: (new TextDecoder).decode(content),
11-
sourceMap: true
12-
})
13-
return {
14-
code: (new TextDecoder).decode(ret.css),
15-
map: ret.map ? (new TextDecoder).decode(ret.map) : undefined,
16-
loader: 'css'
8+
if (path.endsWith('.sass')) {
9+
const ret = renderSync({
10+
file: path,
11+
data: (new TextDecoder).decode(content),
12+
sourceMap: true,
13+
indentedSyntax: true
14+
})
15+
return {
16+
code: (new TextDecoder).decode(ret.css),
17+
map: ret.map ? (new TextDecoder).decode(ret.map) : undefined,
18+
loader: 'css'
19+
}
20+
} else {
21+
const ret = renderSync({
22+
file: path,
23+
data: (new TextDecoder).decode(content),
24+
sourceMap: true
25+
})
26+
return {
27+
code: (new TextDecoder).decode(ret.css),
28+
map: ret.map ? (new TextDecoder).decode(ret.map) : undefined,
29+
loader: 'css'
30+
}
1731
}
1832
}
1933
}

plugins/sass_test.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,33 @@
11
import { assertEquals } from 'https://deno.land/std/testing/asserts.ts';
22
import plugin from './sass.ts';
33

4-
Deno.test('project sass loader plugin', () => {
4+
Deno.test('project scss loader plugin', () => {
55
Object.assign(window, {
66
location: {
77
href: 'https://localhost/'
88
}
99
})
1010
const { code, loader } = plugin.transform(
1111
(new TextEncoder).encode('$someVar: 123px; .some-selector { width: $someVar; }'),
12-
'test.sass'
12+
'test.scss'
1313
)
1414
assertEquals(plugin.test.test('test.sass'), true)
1515
assertEquals(plugin.test.test('test.scss'), true)
1616
assertEquals(plugin.acceptHMR, true)
1717
assertEquals(code, '.some-selector {\n width: 123px;\n}')
1818
assertEquals(loader, 'css')
1919
})
20+
21+
Deno.test('project sass loader plugin', () => {
22+
Object.assign(window, {
23+
location: {
24+
href: 'https://localhost/'
25+
}
26+
})
27+
const { code, loader } = plugin.transform(
28+
(new TextEncoder).encode('$someVar: 123px\n.some-selector\n width: 123px'),
29+
'test.sass'
30+
)
31+
assertEquals(code, '.some-selector {\n width: 123px;\n}')
32+
assertEquals(loader, 'css')
33+
})

0 commit comments

Comments
 (0)