Modular Code - sgml/signature GitHub Wiki
-
Comment out code that you don't need if it is causing errors
-
Use default imports and exports since webpack and babel fail with poor error messaging when a named import is used with sourcemaps:
-
Use a modular structure like HighCharts or i18next-icu to avoid the need for destructuring exports
-
Use jsfiddle, codepen, or plunker to test things such as open source react components. For example:
- Then map the imports to script tags as follows:
import | script |
---|---|
import React from 'react' | https://unpkg.com/[email protected]/umd/react.production.min.js |
import ReactDOM from 'react-dom' | https://unpkg.com/[email protected]/umd/react-dom.production.min.js |
import moment from 'moment' | https://unpkg.com/[email protected]/moment.js |
Use the following code for babel and react without node.js:
<script src="https://unpkg.com/[email protected]/babel.js"></script> <script type="text/babel"> var contentNode = document.getElementById('content'); var component = <h1> Hello World </h1>; // A simple JSX component ReactDOM.render(component, contentNode); // Render the conponent </script>
-
Use react as a standard preset: presets:["react"]
-
Instead of a preset like babel-preset-env, use individual Babel plugins listed in the verbose output such as:
-
https://babeljs.io/docs/en/babel-plugin-transform-arrow-functions
-
https://babeljs.io/docs/en/babel-plugin-transform-destructuring
-
https://babeljs.io/docs/en/babel-plugin-transform-shorthand-properties
-
https://babeljs.io/docs/en/babel-plugin-transform-function-name
-
Use explicit code instead of stage0, stage1, stage2, and stage3 presets for proposed tc39 features such as:
- decorators
- class properties
- export-default-from
- null coalescing (??)
-
Use the copy webpack plugin to move HTML and CSS files rather than the loaders in development mode, use the file-loader to inline images, the style-loader to inline styles, the postCSS plugin to handle CSS imports, and use the extract text plugin to combine the styles with the design language CSS in production mode
-
Use styled-components rather than inline styles