|
| 1 | +# Babel Configurations |
| 2 | +Standard configurations for [Babel](https://babeljs.io/). |
| 3 | + |
| 4 | +**Why?** — We use Babel to support latest JavaScript specifications in our projects, and to allow for some fancy features in our code. The standard Babel configurations help to ensure that selected code patterns are supported in all of our apps. |
| 5 | + |
| 6 | +Several Babel configurations are provided by this package: |
| 7 | + |
| 8 | +[**config/babel/webpack.json**](#webpack) — Babel config to use for JS and JSX files compilation during the Webpack build process; |
| 9 | + |
| 10 | +[**config/babel/node-ssr.json**](#node-ssr) — Server-side configuration with support of server-side rendering; |
| 11 | + |
| 12 | +To use any of these configurations in your code use `extend` Babel option in your `.babelrc` file, or whenever you need it, e.g. |
| 13 | +```json |
| 14 | +{ |
| 15 | + "extend": "topcoder-react-utils/config/babel/node-ssr.json" |
| 16 | +} |
| 17 | +``` |
| 18 | +This way you can also easily tune some of Babel options in the way specific to your project; however if you feel that an option change you need is necessary for any generic react-based project, consider to submit an update to the configuration provided by `topcoder-react-utils`. |
| 19 | + |
| 20 | +### Configuration Details |
| 21 | + |
| 22 | +- <a name="webpack">**`config/babel/webpack.json`**</a> — Babel config to use for JS and JSX files compilation during the Webpack build process; |
| 23 | + |
| 24 | + - Presets: [env](https://www.npmjs.com/package/babel-preset-env), [react](https://www.npmjs.com/package/babel-preset-react), [stage-2](https://www.npmjs.com/package/babel-preset-stage-2); |
| 25 | + |
| 26 | + - Uses [`babel-plugin-react-css-modules`](https://www.npmjs.com/package/babel-plugin-react-css-modules) to transform `styleName` props of ReactJS components into `className` props. A style name is transformed into: (i) `.path-to-the-stylesheet-and-stylesheet-file-name___original-style-name` class in the *development* Babel environment; (ii) `.6-symbols-hash-of-the-style` in the *production* environment. The class names generated in the first cases are verbose, thus good for debugging; and in the second case they are compact which results in smaller size of JS and CSS bundles. |
| 27 | + |
| 28 | + - Uses [`babel-plugin-inline-react-svg`](https://www.npmjs.com/package/babel-plugin-inline-react-svg) to embed imported SVG files into complied JS code; |
| 29 | + |
| 30 | + - Uses [`babel-plugin-transform-runtime`](https://ww.npmjs.com/package/babel-plugin-transform-runtime) to generate more optimal JS bundles; |
| 31 | + |
| 32 | + - Uses [`babel-plugin-module-resolver`](https://www.npmjs.com/package/babel-plugin-module-resolver) to setup the following paths as the roots for resolution of relative imports: `./src/shared`, `./src`; |
| 33 | + |
| 34 | + - Uses [`react-hot-loader/babel`](https://www.npmjs.com/package/react-hot-loader) to support hot module reloading in *development* environment. |
| 35 | + |
| 36 | +- <a name="node-ssr">**`config/babel/node-ssr.json`**</a> — Server-side configuration with support of server-side rendering. It extends [`config/babel/webpack.json`](#webpack) configuration with the following: |
| 37 | + |
| 38 | + - In the *test* Babel environment [`babel-plugin-react-css-modules`](https://www.npmjs.com/package/babel-plugin-react-css-modules) transforms a style name into `.path-to-the-stylesheet-___stylesheet-file-name__origina-style-name___5-symbols-hash-of-the-style` class. Resuling class names are verbose and good for debugging, the difference from *development* environment is for historic reasons. |
| 39 | + |
| 40 | + - Uses [`babel-plugin-css-modules-transform`](https://www.npmjs.com/package/babel-plugin-css-modules-transform) to convert CSS and SCSS imports into objects with keys and values being the original and generated class names. The class names are generated by the same rules being used to transform style names into classes; |
| 41 | + |
| 42 | + - Uses [`babel-plugin-tranform-assets`](https://www.npmjs.com/package/babel-plugin-transform-assets) to convert GIF, JPEG, JPG, and PNG imports into URL strings like `/images/hash-of-the-asset-file.original-file-extension`, where `/images/` is a fixed path prefix; |
| 43 | + |
| 44 | + - Uses [`babel-plugin-dynamic-import-node`](https://www.npmjs.com/package/babel-plugin-dynamic-import-node) to support dynamic `import(..)` statement; |
| 45 | + |
| 46 | + - Avoids using [`react-hot-loader/babel`](https://www.npmjs.com/package/react-hot-loader) in the *development* Babel environment. |
0 commit comments