セットアップreactjs +タイアップスクリプトを使用して
11010 ワード
このポストでは、reactjs(typescript)でTailwind CSSを設定する方法をあなたに教えます.
我々が作り出すものはこれです.
https://hopeful-rosalind-29803f.netlify.app/
1 .作成したReactJPプロジェクトを作成する
2 .風のかかるCSSをインストールする
インストール
ファイルの変更
この手順では、2つのファイルを編集します.
5 .生成
6 .風を加える
7 .コンポーネントを作成する
8 .アプリの実行
レポ
koji / react_with_TailwindCSS
Trewind CSSによるReactJS
アプリケーションを作成する反応
このプロジェクトはブートしたCreate React App .
利用可能なスクリプト
プロジェクトディレクトリで実行できます.
オープンhttp://localhost:3000 ブラウザで表示するには.
あなたが編集をするならば、ページは再ロードされます.
コンソール内のlintエラーも表示されます.
詳しくはrunning tests を参照してください.
それは正しく束が生産モードで反応し、最適なパフォーマンスのためのビルドを最適化します.
ビルドはミニ化され、ファイル名はハッシュを含みます.
あなたのアプリケーションを展開する準備が整いました!
詳しくはdeployment を参照してください.
あなたが満足しないならば..
View on GitHub
我々が作り出すものはこれです.
https://hopeful-rosalind-29803f.netlify.app/
1 .作成したReactJPプロジェクトを作成する
$ yarn create react-app react-tailwind-ts --template typescript
2 .風のかかるCSSをインストールする
$ yarn add -D tailwindcss@npm:@tailwindcss/postcss7-compat postcss@^7 autoprefixer@^9
インストール
$ yarn add @craco/craco
ファイルの変更
この手順では、2つのファイルを編集します.
package.json
and craco.config.js
(作成)package.json
"scripts": {
"start": "craco start",
"build": "craco build",
"test": "craco test",
"eject": "react-scripts eject"
},
craco.config.js
module.exports = {
style: {
postcss: {
plugins: [require("tailwindcss"), require("autoprefixer")],
},
},
};
5 .生成
tailwind.config.js
このステップでは、我々は生成されますtailwind.config.js
以下のコマンドと編集によってpurge
.$ yarn tailwindcss-cli@latest init
tailwind.config.js
module.exports = {
purge: ["./src/**/*.{js,jsx,ts,tsx}", "./public/index.html"],
darkMode: false, // or 'media' or 'class'
theme: {
extend: {},
},
variants: {
extend: {},
},
plugins: [],
};
6 .風を加える
index.css
@tailwind base;
@tailwind components;
@tailwind utilities;
index.tsx
import React from "react";
import ReactDOM from "react-dom";
import "./index.css";
import App from "./App";
import reportWebVitals from "./reportWebVitals";
ReactDOM.render(<App />, document.getElementById("root"));
reportWebVitals();
7 .コンポーネントを作成する
Gradient Text
components/GradientText.tsx
type Props = {
text: string;
};
export const GradientText = ({ text }: Props) => {
return (
<div className="p-10 min-h-screen flex items-center justify-center bg-cool-gray-700">
<h1 className="text-9xl font-black text-white text-center">
<span className="bg-gradient-to-r text-transparent bg-clip-text from-green-400 to-purple-500">
{text}
</span>
</h1>
</div>
);
};
8 .アプリの実行
$ yarn start
すべてがうまくいくならば、あなたは以下のイメージを見ます.レポ
koji / react_with_TailwindCSS
Trewind CSSによるReactJS
アプリケーションを作成する反応
このプロジェクトはブートしたCreate React App .
利用可能なスクリプト
プロジェクトディレクトリで実行できます.
yarn start
開発モードでアプリケーションを実行します.オープンhttp://localhost:3000 ブラウザで表示するには.
あなたが編集をするならば、ページは再ロードされます.
コンソール内のlintエラーも表示されます.
yarn test
インタラクティブウォッチモードでテストランナーを起動します.詳しくはrunning tests を参照してください.
yarn build
生産のためのアプリケーションをビルドしますbuild
フォルダ.それは正しく束が生産モードで反応し、最適なパフォーマンスのためのビルドを最適化します.
ビルドはミニ化され、ファイル名はハッシュを含みます.
あなたのアプリケーションを展開する準備が整いました!
詳しくはdeployment を参照してください.
yarn eject
注意:これは一方向操作です.一度eject
, あなたは戻って行くことはできません!あなたが満足しないならば..
View on GitHub
Reference
この問題について(セットアップreactjs +タイアップスクリプトを使用して), 我々は、より多くの情報をここで見つけました https://dev.to/0xkoji/setup-reactjs-typescript-with-tailwind-css-2k0iテキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol