
ํ์ฌ์์ Docusaurus ๋ก ํ์ฌ ๋ฌธ์๋ฅผ ๊ด๋ฆฌํ๋ค.
์ด๋ ์ฌ์ฉ๋๋ Pakage ์ค ํ๋๊ฐ Redocusaurus ๋ฅผ ์ด์ฉํด์ REST API ๋ฌธ์๋ฅผ ๋ง๋ค๊ณ ์์๋๋ฐ,
ํ๋จ์ ์๋ฌ๊ฐ ๋๋ฉด์ ์๊พธ build๊ฐ ์๋์๋ค.
Error
[ERROR] Error: Unable to build website for locale en.
at tryToBuildLocale (/eric/node_modules/@docusaurus/core/lib/commands/build.js:54:19)
at async /eric/node_modules/@docusaurus/core/lib/commands/build.js:65:9
at async mapAsyncSequential (/eric/node_modules/@docusaurus/utils/lib/jsUtils.js:20:24)
at async Command.build (/eric/node_modules/@docusaurus/core/lib/commands/build.js:63:5) {
[cause]: server.bundle.js:210767
{}.DEBUG = namespaces;
^
SyntaxError: Unexpected token '.'
at new Script (node:vm:93:7)
at module.exports (/eric/node_modules/eval/eval.js:83:18)
Solution
plugins: [
...
async function customPlugin(context, opts) {
return {
name: 'custom-plugin',
configureWebpack(config, isServer, utils, content) {
// Modify internal webpack config. If returned value is an Object, it
// will be merged into the final config using webpack-merge;
// If the returned value is a function, it will receive the config as the 1st argument and an isServer flag as the 2nd argument.
return {
plugins: [
new webpack.DefinePlugin({
// IMPORTANT: To fix debug libraryโs bug
// {}.DEBUG = namespaces; // SyntaxError: Unexpected token '.'
'process.env.DEBUG': 'process.env.DEBUG',
})
]
}
},
}
}
],
ํด๋น ์๋ฌ๋ Docusaurus ํ๋ก์ ํธ๋ฅผ ๋น๋ํ ๋ ๋ฐ์ํ๋ ๋ฌธ์ ๋ก, ํนํ server.bundle.js ํ์ผ์ {}.DEBUG = namespaces; ์ค์์ ๊ตฌ๋ฌธ ์ค๋ฅ(SyntaxError: Unexpected token '.')๊ฐ ๋ฐ์ํ๊ฒ์ผ๋ก ๋ณด์๋ค.
์ด ์ค๋ฅ๋ ์๋ฐ์คํฌ๋ฆฝํธ ๋ฌธ๋ฒ ์ค๋ฅ๋ก ๋ณด์์ผ๋ฉฐ, ๊ฐ์ฒด ๋ฆฌํฐ๋ด({})์ ์ง์ ์ ์ผ๋ก ์์ฑ์ ์ถ๊ฐํ๋ ค๊ณ ํ ๋ ๋ฐ์ํ๊ฒ์ผ๋ก ๋ณด์ธ๋ค.
ํด๊ฒฐ ๋ฐฉ๋ฒ์ผ๋ก ์ ์๋ ์ฝ๋๋ Docusaurus์ ํ๋ฌ๊ทธ์ธ ์ค์ ์ ์์ ํ์ฌ Webpack์ ์ค์ ์ ๋ณ๊ฒฝํ๋ ๋ฐฉ๋ฒ์ด๋ค.
๊ตฌ์ฒด์ ์ผ๋ก webpack.DefinePlugin์ ์ฌ์ฉํ์ฌ process.env.DEBUG ํ๊ฒฝ ๋ณ์๋ฅผ ์ ์ํ๊ณ , ์ด ๋ฐฉ๋ฒ์ ํตํด ๋๋ฒ๊ทธ ๋ผ์ด๋ธ๋ฌ๋ฆฌ์ ๋ฒ๊ทธ๋ฅผ ์ฐํํ์๋ค.
์๋ฌ ๋ฐ์ ์์ธ
{}.DEBUG = namespaces;๋ ์๋ฐ์คํฌ๋ฆฝํธ์์ ์ ํจํ ๋ฌธ๋ฒ์ด ์๋๋ค.
๊ฐ์ฒด ๋ฆฌํฐ๋ด {}์ ์์ฑ์ ๋ฐ๋ก ํ ๋นํ๋ ๊ฒ์ ํ์ฉ๋์ง ์์ผ๋ฉฐ, ์ด๋ก ์ธํด ๊ตฌ๋ฌธ ์ค๋ฅ๊ฐ ๋ฐ์ํ๊ฒ์ผ๋ก ๋ณด์ธ๋ค.
ํด๊ฒฐ ๋ฐฉ๋ฒ ์ค๋ช
์ ์๋ ํด๊ฒฐ ๋ฐฉ๋ฒ์ Webpack ์ค์ ์ ์์ ํ์ฌ ์ด ๋ฌธ์ ๋ฅผ ์ฐํํ์๋ค.
webpack.DefinePlugin์ ์ฌ์ฉํ์ฌ process.env.DEBUG๋ฅผ ์ ์ํ๋ ๋ฐฉ์์ผ๋ก,
๋๋ฒ๊ทธ ๋ผ์ด๋ธ๋ฌ๋ฆฌ์์ ๋ฐ์ํ๋ ๊ตฌ๋ฌธ ์ค๋ฅ๋ฅผ ํผํ ์ ์์๋ค.
1. customPlugin ํจ์ ์ถ๊ฐ: Docusaurus ์ค์ ํ์ผ์ ์๋ก์ด ์ปค์คํ ํ๋ฌ๊ทธ์ธ์ ์ถ๊ฐ
2. configureWebpack ํจ์ ์ฌ์ฉ: ์ด ํ๋ฌ๊ทธ์ธ์ configureWebpack ํจ์๋ฅผ ํตํด Webpack ์ค์ ์ ์์
3. webpack.DefinePlugin ์ค์ :
-new webpack.DefinePlugin์ ์ฌ์ฉํ์ฌ ํ๊ฒฝ ๋ณ์๋ฅผ ์ ์.
-'process.env.DEBUG': 'process.env.DEBUG'๋ก ์ค์ ํ์ฌ, ๊ธฐ์กด์ {}.DEBUG = namespaces; ์ฝ๋๋ฅผ ๋์ฒดํ์๋ค.
๋๋ฒ๊ทธ ๋ผ์ด๋ธ๋ฌ๋ฆฌ์ DEBUG ์ค์ ์ ํ๊ฒฝ ๋ณ์๋ก ์ฒ๋ฆฌํ๋๋ก ํ์ฌ ๊ตฌ๋ฌธ ์ค๋ฅ๋ฅผ ํํผํ์๋ค.
์ด๋ ๊ฒ ์์ ํ๋ฉด, {}.DEBUG = namespaces;
๊ตฌ๋ฌธ ์ค๋ฅ๋ฅผ ํผํ ์ ์๊ณ , ๋๋ฒ๊ทธ ์ค์ ์ ์ ์์ ์ผ๋ก ์ ์ฉํ ์ ์์๋ค.
์ด ํด๊ฒฐ ๋ฐฉ๋ฒ์ ์๋ฐ์คํฌ๋ฆฝํธ์ ๋ฌธ๋ฒ ์ค๋ฅ๋ฅผ ์ฐํํ๊ณ , Docusaurus ํ๋ก์ ํธ๊ฐ ์ ์์ ์ผ๋ก ๋น๋๋ ์ ์๋๋ก ํ์ฌ์ ๊ฒฐ๊ตญ ๋น๋ํ์๋ค.