๐ Pre & Post scripts๋ฅผ ์์๋ณด์
SEO ์ต์ ํ๋ฅผ ์ํด Sitemap ์์
์ค package.json ํ์ผ ๋ด๋ถ์ postbuild script๋ฅผ ์์ฑํ๋ ์์
์ด ์์๋ค. ์ด์ ๊น์ง๋ pre์ post prefix๋ฅผ ์ฌ์ฉํ๋ ์ผ์ด ๊ฑฐ์ ์์ด ์ด๊ฒ๋ค์ด ํ๋ ์ญํ ์ ์์ธํ ์์ง ๋ชปํ๋๋ฐ, ์ด๋ฒ์ ์์๋ณด๊ณ ์ npmjs ๊ณต์๋ฌธ์๋ฅผ ์ดํด๋ดค๋ค. ๊ณต์๋ฌธ์์์๋ pre์ post scripts๋ฅผ ๋ค์์ฒ๋ผ ์ ์ํ๊ณ ์์๋ค.
To create "pre" or "post" scripts for any scripts defined in the "scripts" section of the package.json, simply create another script with a matching name and add "pre" or "post" to the beginning of them.
์์ฝํ์๋ฉด pre ๋๋ post์ scripts ์ด๋ฆ์ ๋์ผํ๊ฒ ๋ง๋ค๊ณ , prefix์ pre ๋๋ post์ ์ถ๊ฐํ๋ฉด ๋๋ค๋ ๋ป์ธ๋ฐ, ๊ฒฐ๋ก ์ ์ผ๋ก pre<script>, <script>, <postscript>๊ฐ ๋ชจ๋ ์กด์ฌํ๋ค๋ฉด, ์คํ์์๋ precompress -> comporess -> postcompress๊ฐ ๋๋ ๊ฒ์ด๋ค.
์ฌ๊ธฐ์ ์ค์ํ ๊ฒ์ npm run ์ปค๋งจ๋ ์ฌ์ฉ์ precompress, compress, postcompress ๋ชจ๋๋ฅผ ์
๋ ฅํ๋๊ฒ์ด ์๋๋ผ npm run compress ์คํฌ๋ฆฝํธ๋ง ์
๋ ฅํ๋ฉด scripts๊ฐ ๋ค์ ์์๋๋ก ๋์ํ๋ ๊ฒ์ด๋ค.
{
"scripts": {
"precompress": "{{ executes BEFORE the `compress` script }}",
"compress": "{{ run command to compress files }}",
"postcompress": "{{ executes AFTER `compress` script }}"
}
}
๋๋ scripts๋ฅผ ๋ค์์ฒ๋ผ ์ ์ํ๊ณ , npm run build ์ปค๋งจ๋๋ง ์
๋ ฅํด๋ ์๋์ผ๋ก build -> postbuild์ ์์๋ก script๊ฐ ์คํ๋์๋ค.
{
"scripts": {
"build": "next build",
"postbuild": "next-sitemap",
}
}
๊ทธ๋ ๋ค๊ณ ๋ชจ๋ scripts๊ฐ ์์ ์ธ๊ธํ๋ ์์๋ก ๋์ํ๋ ๊ฒ์ ์๋๋ค. ๋ช ๊ฐ์ง ํน์ scripts์๋ ๊ธฐ์กด life cycle๊ณผ๋ ๋ค๋ฅด๊ฒ ์ค์ ๋์ด์๋๋ฐ pre<event> -> post<event> -> <event> ์์๋ก ๋์ํ๋ค.
prepare,prepublish,prepublishOnly,prepack,postpack,dependencies
ํน์ script์ life cycle์ ๋ ์์ธํ ์๊ณ ์ถ๋ค๋ฉด ํ๋จ Reference 2๋ฒ ๋งํฌ๋ฅผ ํด๋ฆญํด ๋ณด์.
Reference
๋๊ธ