Example project demonstrating the use of React Flag Icon Css with Css Modules or standard (global) Css, and custom country flags images.
Powered by webpack 4.
Previous versions:
Clone the repository:
$ git clone https://github.com/matteocng/react-flag-icon-css-example-multi-example-multi.git
$ cd react-flag-icon-css-example-multi-example-multiInstall the required modules with Yarn:
$ yarnor with npm:
$ npm installRun the webpack development server and apply the configuration for Css Modules:
$ yarn startor with npm:
$ npm run startOpen a browser and go here: http://localhost:8080.
Please note that this example uses React Css Modules which is a HOC (Higher Order Component) that automatically maps Css Modules to React components. The usage of React Css Modules is completely optional; if you don't use it, instead of writing styleName='some-css-module', write className={styles['some-css-module']}.
Run the webpack development server and apply the configuration for standard Css:
$ yarn start:classesor with npm:
$ npm run start:classesOpen a browser and go here: http://localhost:8080.
You can start the server on another port with this command:
$ PORT=5100 yarn startor with npm:
$ PORT=6300 npm run startThis example app uses the USE_CSS_MODULES environment variable (set by package.json scripts) to allow for an easy "switch" between a configuration with or without Css Modules (see: webpack.config.js). This results in more complex code than need be.
In a real project you would never use the USE_CSS_MODULES switch and getStylePropName, and instead of writing [options.stylePropName] in the React components, you would write className or a combination of className and styleName (if you used React Css Modules or Babel Plugin React Css Modules).
Actually, the recommended approach adopted in the upcoming version of create-react-app, is to configure webpack so that its loaders load files ending in .module.css as Css Modules, and files ending in .css as global Css. If you decide to go this way by using the upcoming version of create-react-app or with a custom app, it is easier to use React Flag Icon Css with useCssModules: false. Otherwise, you may try forcing any file that contains the pattern flag-icon-css and ends with .css to be loaded as Css Modules in your webpack configuration (to be tested!).
This example app uses sass (.scss) styles, but sass is not required to use react-flag-icon-css. Your app can use any CSS preprocessor (such as postcss) or no CSS preprocessor at all. For instance, to use postcss in your stylesheets:
- rename 
.scssfiles to.css. - remove 
sass-loaderfrom webpack.config.js. npm installoryarn addthePostCSSplugins that you need.import()them into webpack.config.js- add them to the 
postcss-loadersection afterautoprefixer. 
Contributions are welcome. Please use a topic branch, follow the AngularJS commit style guidelines and check that yarn run pre-commit returns zero errors before opening a PR. Thanks!
This project is licensed under the terms of the MIT license.