Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add entry file for adding something across pages (like polyfills). #972

Closed
lixiaoyan opened this issue Feb 3, 2017 · 3 comments
Closed

Comments

@lixiaoyan
Copy link

lixiaoyan commented Feb 3, 2017

// in next.config.js

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

// or

module.exports = {
  entry: {
    client: "./entry/client",
    server: "./entry/server",
  },
};
@lixiaoyan
Copy link
Author

lixiaoyan commented Feb 4, 2017

Here is a workaround for now:

Adding import "../entry/server.js"; in pages/_document.js and adding the code below to 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;
  },
};

@jcheroske
Copy link
Contributor

The above code makes a nested entry array. Is that what's needed, or should there be a spread:

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

@arunoda
Copy link
Contributor

arunoda commented May 7, 2017

Yep @jcheroske your suggestion is correct.
I'll update the original code.

And I'm closing this issue.

@arunoda arunoda closed this as completed May 7, 2017
@lock lock bot locked as resolved and limited conversation to collaborators May 11, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants