nextjs global scss variables
To use global SCSS variables in a Next.js project, you can follow these steps:
Create a new file called
_variables.scss
in your project'sstyles
directory. This file will hold your global SCSS variables.Define your SCSS variables in the
_variables.scss
file. For example, you can define a primary color variable like this:
scss
$primary-color: #ff0000;
- Import the
_variables.scss
file in yourstyles/global.scss
file. This will make the variables available globally in your project.
scss
@import 'variables';
- Import the
global.scss
file in your Next.js configuration file, usually_app.js
or_app.tsx
, located in thepages
directory.
```jsx import '../styles/global.scss';
function MyApp({ Component, pageProps }) { // Your code here }
export default MyApp; ```
- You can now use the global SCSS variables in your components by importing the
styles/global.scss
file.
```jsx import styles from '../styles/global.scss';
function MyComponent() { return (
Hello, world!
export default MyComponent; ```
- Finally, you can use the global SCSS variables in your SCSS files by referencing them with the
$
symbol. For example:
scss
.container {
background-color: $primary-color;
}
This is the step-by-step process to use global SCSS variables in a Next.js project. By following these steps, you can define and use global SCSS variables throughout your project, making it easier to manage and update your styles.