![](/img/trans.png)
[英]How to import CSS from node_modules in webpack angular2 app
[英]angular. How to import css from node_modules
我正在使用角度5.我的模块我正在使用传单1.2.0。
在leaflet.css中我遇到图像问题,例如,一些css行:
.leaflet-retina .leaflet-control-layers-toggle {
background-image: url(/assets/images/leaflet/layers-2x.png);
background-size: 26px 26px;
}
/* Default icon URLs */
.leaflet-default-icon-path {
background-image: url(/assets/images/leaflet/marker-icon.png);
}
所以,我需要访问leaflet.css到它的相对路径,我尝试了:
@Component({
selector: 'myComponent',
template:`<div id="myId" class="myClass"></div>`,
styleUrls: ['./myComponent.component.scss','/../../../../node_modules/leaflet/dist/leaflet.css'],
})
文件夹结构:
--project_folder
--node_modules
--leaflet
--dist
--leaflet.css
--src
--app
--myComponentParent
--myComponent
--myComponent.component.ts
--myComponent.component.scss
--myComponent.component.html
我可以参考src中的文件夹吗? 我该怎么做?
如果您使用的是Angular CLI,则需要将Leaflet CSS文件添加到包含在其中的样式数组中。 angular-cli.json
并从其他地方删除css导入
"styles": [
"styles.css",
"../node_modules/leaflet/dist/leaflet.css",
]
无需像这样添加。 在angular-cli.json
文件中,使用脚本路径添加样式标记
"styles": [
"../node_modules/leaflet/dist/leaflet.css",
]
从组件中删除脚本
styleUrls: ['./myComponent.component.scss'],
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.