error-note's Introduction
error-note's People
error-note's Issues
205 Reset Content ์ axios
[string ํํ์ html์ ๋ ๋๋งํ๊ธฐ] ๋๊ธ์ด๋ ๊ฒ์๊ธ์์ ์ค๋ฐ๊ฟํ๊ธฐ!
CRA + TypeScript + Storybook absolute Path ์ค์
CRA + TypeScript + Storybook ์์ alias ๋ก import ๊ฒฝ๋ก ์ค์ ํ๊ธฐ
import Button '../../components/atoms/Button';
import Button '@atoms/Button';
ํ๋ก์ ํธ๋ฅผ ์งํํ๋ฉด์ import ๊ฒฝ๋ก
๊ฐ ๊ธธ์ด์ก๋ค.
์์ค ์ฝ๋๋ฅผ ๊น๋ํ๊ฒ ์ ์งํ๊ณ ์ถ์ด ๋ ๋ฆ๊ธฐ ์ ์, alias
์ค์ ์ ํ๊ธฐ๋ก ๊ฒฐ์ฌํ๋ค.
webpack์ด๋ babel์์ ์ค์ ์ ํ ์ ์์ง๋ง,
CRA์์๋ webpack๊ณผ babel์ ์ค์ ์ด ๊ฐ์ถฐ์ ธ์๋ค.
์ด๋ฅผ ์ํด์ eject๋ฅผ ํ๊ฑฐ๋, CRA์ ์ค์ ์ ์ปค์คํฐ๋ง์ด์งํ ์ ์๋ craco ๋ react-app-rewired ๋ฅผ ์ฌ์ฉํด์ผํ๋ค.
๋ฐฉ๋ฒ๋ค
1) .env์ NODE_PATH=src/ ์ถ๊ฐ ํ์
์คํฌ๋ฆฝํธ ์ ์ฉ ์๋จ
NODE_PATH=src/
CRA์์ .env
ํ์ผ์ ์์ ๊ฐ์ด NODE_PATH๋ฅผ ์ฌ์ฉํ์ฌ import ๊ฒฝ๋ก๋ฅผ ์ค์ผ ์ ์๋ค.
์ด ๋ฐฉ๋ฒ์ ๋ฐ๋ก ๊ฒฝ๋ก ์ด๋ฆ์ ์ ํ ์ ์์ด ๋ง์์ ๋ค์ง ์์๋๋ฐ, ์๋ํด๋ณด๋ ์ ์ฉ๋์ง ์์๋ค.
์ฌํ๊ฒ๋ typescript์์๋ ์ด ๋ฐฉ๋ฒ์ ์ฌ์ฉํ ์ ์๋ค.
2) eject ํ๊ธฐ
$ yarn eject
eject๋ cra๋ก ๊ตฌ์ฑํ ํ๋ก์ ํธ๋ฅผ ์ปค์คํฐ๋ง์ด์ง ํ ์ ์๋๋ก ์จ๊ฒจ์ ธ์๋ ์ค์ ์ ๋ฐ์ผ๋ก ์ถ์ถํ๋ ๋ช
๋ น์ด๋ค.
eject ๋ช
๋ น์ ์คํํ๋ฉด Webpack, babel, ESlint ๋ฑ์ ์ค์ ์ด ๋ณด์ด๊ธฐ ๋๋ฌธ์, alias ์ค์ ์ ํ๋ฉด ๋๋ค.
ํ์ง๋ง, ํ ๋ฒ ์คํํ๋ฉด ๋๋๋ฆด ์ ์๊ธฐ ๋๋ฌธ์ CRA ๋ฌธ์์์ ์ต๊ฐํ๋ฉด ์ํ๋ ๊ธฐ๋ฅ์ ํฌํจํ ๋ชจ๋์ ์ฌ์ฉํ๋ผ๊ณ ์ ํ์๋ค. cra eject
๋ฅผ ๊ตฌ๊ธ์ ๊ฒ์ํ๋๋ ๋๋ถ๋ถ์ ๊ธ๋ค์ด eject ํ์ง ์๊ณ , eject ์์ด XX ํ๊ธฐ
์๋ค. ํ ..๋ค์๋ฒ์ ๊ผญ ejectํด์ ์ด๊ฒ์ ๊ฒ ํด๋ด์ผ์ง..ใ
+Eject์ ๋ฌธ์ ์ ์ฐพ์๋ณด๊ธฐ
3) craco
craco ๋ Create React App Configuration Override์ ์ฝ์์ด๋ค. ๋ง ๊ทธ๋๋ก CRA์ ์ค์ ์ ์ค๋ฒ๋ผ์ด๋ํ ์ ์๋ ๋ชจ๋์ด๋ค. How to modify config of Create React App - without Ejecting! ์ด ๊ธ์ ์ฝ๊ณ ์ ์ ์๋์ด ๋์ผ๋, storybook์์ ์คํ๋์ง ์์๋ค. storybook๋ ์ค์ ์ด ํ์ํ๋ค.
storybook/preset-create-react-app
์ ์ฌ์ฉ ์ค์ด์๊ณ , ๋ค์์ ๊ธ๋ค์ ์ฝ์ผ๋ฉฐ ์๋ํ๋ค.
dilanx/craco#43
https://storybook.js.org/docs/configurations/custom-webpack-config/#using-your-existing-config
storybookjs/presets#109
craco์ createWebpackDevConfig ์ ์ด์ฉํ์ฌ, storybook์ custom webpack ์ค์ ์ ํ๋ คํ์ผ๋, ๊ฒฝ๋ก๋ฅผ ์ฐพ์ง ๋ชปํ์๋ค.
4) react-app-rewired + tsconfig
๊ทธ๋ ๊ฒ react-app-rewired๋ฅผ ์ฌ์ฉํ๊ฒ ๋์๋ค.
react-app-rewired๋ฅผ ์ด์ฉํ์ฌ alias๋ฅผ ์ค์ ํ๋ ๋ฐฉ๋ฒ์ ๊ตฌ๊ธ๋งํ๋ฉด ๋์จ๋ค.
ํ์ง๋ง tsconfig๊ณผ webpack alias๋ฅผ ๋ ๋ค ์ง์ ํด์ค์ผ ํ๊ณ , ํ๋ก์ ํธ์ ์คํ ๋ฆฌ๋ถ ๋๋ค ์ ์ ์๋์ด ๋์์ง๋ง
๋๋ฒ ์ ์ด์ผํด์ ์ฐ์ฐํจ์ ์ง์ธ ์ ์์๋ค. (๋๊ฐ์ ๋ด์ฉ์ด ์ค๋ณต๋๋ ๊ฑฐ ์ซ์ดํ๋ ์คํ์ผ)
tsconfig.paths.json
์ path๋ฅผ ์์ฑํ๊ณ , ์ด๋ฅผ tsconfig.json
์์ extends๋ฅผ ํ๊ณ ,
react-app-rewired์์ ํ์ํ ์ค์ ํ์ผ์ธ config-overrides.js
์์ ๋ํ tsconfig.paths.json
์ ์ฝ์ด๋ค์ด ์นํฉ ํฌ๋งท์ ๋ง๊ฒ ๋ฐ๊ฟ ์ค์ ํ๋ค. ๊ทธ๋ฆฌ๊ณ ์คํ ๋ฆฌ๋ถ์ main.js
์์ config-overrides.js
์ค์ ์ ์ฝ์๋ค.
๋ง์์ ๋ ๋ค.
STEP 1
yarn add --dev react-app-rewired
STEP2
//tsconfig.paths.json
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"~/*": ["./src/*"],
"@atoms/*": ["./src/components/atoms/*"],
//๊ธฐํ ๊ฒฝ๋ก ์ค์
}
}
}
ํ tsconfig.json
์ ๋ค์๊ณผ ๊ฐ์ด ์ถ๊ฐ
//tsconfig.json
{
"extends": "./tsconfig.paths.json",
//...tsconfigs
}
STEP3
config-overrides.js
์์ฑ
const tsconfigPaths = require("./tsconfig.paths.json")["compilerOptions"][
"paths"
];
const path = require("path");
const alias = {};
const resolve = (dir) => path.resolve(__dirname, dir);
const removeSlashStar = (arg) => arg.split("/*")[0];
Object.entries(tsconfigPaths).forEach(([key, [value]]) => {
const name = removeSlashStar(key);
const path = removeSlashStar(value);
alias[name] = resolve(path);
});
module.exports = function (config, env) {
config.resolve.alias = Object.assign(config.resolve.alias, alias);
return config;
};
STEP5
package.json
์์
"scripts": {
"start": "react-app-rewired start",
"build": "react-app-rewired build",
"test": "react-app-rewired test",
ยทยทยท
STEP6
์คํ ๋ฆฌ๋ถ ์ค์
//.storybook/main.js
module.exports = {
...configs,
webpackFinal: (config) => {
return require("../config-overrides")(config);
},
};
git commit --amend ๋๋๋ฆฌ๊ธฐ
STEP 1
git log --reflog
๋ก ํด๋น ์ปค๋ฐ ํด์ฌ๊ฐ ๋ณด๊ธฐ
STEP 2
git reset --soft ์ด์ ์ปค๋ฐ ํด์ฌ๊ฐ
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.