Unverified Commit 467b2c7e authored by Tim Neutkens's avatar Tim Neutkens Committed by GitHub

Enable sassOptions support in next.config.js (#12685)

parent e3aeb2f7
...@@ -92,6 +92,48 @@ Regular `<link>` stylesheets and global CSS files are still supported. ...@@ -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. 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. 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 ## CSS-in-JS
<details> <details>
...@@ -158,32 +200,6 @@ export default HelloWorld ...@@ -158,32 +200,6 @@ export default HelloWorld
Please see the [styled-jsx documentation](https://github.com/zeit/styled-jsx) for more examples. 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 ## Related
For more information on what to do next, we recommend the following sections: For more information on what to do next, we recommend the following sections:
......
...@@ -1032,7 +1032,7 @@ export default async function getBaseWebpackConfig( ...@@ -1032,7 +1032,7 @@ export default async function getBaseWebpackConfig(
isServer, isServer,
isReactRefreshEnabled, isReactRefreshEnabled,
assetPrefix: config.assetPrefix || '', assetPrefix: config.assetPrefix || '',
sassOptions: config.experimental.sassOptions, sassOptions: config.sassOptions,
}) })
if (typeof config.webpack === 'function') { if (typeof config.webpack === 'function') {
......
...@@ -36,6 +36,7 @@ const defaultConfig: { [key: string]: any } = { ...@@ -36,6 +36,7 @@ const defaultConfig: { [key: string]: any } = {
canonicalBase: '', canonicalBase: '',
}, },
exportTrailingSlash: false, exportTrailingSlash: false,
sassOptions: {},
experimental: { experimental: {
cpus: Math.max( cpus: Math.max(
1, 1,
...@@ -50,7 +51,6 @@ const defaultConfig: { [key: string]: any } = { ...@@ -50,7 +51,6 @@ const defaultConfig: { [key: string]: any } = {
reactMode: 'legacy', reactMode: 'legacy',
workerThreads: false, workerThreads: false,
basePath: '', basePath: '',
sassOptions: {},
pageEnv: false, pageEnv: false,
reactRefresh: true, reactRefresh: true,
}, },
......
const path = require('path') const path = require('path')
module.exports = { module.exports = {
experimental: { sassOptions: {
sassOptions: { includePaths: [path.join(__dirname, 'styles')],
includePaths: [path.join(__dirname, 'styles')],
},
}, },
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment