Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
467b2c7e
Unverified
Commit
467b2c7e
authored
May 11, 2020
by
Tim Neutkens
Committed by
GitHub
May 11, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Enable sassOptions support in next.config.js (#12685)
parent
e3aeb2f7
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
46 additions
and
32 deletions
+46
-32
built-in-css-support.md
docs/basic-features/built-in-css-support.md
+42
-26
webpack-config.ts
packages/next/build/webpack-config.ts
+1
-1
config.ts
packages/next/next-server/server/config.ts
+1
-1
next.config.js
...n/scss-fixtures/basic-module-include-paths/next.config.js
+2
-4
No files found.
docs/basic-features/built-in-css-support.md
View file @
467b2c7e
...
...
@@ -92,6 +92,48 @@ Regular `<link>` stylesheets and global CSS files are still supported.
In production, all CSS Module files will be automatically concatenated into
**many minified and code-split**
`.css`
files.
These
`.css`
files represent hot execution paths in your application, ensuring the minimal amount of CSS is loaded for your application to paint.
## Sass Support
Next.js allows you to import Sass using both the
`.scss`
and
`.sass`
extensions.
You can use component-level Sass via CSS Modules and the
`.module.scss`
or
`.module.sass`
extension.
Before you can use Next.js' built-in Sass support, be sure to install
[
`sass`
](
https://github.com/sass/sass
)
:
```
bash
npm
install
sass
```
Sass support has the same benefits and restrictions as the built-in CSS support detailed above.
### Customizing Sass Options
If you want to configure the Sass compiler you can do so by using
`sassOptions`
in
`next.config.js`
.
For example to add
`includePaths`
:
```
js
const
path
=
require
(
'path'
)
module
.
exports
=
{
sassOptions
:
{
includePaths
:
[
path
.
join
(
__dirname
,
'styles'
)],
},
}
```
## Less and Stylus Support
To support importing
`.less`
or
`.styl`
files you can use the following plugins:
-
[
@zeit/next-less
](
https://github.com/zeit/next-plugins/tree/master/packages/next-less
)
-
[
@zeit/next-stylus
](
https://github.com/zeit/next-plugins/tree/master/packages/next-stylus
)
If using the less plugin, don't forget to add a dependency on less as well, otherwise you'll see an error like:
```
bash
Error: Cannot find module
'less'
```
## CSS-in-JS
<details>
...
...
@@ -158,32 +200,6 @@ export default HelloWorld
Please see the
[
styled-jsx documentation
](
https://github.com/zeit/styled-jsx
)
for more examples.
## Sass Support
Next.js allows you to import Sass using both the
`.scss`
and
`.sass`
extensions.
You can use component-level Sass via CSS Modules and the
`.module.scss`
or
`.module.sass`
extension.
Before you can use Next.js' built-in Sass support, be sure to install
[
`sass`
](
https://github.com/sass/sass
)
:
```
bash
npm
install
sass
```
Sass support has the same benefits and restrictions as the built-in CSS support detailed above.
## Less and Stylus Support
To support importing
`.less`
or
`.styl`
files you can use the following plugins:
-
[
@zeit/next-less
](
https://github.com/zeit/next-plugins/tree/master/packages/next-less
)
-
[
@zeit/next-stylus
](
https://github.com/zeit/next-plugins/tree/master/packages/next-stylus
)
If using the less plugin, don't forget to add a dependency on less as well, otherwise you'll see an error like:
```
bash
Error: Cannot find module
'less'
```
## Related
For more information on what to do next, we recommend the following sections:
...
...
packages/next/build/webpack-config.ts
View file @
467b2c7e
...
...
@@ -1032,7 +1032,7 @@ export default async function getBaseWebpackConfig(
isServer
,
isReactRefreshEnabled
,
assetPrefix
:
config
.
assetPrefix
||
''
,
sassOptions
:
config
.
experimental
.
sassOptions
,
sassOptions
:
config
.
sassOptions
,
})
if
(
typeof
config
.
webpack
===
'function'
)
{
...
...
packages/next/next-server/server/config.ts
View file @
467b2c7e
...
...
@@ -36,6 +36,7 @@ const defaultConfig: { [key: string]: any } = {
canonicalBase
:
''
,
},
exportTrailingSlash
:
false
,
sassOptions
:
{},
experimental
:
{
cpus
:
Math
.
max
(
1
,
...
...
@@ -50,7 +51,6 @@ const defaultConfig: { [key: string]: any } = {
reactMode
:
'legacy'
,
workerThreads
:
false
,
basePath
:
''
,
sassOptions
:
{},
pageEnv
:
false
,
reactRefresh
:
true
,
},
...
...
test/integration/scss-fixtures/basic-module-include-paths/next.config.js
View file @
467b2c7e
const
path
=
require
(
'path'
)
module
.
exports
=
{
experimental
:
{
sassOptions
:
{
includePaths
:
[
path
.
join
(
__dirname
,
'styles'
)],
},
sassOptions
:
{
includePaths
:
[
path
.
join
(
__dirname
,
'styles'
)],
},
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment