Skip to content

Commit

Permalink
Remove package.json, cdn and hotReload from config
Browse files Browse the repository at this point in the history
  • Loading branch information
Ives van Hoorne committed Dec 17, 2016
1 parent 4c8ab59 commit 2316e55
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 19 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -306,15 +306,15 @@ An example of this is using `eslint-loader` to lint the files before compiling.

```javascript
module.exports = {
webpack: (webpackConfig, { hotReload, dev }) => {
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 `hotReload` (`true` if hotReload is on) and `dev` (`true` if dev environment). The config you return is the config used by Next.js.
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._
Expand All @@ -325,7 +325,7 @@ These are some more examples:
const I18nPlugin = require('i18n-webpack-plugin');

module.exports = {
webpack: (webpackConfig, { hotReload, dev }) => {
webpack: (webpackConfig, { dev }) => {
// Read image files:
webpackConfig.module.loaders.push({
test: /\.png$/,
Expand Down
2 changes: 1 addition & 1 deletion server/build/webpack.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ export default async function createCompiler (dir, { dev = false } = {}) {
const config = getConfig(dir)
if (config.webpack) {
console.log('> Using Webpack config function defined in next.config.js.')
webpackConfig = await config.webpack(webpackConfig, { hotReload, dev })
webpackConfig = await config.webpack(webpackConfig, { dev })
}
return webpack(webpackConfig)
}
14 changes: 1 addition & 13 deletions server/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { existsSync } from 'fs'
const cache = new Map()

const defaultConfig = {
cdn: true,
webpack: null
}

Expand All @@ -17,25 +16,14 @@ export default function getConfig (dir) {

function loadConfig (dir) {
const path = join(dir, 'next.config.js')
const packagePath = join(dir, 'package.json')

let userConfig = {}
let packageConfig = null

const userHasConfig = existsSync(path)
if (userHasConfig) {
const userConfigModule = require(path)
userConfig = userConfigModule.default || userConfigModule
}

const userHasPackageConfig = existsSync(packagePath)
if (userHasPackageConfig) {
packageConfig = require(packagePath).next
}

if (packageConfig) {
console.warn("> [warn] You're using package.json as source of config for next.js. Use next.config.js instead.")
}

return Object.assign({}, defaultConfig, userConfig, packageConfig || {})
return Object.assign({}, defaultConfig, userConfig)
}
1 change: 0 additions & 1 deletion server/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ async function doRender (req, res, pathname, query, {
}

const docProps = await Document.getInitialProps({ ...ctx, renderPage })
const config = getConfig(dir)

const doc = createElement(Document, {
__NEXT_DATA__: {
Expand Down

0 comments on commit 2316e55

Please sign in to comment.