How to include “leaflet.css” in a React app with webpack?

前端 未结 6 1647
忘掉有多难
忘掉有多难 2021-01-19 02:09

I using the survivejs.com site as a template to build a map based React app with webpack. For the map i am using leaflet but i can\'t find a way to add the leaflet.css. With

6条回答
  •  囚心锁ツ
    2021-01-19 02:31

    In my applications that use webpack (via create-react-app) I add the following line to the top of my css file relevant for maps:

    /* map.css */
    
    @import '~leaflet/dist/leaflet.css';
    

    For example, this file could be map.css. I also put any custom map css styles in this file.

    Then in my javascript / jsx file that uses the Map Component, I import this css file:

    // map.js
    
    import './map.css'
    

提交回复
热议问题