0
0

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+Tailwindcssの環境構築

Last updated at Posted at 2022-03-13

やりたいこと

Next.js+Tailwindcssの環境構築

開発環境

Windows 10Pro

方法(2022/3/13時点)

  • Next.jsのプロジェクト作成
    以下コマンド実行
npx create-next-app --typescript

プロジェクト名を入力して作成する
tempsnip.png

  • Tailwindcssのインストール
    以下コマンド実行
yarn add -D tailwindcss postcss autoprefixer

以下コマンド実行でtailwind.config.jspostcss.config.js を作成

npx tailwindcss init -p
  • パスの設定を変更する
    tailwind.config.jsを以下に変更
tailwind.config.js
module.exports = {
  content: [
    "./pages/**/*.{js,ts,jsx,tsx}",
    "./components/**/*.{js,ts,jsx,tsx}",
  ],
  theme: {
    extend: {},
  },
  plugins: [],
}
  • globals.cssを変更する
    globals.cssを以下に変更
globals.css
@tailwind base;
@tailwind components;
@tailwind utilities;

  • index.jsを変更して確認する
    index.jsを以下に変更
index.js
export default function Home() {
  return (
    <h1 className="text-3xl font-bold underline">
      Hello world!
    </h1>
  )
}

確認できた
キャプチャ.PNG

注意事項

globals.cssの@tailwindがimportされない現象
windowsで環境構築を行ったが、Unknown at rule @tailwind となり、Tailwindcssの設定がうまくimportされなかった

解決策

VSCode拡張機能PostCSS Language Supportを入れる

キャプチャ.PNG

参考記事

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?