Next.js: ํŽ˜์ด์ง€์— ๋ฌด์–ธ๊ฐ€๋ฅผ ์ถ”๊ฐ€ํ•˜๊ธฐ ์œ„ํ•œ ํ•ญ๋ชฉ ํŒŒ์ผ์„ ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค(์˜ˆ: ํด๋ฆฌํ•„).

์— ๋งŒ๋“  2017๋…„ 02์›” 03์ผ  ยท  3์ฝ”๋ฉ˜ํŠธ  ยท  ์ถœ์ฒ˜: vercel/next.js

// in next.config.js

module.exports = {
  entry: "./entry",
};

// or

module.exports = {
  entry: {
    client: "./entry/client",
    server: "./entry/server",
  },
};

๊ฐ€์žฅ ์œ ์šฉํ•œ ๋Œ“๊ธ€

ํ˜„์žฌ ํ•ด๊ฒฐ ๋ฐฉ๋ฒ•์€ ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.

์ถ”๊ฐ€ import "../entry/server.js"; ์— pages/_document.js ์™€์— ์•„๋ž˜์˜ ์ฝ”๋“œ๋ฅผ ์ถ”๊ฐ€ next.config.js .

module.exports = {
  webpack: (config) => {
    const entryFactory = config.entry;
    config.entry = () => (
      entryFactory()
        .then((entry) => {
          entry["main.js"] = [
            "./entry/client.js",
            ...entry["main.js"],
          ];
          return entry;
        })
    );
    return config;
  },
};

๋ชจ๋“  3 ๋Œ“๊ธ€

ํ˜„์žฌ ํ•ด๊ฒฐ ๋ฐฉ๋ฒ•์€ ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.

์ถ”๊ฐ€ import "../entry/server.js"; ์— pages/_document.js ์™€์— ์•„๋ž˜์˜ ์ฝ”๋“œ๋ฅผ ์ถ”๊ฐ€ next.config.js .

module.exports = {
  webpack: (config) => {
    const entryFactory = config.entry;
    config.entry = () => (
      entryFactory()
        .then((entry) => {
          entry["main.js"] = [
            "./entry/client.js",
            ...entry["main.js"],
          ];
          return entry;
        })
    );
    return config;
  },
};

์œ„์˜ ์ฝ”๋“œ๋Š” ์ค‘์ฒฉ๋œ entry ๋ฐฐ์—ด์„ ๋งŒ๋“ญ๋‹ˆ๋‹ค. ๊ทธ๊ฒƒ์ด ํ•„์š”ํ•œ ๊ฒƒ์ž…๋‹ˆ๊นŒ, ์•„๋‹ˆ๋ฉด ํ™•์‚ฐ์ด ์žˆ์–ด์•ผ ํ•˜๋Š” ๊ฒƒ์ž…๋‹ˆ๊นŒ?

module.exports = {
  webpack: (config) => {
    const entryFactory = config.entry;
    config.entry = () => (
      entryFactory()
        .then((entry) => {
          entry["main.js"] = [
            "./entry/client.js",
            ...entry["main.js"], // <-- Flatten the array?
          ];
          return entry;
        })
    );
    return config;
  },
};

๋„ค @jcheroske ๊ท€ํ•˜์˜ ์ œ์•ˆ์ด ๋งž์Šต๋‹ˆ๋‹ค.
์›๋ณธ ์ฝ”๋“œ๋ฅผ ์—…๋ฐ์ดํŠธํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

๊ทธ๋ฆฌ๊ณ  ์ด ๋ฌธ์ œ๋ฅผ ๋‹ซ์Šต๋‹ˆ๋‹ค.

์ด ํŽ˜์ด์ง€๊ฐ€ ๋„์›€์ด ๋˜์—ˆ๋‚˜์š”?
0 / 5 - 0 ๋“ฑ๊ธ‰