React plugin boilerplate is to help you build a powerful plugin with all react power in few seconds.
yarn
ornpm install
yarn start:dev
to build and watch for changes, also a dev server will start onhttp://localhost:3000/
yarn json-server
to create test json apihttp://localhost:3001/
yarn lint
to run eslint onsrc
folder and display code errors if anyyarn flow
to run flow
The goal is to bundle all your code and assets including [images, svgs, and styles] in a single file that can be hosted and then included in any web page, in the following way
<script type="text/javascript" src="http://hosting.server.com/js/scripts.js"></script>
<script>MyPlugin.init({ title: 'My Plugin Title' });</script>
all svgs will be embedded as inline svg in the plugin
- Add your svg in
/src/assets/icons/
- Include it in
/src/utils/svgs.js
- Finally include svg in your component as in
/src/components/Header
images will be converted to base64 and embedded in the bundled scripts.js
file, note that the max image size is set to 50kb ideally you should not be using big size images in a plugin.
- Add your image in
/src/assets/images/
- Reference your image in style and it will be converted to base64 as in
src/components/Header/
all styles will be embedded in bundled scripts.js
You can pass any settings while initializing the plugin, and all your settings will be copied to redux store and can be accessed from all components the same way we used title
settings in src/components/Header/
- ES6 Features
- React Redux to maintain application state
- Redux Thunk to handle asynchronous actions
- axios to handle all api calls
['GET','POST','PUT','DELETE', ...]
- React CSS Modules to be able to build modular CSS code for each React component.
- Svgo to make sure all your svg icons are optimized
- Node express based development server
- json-server no need to wait for backend api to start development, use
json-server
to have test data and test api ready for use - eslint the project contains eslint with
eslint-config-airbnb
extended, to fix and flag javascript code errors. - flow static type checker for javascript
- husky to add
pre-commit
hook that will triggeryarn lint && yarn flow
to make sure no bad commits are pushed
Webpack is the only tool used in this plugin to build the final scripts.js
file
- babel-loader with
['es2015', 'react', 'stage-1', 'flow']
presets for ES6 features and React JSX transpilation to ES5 understood by all browsers. - sass-loader Loads a Sass/SCSS file and compiles it to CSS
- css-loader interprets
@import
/url()
to js modules - postcss-loader to process CSS with PostCSS
- style-loader
- file-loader interprets
@import
/url()
to image files, to copy them todist
folder and return url for these images - svgo-loader to optimize svg before generating final sprite.svg
- uglifyjs-webpack-plugin for javascript minification
- copy-webpack-plugin used to copy
index.html
todist
folder - compression-webpack-plugin for gzip compression of scripts.js
You can use any prefered editor, in case you are using Atom the following packages can help speed up your development process: