React server side rendering
React JS , provides ReactDOMServer
object which
enables to render components to static markup. Typically,
it’s used on a Node server.
Using this method we can generate HTML on the server and serve it to the browser. This allows for faster page loads and also allows search engines to crawl the page for SEO purposes.
References:
Migrating from RequireJS to Webpack
Minimal amount of changes in actual code
Webpack compiler can understand modules written as ES2015 modules, CommonJS or AMD.
Existing code using define()
function doesn’t need modification.
Migrating Require.js config to Webpack config
The first thing to do when converting from Require.js to Webpack is to take your whole Require.js configuration file (requirejs_config.js) and convert it into Webpack configuration file (webpack.config.js).
Module Path Resolution
Help Webpack to find your module files.
NPM in place of Bower components
You can use NPM in place of Bower components , since we can configure easily in Webpack to load NPM dependencies
Aliases
Migrate Require.js paths
to webpack alias
Shim
Require.js shim takes modules that are not AMD compatible and makes them compatible.
References:
Webpack
Webpack is module bundler for modern JavaScript applications.
A module bundler is a tool that takes pieces of JavaScript and their dependencies and bundles them into a single file, usually for use in the browser.
Entry
An entry point indicates which module webpack should use to begin building out its internal dependency graph.
Output
The output property tells webpack where to emit bundles it creates and how to name these files.
Loaders
Out of the box, webpack only understands JavaScript and JSON files. Loaders allow webpack to process other file types and convert them into valid modules that can be consumed by your application and added to the dependency graph.
Plugins
Plugins can be leveraged to perform a wide range of tasks like bundle optimization, asset management and injection of environment variables.
References:
Common digital image formats
JPEG (Joint Photographic Experts Group)
JPEG image format are used by digital cameras to store photos. Because it uses lossy compression so cameras can store more photos on one camera card. Its useful for photographs but not for content like diagrams or charts which require sharpness.
- Mime type: image/jpeg
- File extensions: .jpg .jpeg .jpe .jif .jfif
GIF (Graphics Interchange Format)
GIF image format uses lossless compression. Its good for animation as well. This format is not used for photography because of limited number of colors.
- Mime type: image/gif
- File extensions: .gif
PNG (Portable Network Graphics)
PNG image format uses lossless or lossy compression. Supports higher color depth than GIF. For photographs not as good as JPEG because of larger file size. Good for images with text or line art as well.
- Mime type: image/png
- File extensions: .png
SVG (Scalable Vector Graphics)
SVG is a XML based vector graphics format. They are ideal for images that can be drawn accurately at any size.
- Mime type: image/svg+xml
- File extension: .svg
TIFF (Tagged Image File Format)
TIFF image format was created to store scanned photos. They are larger than images in other formats because of the metadata included. Also they are uncompressed.
- Mime type: image/tiff
- File extensions: .tif, .tiff
BMP (Bitmap)
BMP is most prevalent on Windows computers. They are uncompressed, so file sizes are larger than other formats.
- Mime type: image/bmp
- File extensions: .bmp
Choosing image format
- Photographs - JPEG
- Icons - SVG or PNG
- Screenshots - PNG or JPEG
- Diagrams, Charts - SVG or PNG
References:
CSS in JS
“CSS in JS” refers to ideas on modularizing CSS , so it helps in maintaing large and medium scale applications easier.
React JS style
In React JS style
attribute accepts a JavaScript object with camelCased properties.
Webpack css-loader and style-loader
The css-loader takes a CSS file and reads all dependencies and style-loader embeds the styles into markup.
CSS Modules
References:
- Why I Write CSS in JavaScript
- What actually is CSS-in-JS?
- Styling and CSS
- The Differing Perspectives on CSS-in-JS
- CSS in JS
- 9 CSS in JS Libraries you should Know in 2019
- An Introduction to CSS-in-JS: Examples, Pros, and Cons
- CSS Modules
- css-loader
- style-loader
- What are CSS Modules and why do we need them?
- How to configure CSS and CSS modules in webpack
- CSS Modules
- Styling and CSS
- Adding a Stylesheet
- Block, Element, Modifying Your JavaScript Components
- Getting Started with CSS Modules
- Four ways to style react components
- Modular CSS with React