首页 \ 问答 \ 将svg加载为路径(Load svg as path)

将svg加载为路径(Load svg as path)

我通过CLI使用webpack,比如webpack --watch 。 目标是用SASS编译JS并放入一些单独的html页面。

我在我的sass中有一些svg文件的链接,看起来像这样:

label {
    background: url(../images/checkbox.svg);
    }

问题是我在编译后从未在浏览器中获取它。 我有以下情况:

  1. 如果我使用svg-loader编译它,在浏览器中我看到编译的css是这样的: background: url([object Object]);

建议使用svg-url-loader代替。

  1. 如果我使用提到的svg-url-loader ,我将整页css搞砸了,这使得浏览器显示原始文本而不是样式页面。
  2. 如果我使用file-loader ,我将css编译为后台:

background: url(37efc0ccedf6fe109636ad1416c29425.svg)

当我把结果bundle.js放到其他地方时,我不满意复制我已经拥有的一些文件。

  1. 如果我使用raw-loader ,我在url(...)中得到一些xml而不是文件名,这只是不起作用,在css中显示“错误的属性值”错误。 我很乐意获得正常的路径而不是所有的东西,比如

background: url(../images/checkbox.svg);

那么在我的情况下处理svg的正确方法是什么? 谢谢。


I use webpack via CLI, like webpack --watch. Goal is to compile JS with SASS and put in some separate html page.

I have some links to svg files in my sass, looking like that:

label {
    background: url(../images/checkbox.svg);
    }

The problem is that I never get it in the browser after compiling. I have following situations:

  1. If I compile it using svg-loader, in browser I see compiled css is something like that: background: url([object Object]);

Here is suggested to use svg-url-loader instead.

  1. If I use mentioned svg-url-loader, I have whole page css messed up which makes browser to show raw text instead of styled page.
  2. If I use file-loader, I get css compiled to background:

background: url(37efc0ccedf6fe109636ad1416c29425.svg)

and as I put resulted bundle.js to some other place, I am not happy with copying some files I already have.

  1. If I use raw-loader, I get some xml instead of file name in the url(...), which just doesn't work, showing "wrong property value" error in the css. I would be happy to get just regular path instead of all that things, like

background: url(../images/checkbox.svg);

So what is correct approach to handle svg in my situation? Thank you.


原文:https://stackoverflow.com/questions/34779370
更新时间:2022-02-05 21:02

最满意答案

尽管存在行为差异,SomeOtherAdapter是否有任何业务实施IMyAdapter?

是。 处理接口时,任务返回方法表明它可能是异步的。 如果你有一个同步的真实(即非测试 - 存根)实现,我会在接口本身的文档中注意到方法调用实际上可能是同步的。

让IMyAdapter返回任务类型有什么好处吗? 大概应用程序调用等待MyFileProcessor.DoSomeWorkAsync(...),那么为什么让适配器异步?

是。 您的第一个示例是使用异步的I / O绑定操作,因此使接口任务返回(即异步兼容)非常有意义。

这些操作主要是I / O绑定,而不是CPU绑定 - 这是否会影响我决定如何设计这些组件?

是。 每当您有一个可能异步实现的接口时,它应该具有这些方法的异步兼容签名。

如果MyFileProcessor不需要执行任何CPU绑定工作,那么使用异步是否有任何好处?

我不明白这个问题; 它似乎意味着async应该用于CPU绑定工作。 但这与异步的工作原理相反; async非常适合I / O绑定代码,而不是CPU绑定代码。

您可能对我的async OOP博客系列感兴趣。


Does SomeOtherAdapter have any business implementing IMyAdapter despite the behavioral differences?

Yes. When you deal with interfaces, a task-returning method indicates that it may possibly be asynchronous. If you have a real (i.e., non-test-stub) implementation that is synchronous, I would note in the documentation of the interface itself that the method call may actually be synchronous.

Is there any benefit to having IMyAdapter return Task types? Presumably the application calls await MyFileProcessor.DoSomeWorkAsync(...), so why let the adapters be async?

Yes. Your first example is with an asynchronous, I/O-bound operation, so it makes total sense to make the interface task-returning (i.e., async-compatible).

These operations are mainly I/O bound, not CPU bound - should that impact my decision in how I would design these components?

Yes. Any time you have an interface that is likely to be implemented asynchronously, it should have async-compatible signatures for those methods.

If MyFileProcessor doesn't need to do any CPU bound work, is there any benefit to using async at all?

I don't understand this question; it seems to imply that async should be used for CPU-bound work. But that's the opposite of how async works; async is a natural fit for I/O-bound code, not CPU-bound code.

You may be interested in my async OOP blog series.

相关问答

更多
  • int[] ids = new[] { 1, 2, 3, 4, 5 }; Parallel.ForEach(ids, i => DoSomething(1, i, blogClient).Wait()); 虽然您与上述代码并行运行操作,但是该代码阻止每个操作运行的每个线程。 例如,如果网络呼叫需要2秒钟,每个线程挂起2秒,w / o做任何事情,但等待。 int[] ids = new[] { 1, 2, 3, 4, 5 }; Task.WaitAll(ids.Select(i => DoSomething ...
  • 尽管存在行为差异,SomeOtherAdapter是否有任何业务实施IMyAdapter? 是。 处理接口时,任务返回方法表明它可能是异步的。 如果你有一个同步的真实(即非测试 - 存根)实现,我会在接口本身的文档中注意到方法调用实际上可能是同步的。 让IMyAdapter返回任务类型有什么好处吗? 大概应用程序调用等待MyFileProcessor.DoSomeWorkAsync(...),那么为什么让适配器异步? 是。 您的第一个示例是使用异步的I / O绑定操作,因此使接口任务返回(即异步兼容)非常有 ...
  • 所以,考虑到更多的想法,我认为取消Async任务是没有意义的,因为Begin部分将被调用'inline',就在调用线程上。 因此,不需要以这种方式支持取消。 如果您想实际中止处理调用(例如,到Web服务或使用Web客户端),您可以实现TaskCompletionSource方法,而不是在此处记录: http : //msdn.microsoft.com/en-us/library/ee622454.aspx 很抱歉回答我自己的问题,我猜这有点不禁。 So, having put some more thou ...
  • 经过一番研究,我发现在ORM实例中继承一个承诺并不是一个好主意,因为以下几点: Promises以递归方式解决,每个都返回一个从最后解决的new promise 。 例如: var debug = console.log var promise1 = new Promise((r, e) => { r(1) }) var promise2 = new Promise((r, e) => { r(2) }) var promise3 = promise1.then(data => prom ...
  • 我看到两个问题: 1) 有人可以在第二个异步任务onPostExecute完全完成之前解释为什么调用例程正在进行中吗? 因为打电话 new identifyServer().execute(serverCheck); 仅启动identifyServer任务。 在单独的线程上启动任务后,此调用将返回。 因此,在调用线程(即执行第一个任务的onPostExecute方法的线程)中,Toast的显示是下一个要执行的代码。 正如您所观察到的那样,时间有时会在第二个任务完成之前显示。 2) 如何更好地构建此IP扫描 ...
  • 这基本上是扩展@FrankFajardo的答案,提供一个具体的例子。 传入CancellationToken ,您还需要监视来自外部的任何取消请求。 它看起来像这样: class Class1 { public async Task SomeTaskAsync(CancellationToken cancellationToken) { for (int i = 0; i < 5; i++) { if (cancellationToke ...
  • 经过一番调查和调试后,我找到了答案。 我会在这里描述一下,也许它可以在将来帮助别人。 正如我所怀疑的那样,当需要运行的所有任务都完成时, GcmTaskService停止(这很有意义)。 这方面的证明就是这个方法(在GcmTaskService类中): private void zzdJ(String var1) { Set var2 = this.zzaIU; synchronized(this.zzaIU) { this.zzaIU.remove(var1); ...
  • 好吧,你可以自己构建,但我认为使用TPL Dataflow会更容易。 就像是: static async Task DoWork() { // By default, ActionBlock uses MaxDegreeOfParallelism == 1, // so AThreadUnsafeMethod is not called in parallel. var block = new ActionBlock(AThreadUnsafeMethod); // Star ...
  • 在一个方法中有多个await s没有任何问题。 事实上,这就是为什么你首先使用await ,真的 - 为你管理状态机和延续。 是的,控制权将返回给呼叫者。 但重点是,如果你正在使用await ,你需要一直使用await - 你所描述的行为只会在你的await链被一些不await某种异步方法的方法破坏时发生。 这就是问题所在,而不是await多次的async方法。 There's nothing wrong with having multiple awaits in one method. In fact, ...
  • 这并不难理解,因为它有点像Node.JS的工作原理,除了Node使用了很多回调来实现这一点。 然而,这是我无法理解其优势的地方。 Node.js确实使用了回调,但它有另一个重要的方面,它真正简化了这些回调:它们都被序列化到同一个线程。 因此,当您在.NET中查看异步回调时,通常会处理多线程和异步编程( EAP样式的回调除外)。 使用回调的异步编程称为“继续传递样式”(CPS)。 它是Node.js唯一真正的选项,但它是.NET上的众多选项之一。 特别是,CPS代码可能变得极其复杂且难以维护,因此引入了asy ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)