[英]NPM packages: Deliver assets/images package
I created an (angular2) npm package and uploaded it to my (private) registry. 我创建了一个(angular2)npm软件包并将其上传到我的(私有)注册表。
The component itself is pretty easy and should show an icon. 该组件本身非常简单,应该显示一个图标。 Please see the template here:
请在此处查看模板:
<span
[class]="'icon icon-' + key"
[inlineSVG]="'./assets/icons.svg#' + key"
aria-hidden="true"
></span>
As the path in [inlineSVG] shows, I would like to deliver the icons with the package. 如[inlineSVG]中的路径所示,我想随包装一起提供图标。 So I've put them into
./assets
folder. 因此,我将它们放入
./assets
文件夹中。
But everytime I publish the package and import it into my application, I get a 404 that the file cannot be found: 但是每次发布该软件包并将其导入到我的应用程序中时,都会得到一个404找不到该文件的信息:
I'm building my packages with gulp. 我正在用gulp构建我的包裹。 I can post my gulpfile as well if needed.
如果需要,我也可以发布gulpfile。
Now my question: Is it generally possible to deliver assets (images) in an npm package? 现在我的问题是:通常可以通过npm包交付资产(图像)吗?
Any help is greatly appreciated :) 任何帮助是极大的赞赏 :)
Well technically no you can't because you might be able to upload the assets but the actual path changes. 从技术上讲,不能,因为您可以上传资产,但实际路径会更改,所以您不能这样做。 Your assets are not even served in the server to be honest since they are in the node_modules folder.
说实话,您的资产甚至没有在服务器中提供,因为它们在node_modules文件夹中。
What you might be able to do is import the svgs inline in the css. 您可能能够做的就是在CSS中内联导入svgs。 https://github.com/davidkpiano/sass-svg
https://github.com/davidkpiano/sass-svg
Or otherwise include base64 uri of the image. 否则,请包含图片的base64 uri。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.