問題描述
我使用survivorjs.com 網站作為模板,使用webpack 構建基于地圖的React 應用程序.對于我使用傳單的地圖,但我找不到添加leaflet.css 的方法.如果沒有這個,地圖圖塊的顯示順序就會錯誤.
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.
我嘗試使用這個將leaflet.css 添加到App.jsx 文件中
I have tried adding the leaflet.css to the App.jsx file using this
require('leaflet/dist/leaflet.css');
但出現以下錯誤
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,我不清楚如何做到這一點?
If I had access to the index.html i could add it there but i with webpack, i'm unclear how to do this?
推薦答案
我通過像這樣簡單地導入 CSS 來解決它:
I solved it by simply importing the CSS like this:
import 'leaflet/dist/leaflet.css';
這篇關于如何包含“leaflet.css"在帶有 webpack 的 React 應用程序中?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!