Skip to content

Commit 5b55803

Browse files
authored
fix: externalize CSS preprocessors (#200)
1 parent 8478df7 commit 5b55803

File tree

5 files changed

+23
-1
lines changed

5 files changed

+23
-1
lines changed

src/filename.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export const RE_TS: RegExp = /\.([cm]?)tsx?$/
1010
export const RE_DTS: RegExp = /\.d\.([cm]?)ts$/
1111
export const RE_DTS_MAP: RegExp = /\.d\.([cm]?)ts\.map$/
1212
export const RE_NODE_MODULES: RegExp = /[\\/]node_modules[\\/]/
13-
export const RE_CSS: RegExp = /\.css$/
13+
export const RE_CSS: RegExp = /\.(?:css|scss|sass|less|styl|stylus)$/
1414
export const RE_VUE: RegExp = /\.vue$/
1515
export const RE_JSON: RegExp = /\.json$/
1616
export const RE_ROLLDOWN_RUNTIME: RegExp = exactRegex(RUNTIME_MODULE_ID)

tests/__snapshots__/index.test.ts.snap

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,14 @@ export { Foo };
452452
"
453453
`;
454454
455+
exports[`scss imports are externalized 1`] = `
456+
"// index.d.ts
457+
//#region tests/fixtures/css-scss/index.d.ts
458+
declare const foo: number;
459+
//#endregion
460+
export { foo };"
461+
`;
462+
455463
exports[`side effects 1`] = `
456464
"// index.d.ts
457465
export { };

tests/fixtures/css-scss/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import './styles.scss'
2+
export const foo: number = 1
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.main {
2+
color: blue;
3+
}

tests/index.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,15 @@ test('real css imports are externalized', async () => {
546546
expect(snapshot).not.toContain('.main')
547547
})
548548

549+
test('scss imports are externalized', async () => {
550+
const root = path.resolve(dirname, 'fixtures/css-scss')
551+
const { snapshot } = await rolldownBuild(path.resolve(root, 'index.ts'), [
552+
dts({ emitDtsOnly: true }),
553+
])
554+
expect(snapshot).toMatchSnapshot()
555+
expect(snapshot).not.toContain('.main')
556+
})
557+
549558
test('sub namespace', async () => {
550559
const { snapshot } = await rolldownBuild(
551560
path.resolve(dirname, 'fixtures/sub-namespace.ts'),

0 commit comments

Comments
 (0)