-
Notifications
You must be signed in to change notification settings - Fork 28.2k
Exploration of different config + expose webpack config #222
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
5885d94
Use next.config.js instead of package.json
ca2b6a0
Remove irrelevant comment
46feb1e
Integrate with custom webpack config
c612a6d
Include hotReload option
2f90055
Remove async/await for getConfig
20f847b
Read package.json, show warning when webpack in config is defined
eb850c0
Prepend warning message with WARNING
e142729
Update log statements
bb5d635
Documentation
99d0fb3
Restart server on change of config
5615086
Fix process handling and cases where there is no config
f3c3bb4
Also restart server when config file gets deleted
c23c5b2
Changed second parameter of webpack to config
0d77b3f
Support for returning Promise
4c8ab59
Update documentation, fix bug with webpack config
2316e55
Remove package.json, cdn and hotReload from config
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -285,6 +285,66 @@ Then run `now` and enjoy! | |
|
||
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`) | ||
|
||
## Configuration | ||
|
||
While Next.js aims to work without any configuration, sometimes there is a need to add custom behaviour. | ||
You can define custom configuration in a file called `next.config.js` in the project root directory. | ||
An example of a configuration looks like this: | ||
|
||
```javascript | ||
// next.config.js | ||
module.exports = { | ||
cdn: true | ||
} | ||
``` | ||
|
||
### Customizing webpack config | ||
|
||
Sometimes the user needs to have custom configuration for webpack to add a specific behaviour in the build process. | ||
An example of this is using `eslint-loader` to lint the files before compiling. This can be done by defining | ||
`webpack` in the config. | ||
|
||
```javascript | ||
module.exports = { | ||
webpack: (webpackConfig, { dev }) => { | ||
webpackConfig.module.preLoaders.push({ test: /\.js$/, loader: 'eslint-loader' }) | ||
return webpackConfig | ||
} | ||
} | ||
``` | ||
|
||
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 | ||
`dev` (`true` if dev environment). The config you return is the config used by Next.js. | ||
You can also return a `Promise` which will be resolved first. | ||
|
||
_NOTE: Use this option with care, because you can potentially break the existing webpack build configuration by using this option._ | ||
|
||
These are some more examples: | ||
|
||
```javascript | ||
const I18nPlugin = require('i18n-webpack-plugin'); | ||
|
||
module.exports = { | ||
webpack: (webpackConfig, { dev }) => { | ||
// Read image files: | ||
webpackConfig.module.loaders.push({ | ||
test: /\.png$/, | ||
loader: 'file' | ||
}) | ||
|
||
// Adding a plugin | ||
webpackConfig.plugins.push(new I18nPlugin()) | ||
|
||
// Or adding an alias | ||
// Create webpackConfig.resolve.alias if it doesn't exist yet: | ||
webpackConfig.resolve.alias = webpackConfig.resolve.alias || {} | ||
webpackConfig.resolve.alias.src = './src' | ||
|
||
return webpackConfig | ||
} | ||
} | ||
``` | ||
|
||
## FAQ | ||
|
||
<details> | ||
|
@@ -423,7 +483,7 @@ For this reason we want to promote a situation where users can share the cache f | |
|
||
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). | ||
|
||
To turn the CDN off, just set `{ “next”: { “cdn”: false } }` in `package.json`. | ||
To turn the CDN off, just set `module.exports = { cdn: false }` in `next.config.js`. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't worry about this one. We'll remove it anyway. |
||
</details> | ||
|
||
<details> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
We don't have a
cdn
option. May be we need to re-phrase this.