Skip to content

Commit a7a924f

Browse files
Timerijjk
authored andcommitted
Disable New CSS For Sass, Less, and Stylus (vercel#10043)
1 parent 5c6a20d commit a7a924f

File tree

5 files changed

+58
-11
lines changed

5 files changed

+58
-11
lines changed

packages/next/build/webpack-config.ts

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -865,18 +865,31 @@ export default async function getBaseWebpackConfig(
865865
return false
866866
}
867867

868-
const fileName = '/tmp/test.css'
869-
870-
if (rule instanceof RegExp && rule.test(fileName)) {
868+
const fileNames = [
869+
'/tmp/test.css',
870+
'/tmp/test.scss',
871+
'/tmp/test.sass',
872+
'/tmp/test.less',
873+
'/tmp/test.styl',
874+
]
875+
876+
if (rule instanceof RegExp && fileNames.some(input => rule.test(input))) {
871877
return true
872878
}
873879

874880
if (typeof rule === 'function') {
875-
try {
876-
if (rule(fileName)) {
877-
return true
878-
}
879-
} catch (_) {}
881+
if (
882+
fileNames.some(input => {
883+
try {
884+
if (rule(input)) {
885+
return true
886+
}
887+
} catch (_) {}
888+
return false
889+
})
890+
) {
891+
return true
892+
}
880893
}
881894

882895
if (Array.isArray(rule) && rule.some(canMatchCss)) {
@@ -888,10 +901,9 @@ export default async function getBaseWebpackConfig(
888901

889902
if (config.experimental.css) {
890903
const hasUserCssConfig =
891-
webpackConfig.module &&
892-
webpackConfig.module.rules.some(
904+
webpackConfig.module?.rules.some(
893905
rule => canMatchCss(rule.test) || canMatchCss(rule.include)
894-
)
906+
) ?? false
895907

896908
if (hasUserCssConfig) {
897909
if (webpackConfig.module?.rules.length) {
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
const withSass = require('@zeit/next-sass')
2+
module.exports = withSass({})
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import '../styles/style.scss'
2+
3+
export default () => <div className="example">Hello World!</div>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
$color: #2ecc71;
2+
.example {
3+
background-color: $color;
4+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/* eslint-env jest */
2+
/* global jasmine */
3+
import { remove } from 'fs-extra'
4+
import { nextBuild } from 'next-test-utils'
5+
import { recursiveReadDir } from 'next/dist/lib/recursive-readdir'
6+
import { join } from 'path'
7+
8+
jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 60 * 1
9+
10+
const appDir = join(__dirname, '../')
11+
12+
describe('Legacy Sass Support Should Disable New CSS', () => {
13+
beforeAll(async () => {
14+
await remove(join(appDir, '.next'))
15+
await nextBuild(appDir)
16+
})
17+
18+
it(`should've emitted a single CSS file`, async () => {
19+
const cssFiles = await recursiveReadDir(
20+
join(appDir, '.next', 'static'),
21+
/\.css$/
22+
)
23+
24+
expect(cssFiles.length).toBe(1)
25+
})
26+
})

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy