razzle-eslint-plugin์ ์ถ๊ฐํ๊ณ razzle.config.js์ ๋ค์๊ณผ ๊ฐ์ด ํฌํจํ์ต๋๋ค.
plugins: ['scss', 'eslint']
๋ฌธ์ ๋ ์ฝ์์ด typescript ํ์ผ์ ๋ํ Lint ๊ฒฝ๊ณ ๋ฅผ ํ์ํ์ง ์๋๋ค๋ ๊ฒ์
๋๋ค. ์ฝ์์์ eslint๋ฅผ ์๋์ผ๋ก ์คํํ๋ฉด Lint ์ค๋ฅ๊ฐ ํ์๋์ง๋ง razzle start
์คํ ์ค์๋ ํ์๋์ง ์์ต๋๋ค.
razzle-eslint-plugin
์์ค๋ฅผ ํ์ธํ๋ฉด ๊ท์น์ด ์๋์ ํ์๋๋๋ก ํ์ธํ js ๋ฐ jsx ํ์ผ ๋ง ์ธ๊ธํ๋ ๊ฒ์ ๋ณผ ์ ์์ต๋๋ค.
config.module.rules = [
{
test: /\.(js|jsx|mjs)$/,
enforce: 'pre',
loader: require.resolve('eslint-loader'),
options: mainEslintOptions,
exclude: /node_modules/,
},
...config.module.rules,
]
์์ ๊ตฌ์ฑ์ ts|tsx
๋ฅผ ์ถ๊ฐํ๋ฉด ์ฆ์ ๊ฒฝ๊ณ ๋ฅผ ๋ณผ ์ ์์ต๋๋ค. ๊ทธ๋ฌ๋ ๊ทธ๊ฒ์ ๋ด๊ฐ ํผํ๊ณ ์ถ์ node_modules
ํ์ผ์ ์๋์ผ๋ก ํธ์งํด์ผํฉ๋๋ค. razzle.config.js์์ ๊ตฌ์ฑ์ ํ์ฅ ํ ์์๋ ๋ฐฉ๋ฒ์ด ์์ต๋๊น? module.rules.push
ํตํด ์ ๊ท์น์ ํธ์ํ๋ ค๊ณ ํ์ง๋ง These relative modules were not found:
์ค๋ฅ๊ฐ ๋ฐ์ํฉ๋๋ค.
์ด๊ฒ์ด razzle-eslint-plugin
์ถ๊ฐ๋์ด์ผํ๋ค๋ฉด PR์ ์ฌ๋ฆด ์ ์์ต๋๋ค. ์ ์ํ์ญ์์ค
razzle.config.js
ํ์ผ์ ๋ค์ ์ค์ ์ ์ง์ ํ์ต๋๋ค.
'use strict'
module.exports = {
plugins: [
{
name: 'typescript',
options: {
useBabel: true,
useEslint: true,
forkTsChecker: {
tsconfig: './tsconfig.json',
tslint: undefined,
watch: './src',
typeCheck: true
}
}
}
]
}
๋ค์๊ณผ ๊ฐ์ด .eslintrc.json
{
"extends": [
"eslint:recommended",
"prettier",
"plugin:jsx-a11y/recommended",
"plugin:@typescript-eslint/recommended",
"plugin:react/recommended"
],
"plugins": ["@typescript-eslint"],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module",
"ecmaFeatures": {
"modules": true,
"jsx": true
}
},
"env": {
"browser": true,
"node": true,
"jest": true
},
"settings": {
"react": {
"version": "detect"
},
"import/resolver": {
"node": {
"extensions": [".js", ".jsx", ".ts", ".tsx"]
}
}
}
}
๊ทธ๋ฐ ๋ค์ ๋ด package.json
์์ ๋ค์ ํ์ linting์ ์ํํฉ๋๋ค.
"lint": "eslint --ext 'js,jsx,ts,tsx' .",
@andersnylund ์
๋ ฅ npm run lint
๋ฅผ ์คํํ๋ฉด ๋ง์ Lint ๊ฒฝ๊ณ ๋ฅผ ๋ณผ ์ ์์ต๋๋ค. CRA ํ๋ก์ ํธ ์์์ฒ๋ผ ์ฝ์์์ ๋ฐ๋ก ๊ฒฝ๊ณ ๋ฅผ ๋ณผ ์ ์๋ค๋ฉด ํจ์ฌ ๋ ๋์ ๊ฒฝํ์ด ๋ ๊ฒ์
๋๋ค.
์ด๊ฒ์ ๋ด ํ์ฌ ๊ตฌ์ฑ์ ๋๋ค.
const path = require('path')
module.exports = {
plugins: ['scss', 'eslint'],
modify(defaultConfig, { target, dev }, webpack) {
const config = defaultConfig
config.resolve.extensions.push('.ts', '.tsx')
config.module.rules.push({
test: /\.(ts|js)x?$/,
exclude: /node_modules/,
loader: 'babel-loader',
})
if (target === 'node' && !dev) {
config.entry = path.resolve(__dirname, './src/server.tsx')
config.output.filename = 'server.bundle.js'
config.output.path = path.resolve(__dirname, './build')
config.output.libraryTarget = 'commonjs2'
}
return config
}
}
Tslint๋ 2019 ๋ ์ธ์ ๊ฐ ESLint์์ ์ฌ์ฉ์ด ์ค๋จ๋๊ณ 11 ์ ์ค์ ์ฏค์ด๋ฏ๋ก razzle์ ์๋ง๋ ESLint๋ก ์ ํ ํ ๊ณํ์ ์ธ์์ผ ํ ๊ฒ์ ๋๋ค.
๋ง์ง๋ง์ผ๋ก ์๋ ๊ตฌ์ฑ์ ์ฌ์ฉํ์ฌ ์ฝ์์์ Typescript ์ค๋ฅ์ ESLint ๊ฒฝ๊ณ ๋ฅผ ๋ชจ๋ ์ป์ ์์์์ต๋๋ค.
const ForkTSCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin')
const path = require('path')
module.exports = {
modify(defaultConfig, { target, dev }, webpack) {
const config = defaultConfig
config.resolve.extensions.push('.ts', '.tsx')
config.plugins.push(
new ForkTSCheckerWebpackPlugin({
checkSyntacticErrors: true,
eslint: true,
}))
config.module.rules.push({
test: /\.(ts|js)x?$/,
include: [path.resolve(__dirname, 'src')],
loader: 'babel-loader',
})
}
}
๊ทธ๋ฆฌ๊ณ typescript ํ์๊ฐ์๋ ํ๋ก์ ํธ ๋ฃจํธ์ .eslintrc
ํ์ผ์ด ์์ต๋๋ค.
@ fifn2 @ aswin-s ๋ฌธ์ ๋ razzle-plugin-typescript๊ฐ ์ฌ์ฉํ๋ Fork TS Checker Webpack ํ๋ฌ๊ทธ์ธ์ด ์ค๋๋์๊ณ (v0.4.1) eslint๋ฅผ ์ง์ํ์ง ์๋๋ค๋ ๊ฒ์ ๋๋ค. # 1174์์ ํ๋ฌ๊ทธ์ธ์ ์ ๋ฐ์ดํธํ๊ธฐ ์ํด PR์ ๋ง๋ค์์ต๋๋ค.
์ด PR์ ์ฌ์ฉํ ์ค๋น๊ฐ ๋์์ต๋๊น?
@ imagine10255 ์ด๊ฒ์ PR์ด ์๋์ง๋ง ์ฐ๋ฆฌ๋ ์ด๊ฒ์์ํ ๊ณํ์ด ์์ต๋๋ค
๋ช ์ฃผ ์์ typescript๋ฅผ ์ง์ํ์ฌ razzle-plugin-eslint
์ ์ ๋ฒ์ ์ ์ถ์ ํ ์์ ์
๋๋ค.
@ nimaa77 ๊ฐ์ฌํฉ๋๋ค. ํ์ฌ typescript๋ฅผ ํตํฉํ๊ณ ์์ต๋๋ค. ๋จผ์ ์ฌ์ฉํ ๋ฐฉ๋ฒ์ด ์์ต๋๊น?
@ nimaa77 ์ ๋ฐ์ดํธ๊ฐ ์์ต๋๊น? ๋๋ ๋์ธ ๋ฐฉ๋ฒ์ด ์์ต๋๊น?
์ด๊ฒ์ ๊ฐ๋ฅํ๋ค. ์ด์ github ํ ๋ก ์ด ํ์ฑํ๋์์ต๋๋ค. ์ฌ๊ธฐ๋ก ์ด๋ํ์ญ์์ค :) ๋ํ ์๋ก์ด typescript ํ๋ฌ๊ทธ์ธ์ eslint๋ฅผ ์ฌ์ฉํฉ๋๋ค.
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
Tslint๋ 2019 ๋ ์ธ์ ๊ฐ ESLint์์ ์ฌ์ฉ์ด ์ค๋จ๋๊ณ 11 ์ ์ค์ ์ฏค์ด๋ฏ๋ก razzle์ ์๋ง๋ ESLint๋ก ์ ํ ํ ๊ณํ์ ์ธ์์ผ ํ ๊ฒ์ ๋๋ค.