2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Next.js の CSS Modules で変数などの共通で読み込みたいファイルの読み込み処理を共通化する方法

2
Posted at

Next.jsでCSS Modules(SCSS)などを使っている時などに、メディアクエリーや共通の変数を定義したファイルを新しくscssファイルつくるたびに読み込まなくてはならないのは地味にめんどくさいです。

next.config.jsのsass optionsに設定を記入することで共通scssファイルの読み込み処理を自動化できます。

next.config.js
module.exports = {
  ‥‥‥‥‥‥‥‥‥‥‥‥
  sassOptions: {
    prependData: `
    @use '@variables' as *;
    `,
  },
  ‥‥‥‥‥‥‥‥
};

これでscssファイルの冒頭に自動で @use '@variables' as *; 文(tsConfigで@variablesのaliasを設定している)が挿入されてくれます。便利です。

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?