June 07, 2021
Parcel을 사용해 React + TypeScript 프로젝트를 세팅하는 방법을 정리하는 글입니다.
제가 좋아하는 Tailwind를 세팅하는 법까지 추가로 정리했습니다.
Parcel에 대한 정보는 아래 링크를 통해 확인하실 수 있습니다.
mkdir parcel-ts-react
cd parcel-ts-react
yarn init -y
yarn add -D parcel-bundler typescript @types/react @types/react-dom
yarn add react react-dom
{
"compilerOptions": {
"target": "es5",
"module": "esnext",
"lib": ["ESNext", "DOM"],
"jsx": "react-jsxdev",
"sourceMap": true,
"strict": true,
"moduleResolution": "node",
"baseUrl": "./src",
"paths": {
"~/*": ["./*"]
},
"typeRoots": ["node_modules/@types"],
"allowSyntheticDefaultImports": true,
"esModuleInterop": true
},
"include": ["src/**/*"]
}
"scripts": {
"start": "parcel public/index.html --open",
"build": "parcel build public/index.html --no-source-maps"
},
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Hello Parcel Bundler</title>
</head>
<body>
<noscript>You need to enable Javascript to run this application.</noscript>
<div id="root">
<!-- Your react app will be rendered here -->
</div>
<script src="../src/index.tsx"></script>
</body>
</html>
import React, { StrictMode } from 'react'
import { render } from 'react-dom'
render(
<StrictMode>
<h1>Hello Parcel Bundler</h1>
</StrictMode>,
document.getElementById('root')
)
yarn start
yarn add -D prettier eslint eslint-config-prettier @typescript-eslint/eslint-plugin eslint-plugin-react-hooks
module.exports = {
printWidth: 120,
singleQuote: true,
}
module.exports = {
env: {
browser: true,
es2021: true,
amd: true,
node: true,
},
extends: [
'eslint:recommended',
'plugin:react/recommended',
'plugin:react-hooks/recommended',
'plugin:@typescript-eslint/recommended',
'prettier',
],
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaFeatures: {
jsx: true,
},
ecmaVersion: 12,
sourceType: 'module',
},
plugins: ['react', 'react-hooks', '@typescript-eslint'],
rules: {
'@typescript-eslint/explicit-function-return-type': 'off',
},
}
yarn add -D tailwindcss@npm:@tailwindcss/postcss7-compat postcss@^7 autoprefixer@^9
module.exports = {
plugins: {
tailwindcss: 'tailwind.config.js',
autoprefixer: {},
},
}
module.exports = {
purge: ['./src/**/*.{js,jsx,ts,tsx}', './public/index.html'],
darkMode: false,
theme: {
extend: {},
},
variants: {
extend: {},
},
plugins: [],
}
@tailwind base;
@tailwind components;
@tailwind utilities;
import React, { StrictMode } from 'react'
import { render } from 'react-dom'
import './index.css'
render(
<StrictMode>
<h1 className="text-red-300">Hello Parcel Bundler</h1>
</StrictMode>,
document.getElementById('root')
)
yarn start