How to include quot;leaflet.cssquot; in a React app with webpack?(如何包含“leaflet.css在带有 webpack 的 React 应用程序中?)
问题描述
我使用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 应用程序中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何包含“leaflet.css"在带有 webpack 的 React 应用程序中?


- Quasar 2+Apollo:错误:找不到ID为默认的Apollo客户端。如果您在组件设置之外,请使用ProvideApolloClient() 2022-01-01
- Flexslider 箭头未正确显示 2022-01-01
- Fetch API 如何获取响应体? 2022-01-01
- Css:将嵌套元素定位在父元素边界之外一点 2022-09-07
- 如何使用 JSON 格式的 jQuery AJAX 从 .cfm 页面输出查 2022-01-01
- addEventListener 在 IE 11 中不起作用 2022-01-01
- 400或500级别的HTTP响应 2022-01-01
- 使用RSelum从网站(报纸档案)中抓取多个网页 2022-09-06
- 失败的 Canvas 360 jquery 插件 2022-01-01
- CSS媒体查询(最大高度)不起作用,但为什么? 2022-01-01