Skip to content

Exploration of different config + expose webpack config - #222

Merged
rauchg merged 16 commits into
vercel:masterfrom
CompuIves:new_config
Dec 17, 2016
Merged

rauchg merged 16 commits into
vercel:masterfrom
CompuIves:new_config

Conversation

@CompuIves

@CompuIves CompuIves commented Nov 7, 2016 •

Copy link
Copy Markdown
Contributor

We currently use package.json for our configuration. I think we should move away from using package.json and use something like next.config.js since it gives us more power than JSON.

An example is the issue for custom Webpack support: #40.
With a config like this you could do this for example:

// next.config.js

export default {
  webpack: (webpackConfig) => {
    const newConfig = { ...webpackConfig };
    newConfig.module.preloaders.push({ test: /\.js$/, loader: 'eslint-loader' });
    return newConfig;
  },
  cdn: false
}

Which is in my opinion better than creating a new file for webpack since this is more centralised. This does however still give users the option to use different files, for the webpack example:

// next.config.js

export default {
  webpack: require('./webpack').default,
  cdn: false
}

These are just my thoughts, I found out that I needed a sort of config file in .js when starting a PR for this project. Very curious what others think of this 😄.

@CompuIves CompuIves mentioned this pull request Nov 7, 2016
@frol

frol commented Nov 7, 2016

Copy link
Copy Markdown
Contributor

Disclaimer: I am not a JS developer, so I am not familiar with the traditions in JS world.

Config files in JS enable great flexibility, but at a cost of greater complexity and potential misuse and errors. In Python (which is my preferred language), it is common to use config files written in Python.

Overall, I like this idea.

Comment thread server/config.js Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI, the above comment is irrelevant for the updated implementation.

@rauchg

rauchg commented Nov 7, 2016

Copy link
Copy Markdown
Member

This is a pretty great idea I think

@Florian-R

Copy link
Copy Markdown

If this one get merged (and I hope it will), should this fall back to the old behaviour, so this is not a breaking change?

@CompuIves

Copy link
Copy Markdown
Contributor Author

@Florian-R You mean also read package.json for CND settings? We could do this, although it does add an extra bit of complexity since then we're reading two files for configuration.

@frol

frol commented Nov 8, 2016

Copy link
Copy Markdown
Contributor

@Florian-R There existed only one config option: cdn=true. I don't think it is so much of a trouble to move one line from package.json to next.config.js.

@Florian-R

Copy link
Copy Markdown

@frol You're right I missed that, don't know why I was sure there was others options. This indeed shouldn't break any code, dismiss my previous comments.

@CompuIves CompuIves changed the title Exploration of different config Exploration of different config + expose webpack config Nov 10, 2016
@CompuIves

Copy link
Copy Markdown
Contributor Author

This PR now also includes #174

Comment thread server/build/webpack.js Outdated

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this async? i don't see any way for it to be async.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh right! That need was removed since we now use require. Good catch, I'll update the PR.

@dbo dbo mentioned this pull request Nov 16, 2016
@rauchg

rauchg commented Nov 16, 2016

Copy link
Copy Markdown
Member

Important: since this effectively deprecates package.next (which I'm 100% ok with), we should probably WARN if we find it

@arunoda arunoda self-assigned this Nov 16, 2016
This was referenced Nov 16, 2016

@arunoda arunoda left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@CompuIves could you check these suggestion.
After that, we could get ship this PR :)

Comment thread server/config.js Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's better to do a sync FS check rather doing this.
That's cleaner.

Comment thread server/config.js Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a pretty good idea if we could log something, when we are using this user supplied webpack config decorator.
So, I suggest to not to define this.
And when we are using this, we can check for webpack decorator and log it.

Comment thread server/build/webpack.js Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do this only if user provides a webpack decorator.
If there's a one, we should log it so the user know this is happening.

Comment thread server/config.js Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We we should also read the package.json and check for the next config. If it's there, we should get it. (Only the cdn field).
And if we found it, we need log a message as it's deprecated.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nkzawa @rauchg do we have any specific format to log these messages.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, I think

@jonaswindey

Copy link
Copy Markdown
Contributor

Could we have a variable className on https://github.com/zeit/next.js/blob/master/lib/document.js#L11 in this config too?

That would cover #251

@CompuIves

Copy link
Copy Markdown
Contributor Author

@arunoda Processed your feedback!
Maybe we could make a helper function in the future to show warnings/notices/errors with the use of chalk to make them stand out more.

@jonaswindey I think we should create a separate PR for that issue so we can put this PR live sooner.

@rauchg

rauchg commented Nov 17, 2016

Copy link
Copy Markdown
Member

@jonaswindey @CompuIves the right way to address that is #251

@rauchg

rauchg commented Nov 18, 2016

Copy link
Copy Markdown
Member

It just occurred to me that it might be smart to restart the next process (with the same flags) when this file changes? 🤔

@rauchg

rauchg commented Nov 18, 2016

Copy link
Copy Markdown
Member

Unless, of course, it's tractable to reload everything without a full restart

@arunoda arunoda left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is beautiful. We just need some few messages changes. I've added comments for them.

You may also need to rebase again since there are some conflicts.

Also we need to add a section to doc about configuring webpack config. Here's a suggestion for the layout:

  • Add sub section about Customizing webpack config.
  • Tell about the main goal of this.
  • Show a simple example (like importing images directly)
  • Then, ask to use this with care. (Since user could broke our default config)
  • So show safe operations like adding plugins, aliases, loaders etc.

Also try to keep the doc for this minimal and we can have a full detailed section on the Wiki.

Comment thread server/build/webpack.js Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a "> " before the message. Like this:

console.log('> Using Webpack config function defined in next.config.js.')

Comment thread server/config.js Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change this to:

console.log("> [warn] You are using package.json for next.js config. Use next.config.js instead.");

Just FYI: Try not to use "Please" in front of messages. It's sounds like commanding.
I tend to use that and one of my UK friend asked to drop that. Messages sounds nice after that :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, thanks for the tip!

@CompuIves

CompuIves commented Nov 19, 2016 •

Copy link
Copy Markdown
Contributor Author

@arunoda Added docs, let me know what you think! I'll rebase tomorrow, out of time now 😅

@rauchg Hmm, this is a valid point. I'll check if there is a way to restart the server when the config file changes.

@arunoda

arunoda commented Nov 19, 2016

Copy link
Copy Markdown
Contributor

@rauchg That's a good point, but it seems like it's hard to do that via webpack itself.

We have to do a hard process restart, may be we could do it using the grunt config easily.

@arunoda

arunoda commented Nov 19, 2016 •

Copy link
Copy Markdown
Contributor

@CompuIves yep. Changes are great. Shall we try @rauchg's suggestion too.

@CompuIves

CompuIves commented Nov 20, 2016 •

Copy link
Copy Markdown
Contributor Author

@arunoda Added config watching, it kills the old child process and start a new one when it sees a change in next.config.js (only for dev mode).

Also rebased with master!

@nkzawa

nkzawa commented Nov 20, 2016 •

Copy link
Copy Markdown
Contributor

I wonder if we should:

  • transpile the next.config.js (support import export, async/await etc)
  • support asynchronous operations in each config
export default {
  async webpack (webpackConfig, hotReload) {
    const newConfig = { ...webpackConfig }
    newConfig.something = await getSomething()
    return newConfig
  }
}

@coveralls

coveralls commented Dec 17, 2016 •

Copy link
Copy Markdown

Coverage Status

Coverage increased (+2.9%) to 60.036% when pulling 2316e55 on CompuIves:new_config into b62a0e8 on zeit:master.

@CompuIves

CompuIves commented Dec 17, 2016 •

Copy link
Copy Markdown
Contributor Author

Rebased master and did the required changes.

I stumbled upon the item of CDN in the FAQ of the README. Do we still need this?

Comment thread README.md
```javascript
// next.config.js
module.exports = {
cdn: true

Copy link
Copy Markdown
Contributor

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.

Comment thread README.md
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`.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't worry about this one. We'll remove it anyway.

@arunoda

arunoda commented Dec 17, 2016

Copy link
Copy Markdown
Contributor

@CompuIves I added some comments.

@arunoda arunoda mentioned this pull request Dec 17, 2016
@rauchg
rauchg merged commit 5ab7463 into vercel:master Dec 17, 2016
@rauchg

rauchg commented Dec 17, 2016

Copy link
Copy Markdown
Member

I'll remove the cdn notes myself

@rauchg

rauchg commented Dec 17, 2016

Copy link
Copy Markdown
Member

Thanks @CompuIves

@arunoda

arunoda commented Dec 17, 2016

Copy link
Copy Markdown
Contributor

Awesome!

@CompuIves

Copy link
Copy Markdown
Contributor Author

Nice! Was great to help! 🎉

@lukeed lukeed mentioned this pull request Dec 27, 2016
@lock lock Bot locked as resolved and limited conversation to collaborators Jan 19, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.