- install parcel as the bundling tool
- create index.js and index.html
- create .babelrc config file for jsx to js converting
parcel index.htmlto run this little app
- get jsx and convert to virtual dom with createElement
- render virtual dom on the real dom
- update render function, render can handle react function components and class components
- add createComponent, setComponentProps, and createComponent to handle components
- implement react life cycle functions in createComponent, setComponentProps and createComponen
- now react will replace all DOM when updating, it's expensive
- Create diff function. Diff can find the changes in virtual dom and only updates the real dom with the difference for better performance.
- Compare between the real dom and the virtual dom. React will compare the new virtual dom and old virtual dom, find changes and update the real dom with the patches.
- compare and update at same time
- Update setState function.
- Push all stateChange and component to queue. Push the component to render queue only once. Remove dups.
- Create flush function to execute stateChange in queue and render component
- Run flush function after all sync function. Defer flush with promise or setTimeout(0)
- create my react 16 for learning hook, fiber, useState, reconciliation, performUnitOfWork and new features
- build myreact with webpack
- optimize webpack config
-
babel/core: The core babel library
-
babel/preset-env: Is a smart preset that allows you to use the latest JavaScript without needing to micromanage which syntax transforms (and optionally, browser polyfills) are needed by your target environment(s)This is also known as browser polyfills
-
babel/preset-react: Transform React JSX into regular JavaScript code
-
babel-loader: Webpack loader helper
-
CSS-loader: Handle CSS files
-
style-loader: The style-loader takes CSS and actually inserts it into the page so that the styles are active on the page.
-
postcss-loader: Will process CSS to work on older browsers
-
URL-loader: Will load the image files. Url loader depends on file-loader
-
autoprefixer: Autoprefixer is a PostCSS plugin which parses your CSS and adds vendor prefixes
-
html-webpack-plugin: The HtmlWebpackPlugin simplifies the creation of HTML files to serve your webpack bundles. This is especially useful for webpack bundles that include a hash in the filename which changes every compilation.
-
clean-webpack-plugin: clean bundle folder befoer build new folder
-
mini-css-extract-plugin: extract css code from bundle.js as seperate style file and inject into index.html
-
happypack and thread-loader: run bundle job in worker pool. Now we should use thread-loader since happypack is inactive.
-
lazy loading: the print.js file will be lazy-loading. Only load the splited print.js bundle when = button is clicked.
-
tree shaking: prune code if unused.
-
cache: add [contenthash] to the output file. it helps the web server and browser caching.
-
code splitting: Split code for multiple entry. Extract common dependencies into an existing entry chunk or an entirely new chunk