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

Rewriting entry function in custom next.config.js or client/npm-dev.js & client/index.js #1254

Closed
lenny0702 opened this issue Feb 23, 2017 · 3 comments

Comments

@lenny0702
Copy link

I want to write some my own logic in client js (client/index.js & client/npm.dev.js). So I am trying to change the MainJS's path in entryies of webpack.js to compile my own version of client js.

Is it possible to do this?

Actually I tried to rewrite the entry function in custom next.config.js. But it never been called.

Thanks!

@lenny0702 lenny0702 changed the title Rewriting entry function in custom next.config.js Rewriting entry function or client js in custom next.config.js Feb 23, 2017
@lenny0702 lenny0702 changed the title Rewriting entry function or client js in custom next.config.js Rewriting entry function in custom next.config.js or client/npm-dev.js & client/index.js Feb 23, 2017
@arunoda
Copy link
Contributor

arunoda commented Feb 23, 2017

You can access the full webpack config object with next.config.js and using webpack() function. Here entry is an object and try to log it and change as you need it.

@arunoda arunoda closed this as completed Feb 23, 2017
@lenny0702
Copy link
Author

@arunoda Thanks for your response.
But when I try to log the entry object in my next.config.js, I got this:

next.config.js:
image

Output:
image

Apparently, it's a function when it's logging. Is there some thing I did wrong?

@arunoda
Copy link
Contributor

arunoda commented Feb 24, 2017

Actually, it's a async function now.
See: https://github.com/zeit/next.js/blob/master/server/build/webpack.js#L39

Now you need to do something like this:

module.exports = {
  webpack: function(c) {
    const original = c.entry
    c.entry = function () {
      return original()
        .then((entry) => {
          // do something with it
          console.log(entry)
          return entry
        })
    }
    return c
  }
}

@lock lock bot locked as resolved and limited conversation to collaborators May 12, 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

2 participants