Skip to content

Commit

Permalink
Babel 7 (#2324)
Browse files Browse the repository at this point in the history
Babel 7 was recently released so I gave a shot at upgrading it. Followed the advice from the official upgrade guide [here](https://babeljs.io/docs/en/v7-migration). Also, stage presets were removed so I used [babel-upgrade](https://github.com/babel/babel-upgrade) to make sure we had the relevant plugins for stage 0 (as we had until now).
  • Loading branch information
julienben committed Aug 29, 2018
1 parent 4623771 commit b243612
Show file tree
Hide file tree
Showing 12 changed files with 1,940 additions and 1,737 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const fs = require('fs');
const path = require("path");
const path = require('path');

const prettierOptions = JSON.parse(fs.readFileSync(path.resolve(__dirname, '.prettierrc'), 'utf8'));

Expand Down
6 changes: 3 additions & 3 deletions app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

// Needed for redux-saga es6 generator support
import 'babel-polyfill';
import '@babel/polyfill';

// Import all the third party stuff
import React from 'react';
Expand All @@ -25,7 +25,7 @@ import LanguageProvider from 'containers/LanguageProvider';

// Load the favicon and the .htaccess file
import '!file-loader?name=[name].[ext]!./images/favicon.ico';
import 'file-loader?name=[name].[ext]!./.htaccess'; // eslint-disable-line import/extensions
import 'file-loader?name=.htaccess!./.htaccess'; // eslint-disable-line import/extensions

import configureStore from './configureStore';

Expand Down Expand Up @@ -83,7 +83,7 @@ if (!window.Intl) {
import('intl/locale-data/jsonp/en.js'),
import('intl/locale-data/jsonp/de.js'),
]),
)
) // eslint-disable-line prettier/prettier
.then(() => render(translationMessages))
.catch(err => {
throw err;
Expand Down
1 change: 0 additions & 1 deletion app/containers/FeaturePage/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import ListItem from './ListItem';
import ListItemTitle from './ListItemTitle';

export default class FeaturePage extends React.Component {
// eslint-disable-line react/prefer-stateless-function
// Since state and props are static,
// there's no need to re-render this component
shouldComponentUpdate() {
Expand Down
1 change: 0 additions & 1 deletion app/containers/LanguageProvider/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import { IntlProvider } from 'react-intl';
import { makeSelectLocale } from './selectors';

export class LanguageProvider extends React.PureComponent {
// eslint-disable-line react/prefer-stateless-function
render() {
return (
<IntlProvider
Expand Down
2 changes: 1 addition & 1 deletion docs/general/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ Webpack requires an entry point to your application. Think of it as a door to yo

`app/app.js` is one of the biggest files of the boilerplate. It contains all the global setup to make sure your app runs smoothly. Let's break its contents down:

- `babel-polyfill` is imported. This enables cool stuff like generator functions, `Promise`s, etc.
- `@babel/polyfill` is imported. This enables cool stuff like generator functions, `Promise`s, etc.
- A `history` object is created, which remembers all the browsing history for your app. This is used by the ConnectedRouter to know which pages your users visit. (Very useful for analytics, by the way.)
- A redux `store` is instantiated.
- `ReactDOM.render()` not only renders the [root react component](https://github.com/react-boilerplate/react-boilerplate/blob/master/app/containers/App/index.js) called `<App />`, of your application, but it renders it with `<Provider />`, `<LanguageProvider />` and `<ConnectedRouter />`.
Expand Down
2 changes: 1 addition & 1 deletion internals/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const ReactBoilerplate = {
* Specify any additional dependencies here. We include core-js and lodash
* since a lot of our dependencies depend on them and they get picked up by webpack.
*/
include: ['core-js', 'eventsource-polyfill', 'babel-polyfill', 'lodash'],
include: ['core-js', 'eventsource-polyfill', '@babel/polyfill', 'lodash'],

// The path where the DLL manifest and bundle will get built
path: resolve('../node_modules/react-boilerplate-dlls'),
Expand Down
4 changes: 2 additions & 2 deletions internals/scripts/npmcheckversion.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const { exec } = require('child_process');
exec('npm -v', (err, stdout) => {
if (err) throw err;
if (parseFloat(stdout) < 5) {
throw new Error('[ERROR: React Boilerplate] You need npm version @>=5');
// process.exit(1);
// NOTE: This can happen if you have a dependency which lists an old version of npm in its own dependencies.
throw new Error(`[ERROR] You need npm version @>=5 but you have ${stdout}`);
}
});
2 changes: 1 addition & 1 deletion internals/templates/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

// Needed for redux-saga es6 generator support
import 'babel-polyfill';
import '@babel/polyfill';

// Import all the third party stuff
import React from 'react';
Expand Down
35 changes: 20 additions & 15 deletions internals/templates/index.html
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
<!doctype html>
<html lang="en">
<head>
<!-- The first thing in any HTML file should be the charset -->
<meta charset="utf-8">
<!-- Make the page mobile compatible -->
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="mobile-web-app-capable" content="yes">
<title>React.js Boilerplate</title>
</head>
<body>
<!-- Display a message if JS has been disabled on the browser. -->
<noscript>If you're seeing this message, that means <strong>JavaScript has been disabled on your browser</strong>, please <strong>enable JS</strong> to make this app work.</noscript>

<!-- The app hooks into this div -->
<div id="app"></div>
<!-- A lot of magic happens in this file. HtmlWebpackPlugin automatically includes all assets (e.g. bundle.js, main.css) with the correct HTML tags, which is why they are missing in this HTML file. Don't add any assets here! (Check out webpackconfig.js if you want to know more) -->
</body>
<head>
<!-- The first thing in any HTML file should be the charset -->
<meta charset="utf-8">
<!-- Make the page mobile compatible -->
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="mobile-web-app-capable" content="yes">
<title>React.js Boilerplate</title>
</head>

<body>
<!-- Display a message if JS has been disabled on the browser. -->
<noscript>If you're seeing this message, that means
<strong>JavaScript has been disabled on your browser</strong>, please
<strong>enable JS</strong> to make this app work.</noscript>

<!-- The app hooks into this div -->
<div id="app"></div>
<!-- A lot of magic happens in this file. HtmlWebpackPlugin automatically includes all assets (e.g. bundle.js, main.css) with the correct HTML tags, which is why they are missing in this HTML file. Don't add any assets here! (Check out webpackconfig.js if you want to know more) -->
</body>

</html>
2 changes: 1 addition & 1 deletion internals/testing/test-bundler.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// needed for regenerator-runtime
// (ES7 generator support is required by redux-saga)
import 'babel-polyfill';
import '@babel/polyfill';
87 changes: 65 additions & 22 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,42 @@
"pre-commit": "lint:staged",
"babel": {
"plugins": [
"styled-components"
"styled-components",
"@babel/plugin-syntax-dynamic-import",
"@babel/plugin-syntax-import-meta",
"@babel/plugin-proposal-class-properties",
"@babel/plugin-proposal-json-strings",
[
"@babel/plugin-proposal-decorators",
{
"legacy": true
}
],
"@babel/plugin-proposal-function-sent",
"@babel/plugin-proposal-export-namespace-from",
"@babel/plugin-proposal-numeric-separator",
"@babel/plugin-proposal-throw-expressions",
"@babel/plugin-proposal-export-default-from",
"@babel/plugin-proposal-logical-assignment-operators",
"@babel/plugin-proposal-optional-chaining",
[
"@babel/plugin-proposal-pipeline-operator",
{
"proposal": "minimal"
}
],
"@babel/plugin-proposal-nullish-coalescing-operator",
"@babel/plugin-proposal-do-expressions",
"@babel/plugin-proposal-function-bind"
],
"presets": [
[
"env",
"@babel/preset-env",
{
"modules": false
}
],
"react",
"stage-0"
"@babel/preset-react"
],
"env": {
"production": {
Expand All @@ -79,13 +104,13 @@
],
"plugins": [
"transform-react-remove-prop-types",
"transform-react-inline-elements",
"transform-react-constant-elements"
"@babel/plugin-transform-react-inline-elements",
"@babel/plugin-transform-react-constant-elements"
]
},
"test": {
"plugins": [
"transform-es2015-modules-commonjs",
"@babel/plugin-transform-modules-commonjs",
"dynamic-import-node"
]
}
Expand Down Expand Up @@ -143,8 +168,11 @@
"enzyme-to-json/serializer"
]
},
"resolutions": {
"babel-core": "7.0.0-bridge.0"
},
"dependencies": {
"babel-polyfill": "6.26.0",
"@babel/polyfill": "7.0.0",
"chalk": "2.4.1",
"compression": "1.7.2",
"cross-env": "5.2.0",
Expand All @@ -163,7 +191,7 @@
"react-dom": "16.4.1",
"react-helmet": "5.2.0",
"react-intl": "2.4.0",
"react-loadable": "5.4.0",
"react-loadable": "5.3.1",
"react-redux": "5.0.7",
"react-router-dom": "4.3.1",
"react-router-redux": "5.0.0-alpha.9",
Expand All @@ -177,23 +205,38 @@
"whatwg-fetch": "2.0.4"
},
"devDependencies": {
"@babel/cli": "7.0.0",
"@babel/core": "7.0.0",
"@babel/plugin-proposal-class-properties": "7.0.0",
"@babel/plugin-proposal-decorators": "7.0.0",
"@babel/plugin-proposal-do-expressions": "7.0.0",
"@babel/plugin-proposal-export-default-from": "7.0.0",
"@babel/plugin-proposal-export-namespace-from": "7.0.0",
"@babel/plugin-proposal-function-bind": "7.0.0",
"@babel/plugin-proposal-function-sent": "7.0.0",
"@babel/plugin-proposal-json-strings": "7.0.0",
"@babel/plugin-proposal-logical-assignment-operators": "7.0.0",
"@babel/plugin-proposal-nullish-coalescing-operator": "7.0.0",
"@babel/plugin-proposal-numeric-separator": "7.0.0",
"@babel/plugin-proposal-optional-chaining": "7.0.0",
"@babel/plugin-proposal-pipeline-operator": "7.0.0",
"@babel/plugin-proposal-throw-expressions": "7.0.0",
"@babel/plugin-syntax-dynamic-import": "7.0.0",
"@babel/plugin-syntax-import-meta": "7.0.0",
"@babel/plugin-transform-modules-commonjs": "7.0.0",
"@babel/plugin-transform-react-constant-elements": "7.0.0",
"@babel/plugin-transform-react-inline-elements": "7.0.0",
"@babel/preset-env": "7.0.0",
"@babel/preset-react": "7.0.0",
"@babel/register": "7.0.0",
"add-asset-html-webpack-plugin": "2.1.3",
"babel-cli": "6.26.0",
"babel-core": "6.26.3",
"babel-eslint": "8.2.3",
"babel-loader": "7.1.4",
"babel-plugin-dynamic-import-node": "1.2.0",
"babel-eslint": "9.0.0",
"babel-loader": "8.0.0",
"babel-plugin-dynamic-import-node": "2.1.0",
"babel-plugin-react-intl": "2.4.0",
"babel-plugin-react-transform": "3.0.0",
"babel-plugin-styled-components": "1.5.1",
"babel-plugin-transform-es2015-modules-commonjs": "6.26.2",
"babel-plugin-transform-react-constant-elements": "6.23.0",
"babel-plugin-transform-react-inline-elements": "6.22.0",
"babel-plugin-transform-react-jsx-source": "6.22.0",
"babel-plugin-transform-react-remove-prop-types": "0.4.13",
"babel-preset-env": "1.7.0",
"babel-preset-react": "6.24.1",
"babel-preset-stage-0": "6.24.1",
"babel-plugin-transform-react-remove-prop-types": "0.4.15",
"circular-dependency-plugin": "5.0.2",
"coveralls": "3.0.1",
"css-loader": "0.28.11",
Expand Down

0 comments on commit b243612

Please sign in to comment.