問題描述
我使用survivorjs.com 網(wǎng)站作為模板,使用webpack 構(gòu)建基于地圖的React 應(yīng)用程序.對(duì)于我使用傳單的地圖,但我找不到添加leaflet.css 的方法.如果沒有這個(gè),地圖圖塊的顯示順序就會(huì)錯(cuò)誤.
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. Without this the map tiles are displayed in the wrong order.
我嘗試使用這個(gè)將leaflet.css 添加到App.jsx 文件中
I have tried adding the leaflet.css to the App.jsx file using this
require('leaflet/dist/leaflet.css');
但出現(xiàn)以下錯(cuò)誤
ERROR in ./~/leaflet/dist/leaflet.css
Module parse failed: myApp/node_modules/leaflet/dist/leaflet.css Unexpected token (3:0)
You may need an appropriate loader to handle this file type.
如果我可以訪問 index.html,我可以將它添加到那里,但我使用 webpack,我不清楚如何做到這一點(diǎn)?
If I had access to the index.html i could add it there but i with webpack, i'm unclear how to do this?
推薦答案
我通過像這樣簡(jiǎn)單地導(dǎo)入 CSS 來解決它:
I solved it by simply importing the CSS like this:
import 'leaflet/dist/leaflet.css';
這篇關(guān)于如何包含“l(fā)eaflet.css"在帶有 webpack 的 React 應(yīng)用程序中?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!