-
Notifications
You must be signed in to change notification settings - Fork 27.6k
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
Pass webpack
into webpack()
fn in next.config.js
#456
Conversation
This passes a refernce to the `webpack` module into a custom `webpack()` function defined in `next.config.js`. A user wanting to add something like a custom `DefinePlugin` entry might have a `next.config.js` file that looks like this: ```js module.exports = { webpack: (cfg) => { cfg.plugins.push( new webpack.DefinePlugin({ 'process.env.CUSTOM_VALUE': JSON.stringify(process.env.CUSTOM_VALUE), }) ); return cfg; }, }; ``` The problem is they need access to the `webpack` module. They might think to `require('webpack')` in their `next.config.js`, but then they might feel obligated to add `webpack` to their `package.json`. Instead, it might be simpler to just pass a reference to the `webpack` to their config like this: ```js module.exports = { webpack: (cfg, {webpack}) => { // ... }, }; ```
@@ -397,8 +397,13 @@ The following example shows how you can use [`react-svg-loader`](https://github. | |||
|
|||
```js | |||
module.exports = { | |||
webpack: (cfg, { dev }) => { | |||
webpack: (cfg, { webpack, dev }) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this core idea here. It makes totally sense.
But I'm not quite sure about the name of it.
May be it could be webpackNpmModule
.
What if it's |
@nkzawa sure! Side question: does |
+1 for using import system. Should we just embrace "npm3 flat structure side effects" and go for |
@rauchg that's what I'm doing right now. My main concern was someone wanting to add Also, we can only use export default {}; …instead of: module.exports = {}; This is similar to how |
@ericf we don't transpile the config file by design for now because we're going to have custom babel setting on the file but can't use the setting to transpile the file itself. |
@nkzawa yeah that would be a gap. I see three main ways forward to resolve this:
|
@ericf I think the best solution is to expose it as |
Btw, I think we have a naming issue since we have |
I don't think this has been done has it? Exposing webpack to next/webpack. As many others said this will be very helpful for |
This passes a refernce to the
webpack
module into a customwebpack()
function defined innext.config.js
.A user wanting to add something like a custom
DefinePlugin
entry might have anext.config.js
file that looks like this:The problem is they need access to the
webpack
module. They might think torequire('webpack')
in theirnext.config.js
, but then they might feel obligated to addwebpack
to theirpackage.json
. Instead, it might be simpler to just pass a reference to thewebpack
to their config like this:Curious what folks think about this. Maybe someone is worried that the user would try to call the
webpack()
module ref and kick off the build?