如何包含“leaflet.css"在带有 webpack 的 React 应用程序中?

2022-01-12 00:00:00 reactjs leaflet css webpack

我使用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';

相关文章