Tuesday, December 31, 2019

Styles and Assets






This project setup uses Webpack for handling all assets. Webpack offers a custom way of “extending” the concept of import beyond JavaScript. To express that a JavaScript file depends on a CSS file, you need to import the CSS from the JavaScript file:

In the Button.css


.Button {
   padding : 20px;
}

In Button.js

Import React, {Component} from 'react'
Import './Button.css' //This tells web pack that the component uses this csss

Class Button extends Component {
render(){
   Return
 

}

}


This is not required for React but many people find this feature convenient. You can read about the benefits of this approach here. However you should be aware that this makes your code less portable to other build tools and environments than Webpack

In development, expressing dependencies this way allows your styles to be reloaded on the fly as you edit them. In production, all CSS files will be concatenated into a single minified .css file in the build output.

If you are concerned about using Webpack-specific semantics, you can put all your CSS right into src/index.css. It would still be imported from src/index.js, but you could always remove that import if you later migrate to a different build tool.



References:
https://facebook.github.io/create-react-app/docs/using-https-in-development

No comments:

Post a Comment