Skip to content

Commit a189a4d

Browse files
samcxztannerijjk
authored
chore(sass): add docs for implementation property in sassOptions and update sassOption types (#70428)
## Why? We currently don't document the `implementation` property for `sassOptions`. Since this is one our maintained properties, we should also update the types for `sassOptions`. - Fixes #70020 --------- Co-authored-by: Zack Tanner <[email protected]> Co-authored-by: JJ Kasper <[email protected]>
1 parent 33c1eb7 commit a189a4d

File tree

5 files changed

+107
-11
lines changed

5 files changed

+107
-11
lines changed

docs/02-app/01-building-your-application/05-styling/03-sass.mdx

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,58 @@ npm install --save-dev sass
2424
2525
### Customizing Sass Options
2626

27-
If you want to configure the Sass compiler, use `sassOptions` in `next.config.js`.
27+
If you want to configure your Sass options, use `sassOptions` in `next.config`.
2828

29-
```js filename="next.config.js"
30-
const path = require('path')
29+
```ts filename="next.config.ts" switcher
30+
import type { NextConfig } from 'next'
3131

32-
module.exports = {
32+
const nextConfig: NextConfig = {
3333
sassOptions: {
34-
includePaths: [path.join(__dirname, 'styles')],
34+
additionalData: `$var: red;`,
3535
},
3636
}
37+
38+
export default nextConfig
39+
```
40+
41+
```js filename="next.config.js" switcher
42+
/** @type {import('next').NextConfig} */
43+
44+
const nextConfig = {
45+
sassOptions: {
46+
additionalData: `$var: red;`,
47+
},
48+
}
49+
50+
module.exports = nextConfig
51+
```
52+
53+
#### Implementation
54+
55+
You can use the `implementation` property to specify the Sass implementation to use. By default, Next.js uses the [`sass`](https://www.npmjs.com/package/sass) package.
56+
57+
```ts filename="next.config.ts" switcher
58+
import type { NextConfig } from 'next'
59+
60+
const nextConfig: NextConfig = {
61+
sassOptions: {
62+
implementation: 'sass-embedded',
63+
},
64+
}
65+
66+
export default nextConfig
67+
```
68+
69+
```js filename="next.config.js" switcher
70+
/** @type {import('next').NextConfig} */
71+
72+
const nextConfig = {
73+
sassOptions: {
74+
implementation: 'sass-embedded',
75+
},
76+
}
77+
78+
module.exports = nextConfig
3779
```
3880

3981
### Sass Variables
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
---
2+
title: sassOptions
3+
description: Configure Sass options.
4+
---
5+
6+
`sassOptions` allow you to configure the Sass compiler.
7+
8+
```ts filename="next.config.ts" switcher
9+
import type { NextConfig } from 'next'
10+
11+
const sassOptions = {
12+
additionalData: `
13+
$var: red;
14+
`,
15+
}
16+
17+
const nextConfig: NextConfig = {
18+
sassOptions: {
19+
...sassOptions,
20+
implementation: 'sass-embedded',
21+
},
22+
}
23+
24+
export default nextConfig
25+
```
26+
27+
```js filename="next.config.js" switcher
28+
/** @type {import('next').NextConfig} */
29+
30+
const sassOptions = {
31+
additionalData: `
32+
$var: red;
33+
`,
34+
}
35+
36+
const nextConfig = {
37+
sassOptions: {
38+
...sassOptions,
39+
implementation: 'sass-embedded',
40+
},
41+
}
42+
43+
module.exports = nextConfig
44+
```
45+
46+
> **Good to know:** `sassOptions` are not typed outside of `implementation` because Next.js does not maintain the other possible properties.

docs/02-app/02-api-reference/05-next-config-js/useLightningcss.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ version: experimental
66

77
Experimental support for using [Lightning CSS](https://lightningcss.dev), a fast CSS bundler and minifier, written in Rust.
88

9-
```ts filename="next.config.ts"
9+
```ts filename="next.config.ts" switcher
1010
import type { NextConfig } from 'next'
1111

1212
const nextConfig: NextConfig = {
@@ -18,7 +18,7 @@ const nextConfig: NextConfig = {
1818
export default nextConfig
1919
```
2020

21-
```js filename="next.config.js"
21+
```js filename="next.config.js" switcher
2222
/** @type {import('next').NextConfig} */
2323
const nextConfig = {
2424
experimental: {

packages/next/src/server/config-schema.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -602,8 +602,13 @@ export const configSchema: zod.ZodType<NextConfig> = z.lazy(() =>
602602
)
603603
)
604604
.optional(),
605-
// saas option is unknown, use z.any() here
606-
sassOptions: z.record(z.string(), z.any()).optional(),
605+
// sassOptions properties are unknown besides implementation, use z.any() here
606+
sassOptions: z
607+
.object({
608+
implementation: z.string().optional(),
609+
})
610+
.catchall(z.any())
611+
.optional(),
607612
serverExternalPackages: z.array(z.string()).optional(),
608613
serverRuntimeConfig: z.record(z.string(), z.any()).optional(),
609614
skipMiddlewareUrlNormalize: z.boolean().optional(),

packages/next/src/server/config-shared.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -770,8 +770,11 @@ export interface NextConfig extends Record<string, any> {
770770
*/
771771
basePath?: string
772772

773-
/** @see [Customizing sass options](https://nextjs.org/docs/basic-features/built-in-css-support#customizing-sass-options) */
774-
sassOptions?: { [key: string]: any }
773+
/** @see [Customizing sass options](https://nextjs.org/docs/app/api-reference/next-config-js/sassOptions) */
774+
sassOptions?: {
775+
implementation?: string
776+
[key: string]: any
777+
}
775778

776779
/**
777780
* Enable browser source map generation during the production build

0 commit comments

Comments
 (0)