简体   繁体   English

NPM软件包:交付资产/图像软件包

[英]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.

相关问题 NPM Package:指 package 内的资产 - NPM Package : Referring to assets within the package 如何打包本地NPM软件包 - How to package local NPM packages npm软件包未从package.json更新 - npm packages not updating from package.json 我的 Angular 8 NPM package 找不到自己的资产 - My Angular 8 NPM package is not finding its own assets 使用ng serve或npm start时,Angular 4将无法识别资产/图像文件夹中的某些图像 - Angular 4 will not recognize certain images located in assets/images folder when using ng serve or npm start 尽管软件包报告了相同的版本,但本地 npm package 和 repo 之间怎么能不匹配? - How can you have a mismatch between a local npm package and repo though the packages report same version? npm 包需要 Angular 2 和 4 - npm packages requires Angular 2 and 4 Angular: Why would package-lock.json have higher versions of packages than package.json after fresh npm install? - Angular: Why would package-lock.json have higher versions of packages than package.json after fresh npm install? Angular 项目因安装任何 npm 包而崩溃。 如果我们在测试项目中安装相同的包,它会工作,但不会在实际项目中 - Angular project crashes due to installation any npm packages. if we install same package in test project it works but not in Actual projects 在角度6工作空间中安装NPM包 - Installing NPM packages in angular 6 workspace
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM