-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Allow to customize our babel configuration #466
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| # Example app using custom babel config | ||
|
|
||
| This example features: | ||
|
|
||
| * An app using proposed [do expressions](https://babeljs.io/docs/plugins/transform-do-expressions/). | ||
| * It uses babel-preset-stage-0, which allows us to use above JavaScript feature. | ||
|
|
||
| ## How to run it | ||
|
|
||
| ```sh | ||
| npm install | ||
| npm run dev | ||
| ``` |
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| // This file is not going through babel transformation. | ||
| // So, we write it in vanilla JS | ||
| // (But you could use ES2015 features supported by your Node.js version) | ||
|
|
||
| module.exports = { | ||
| // config is the set of options we pass to our babel-loaders's query option | ||
| babel: function (config) { | ||
| // Add the stage-0 preset. | ||
| // Make sure to use 'require.resolve' otherwise we won't be able to find it. | ||
| config.presets.push(require.resolve('babel-preset-stage-0')) | ||
|
|
||
| // Important: return the modified config | ||
| return config | ||
| } | ||
| } |
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| { | ||
| "name": "with-custom-babel-config", | ||
| "version": "1.0.0", | ||
| "description": "This example features:", | ||
| "main": "index.js", | ||
| "scripts": { | ||
| "dev": "next", | ||
| "build": "next build", | ||
| "start": "next start" | ||
| }, | ||
| "dependencies": { | ||
| "next": "^2.0.0-beta" | ||
| }, | ||
| "author": "", | ||
| "license": "ISC", | ||
| "devDependencies": { | ||
| "babel-preset-stage-0": "^6.16.0" | ||
| } | ||
| } |
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| import React from 'react' | ||
|
|
||
| export default class MyLuckNo extends React.Component { | ||
| constructor (...args) { | ||
| super(...args) | ||
| this.state = { randomNo: null } | ||
| } | ||
|
|
||
| componentDidMount () { | ||
| this.recalculate() | ||
| } | ||
|
|
||
| recalculate () { | ||
| this.setState({ | ||
| randomNo: Math.ceil(Math.random() * 100) | ||
| }) | ||
| } | ||
|
|
||
| render () { | ||
| const { randomNo } = this.state | ||
|
|
||
| if (randomNo === null) { | ||
| return (<p>Please wait..</p>) | ||
| } | ||
|
|
||
| // This is an experimental JavaScript feature where we can get with | ||
| // using babel-preset-stage-0 | ||
| const message = do { | ||
| if (randomNo < 30) { | ||
| 'Do not give up. Try again.' | ||
| } else if (randomNo < 60) { | ||
| 'You are a lucky guy' | ||
| } else { | ||
| 'You are soooo lucky!' | ||
| } | ||
| } | ||
|
|
||
| return ( | ||
| <div> | ||
| <h3>Your Lucky number is: "{randomNo}"</h3> | ||
| <p>{message}</p> | ||
| <button onClick={() => this.recalculate()}>Try Again</button> | ||
| </div> | ||
| ) | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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.
This seems a bit too hacky to recommend. I wonder if the following works.
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 can't import since it's next.config.js. It didn't work for me for simply giving the preset.
I will try more options.
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.
That's a pretty good option. I like it.
I thought we wanted to expose everything via next.config.js.
@rauchg what do you think?