You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Exploration of different config + expose webpack config (vercel#222)
* Use next.config.js instead of package.json
* Remove irrelevant comment
* Integrate with custom webpack config
* Include hotReload option
* Remove async/await for getConfig
* Read package.json, show warning when webpack in config is defined
* Prepend warning message with WARNING
* Update log statements
* Documentation
* Restart server on change of config
* Fix process handling and cases where there is no config
* Also restart server when config file gets deleted
* Changed second parameter of webpack to config
* Support for returning Promise
* Update documentation, fix bug with webpack config
* Remove package.json, cdn and hotReload from config
Copy file name to clipboardexpand all lines: README.md
+61-1
Original file line number
Diff line number
Diff line change
@@ -285,6 +285,66 @@ Then run `now` and enjoy!
285
285
286
286
Note: we recommend putting `.next` in `.npmignore` or `.gitignore`. Otherwise, use `files` or `now.files` to opt-into a whitelist of files you want to deploy (and obviously exclude `.next`)
287
287
288
+
## Configuration
289
+
290
+
While Next.js aims to work without any configuration, sometimes there is a need to add custom behaviour.
291
+
You can define custom configuration in a file called `next.config.js` in the project root directory.
292
+
An example of a configuration looks like this:
293
+
294
+
```javascript
295
+
// next.config.js
296
+
module.exports= {
297
+
cdn:true
298
+
}
299
+
```
300
+
301
+
### Customizing webpack config
302
+
303
+
Sometimes the user needs to have custom configuration for webpack to add a specific behaviour in the build process.
304
+
An example of this is using `eslint-loader` to lint the files before compiling. This can be done by defining
As you can see you need to provide a function which has two parameters `webpackConfig`, which is the config used by Next.js, and `options`, which contains
317
+
`dev` (`true` if dev environment). The config you return is the config used by Next.js.
318
+
You can also return a `Promise` which will be resolved first.
319
+
320
+
_NOTE: Use this option with care, because you can potentially break the existing webpack build configuration by using this option._
321
+
322
+
These are some more examples:
323
+
324
+
```javascript
325
+
constI18nPlugin=require('i18n-webpack-plugin');
326
+
327
+
module.exports= {
328
+
webpack: (webpackConfig, { dev }) => {
329
+
// Read image files:
330
+
webpackConfig.module.loaders.push({
331
+
test:/\.png$/,
332
+
loader:'file'
333
+
})
334
+
335
+
// Adding a plugin
336
+
webpackConfig.plugins.push(newI18nPlugin())
337
+
338
+
// Or adding an alias
339
+
// Create webpackConfig.resolve.alias if it doesn't exist yet:
@@ -423,7 +483,7 @@ For this reason we want to promote a situation where users can share the cache f
423
483
424
484
We are committed to providing a great uptime and levels of security for our CDN. Even so, we also **automatically fall back** if the CDN script fails to load [with a simple trick](http://www.hanselman.com/blog/CDNsFailButYourScriptsDontHaveToFallbackFromCDNToLocalJQuery.aspx).
425
485
426
-
To turn the CDN off, just set `{ “next”: { “cdn”: false } }` in `package.json`.
486
+
To turn the CDN off, just set `module.exports = { cdn: false }` in `next.config.js`.
0 commit comments