Next.js: Eintragsdatei hinzufügen, um etwas über Seiten hinzuzufügen (wie Polyfills).

Erstellt am 3. Feb. 2017  ·  3Kommentare  ·  Quelle: vercel/next.js

// in next.config.js

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

// or

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

Hilfreichster Kommentar

Hier ist eine Problemumgehung für jetzt:

Hinzufügen von import "../entry/server.js"; in pages/_document.js und Hinzufügen des folgenden Codes zu 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;
  },
};

Alle 3 Kommentare

Hier ist eine Problemumgehung für jetzt:

Hinzufügen von import "../entry/server.js"; in pages/_document.js und Hinzufügen des folgenden Codes zu 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;
  },
};

Der obige Code erstellt ein verschachteltes entry Array. Ist das nötig oder soll es eine Verbreitung geben:

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;
  },
};

Yep @jcheroske dein Vorschlag ist richtig.
Ich werde den Originalcode aktualisieren.

Und ich schließe dieses Thema.

War diese Seite hilfreich?
0 / 5 - 0 Bewertungen

Verwandte Themen

timneutkens picture timneutkens  ·  3Kommentare

swrdfish picture swrdfish  ·  3Kommentare

havefive picture havefive  ·  3Kommentare

flybayer picture flybayer  ·  3Kommentare

sospedra picture sospedra  ·  3Kommentare