将svg加载为路径(Load svg as path)
我通过CLI使用webpack,比如
webpack --watch
。 目标是用SASS编译JS并放入一些单独的html页面。我在我的sass中有一些svg文件的链接,看起来像这样:
label { background: url(../images/checkbox.svg); }
问题是我在编译后从未在浏览器中获取它。 我有以下情况:
- 如果我使用svg-loader编译它,在浏览器中我看到编译的css是这样的:
background: url([object Object]);
建议使用
svg-url-loader
代替。
- 如果我使用提到的
svg-url-loader
,我将整页css搞砸了,这使得浏览器显示原始文本而不是样式页面。- 如果我使用
file-loader
,我将css编译为后台:
background: url(37efc0ccedf6fe109636ad1416c29425.svg)
当我把结果bundle.js放到其他地方时,我不满意复制我已经拥有的一些文件。
- 如果我使用
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:
- 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.
- 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.- 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.
- 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
最满意答案
尽管存在行为差异,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 ...
-
嵌套并继承异步/任务(Nesting and inheriting async/Tasks)[2024-02-05]
尽管存在行为差异,SomeOtherAdapter是否有任何业务实施IMyAdapter? 是。 处理接口时,任务返回方法表明它可能是异步的。 如果你有一个同步的真实(即非测试 - 存根)实现,我会在接口本身的文档中注意到方法调用实际上可能是同步的。 让IMyAdapter返回任务类型有什么好处吗? 大概应用程序调用等待MyFileProcessor.DoSomeWorkAsync(...),那么为什么让适配器异步? 是。 您的第一个示例是使用异步的I / O绑定操作,因此使接口任务返回(即异步兼容)非常有 ... -
使用异步任务取消(Using Cancellation with Async Tasks)[2024-01-11]
所以,考虑到更多的想法,我认为取消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扫描 ...
-
取消所有异步任务(Cancel all async tasks)[2022-01-31]
这基本上是扩展@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 ...
-
异步任务之间的依赖关系(Dependencies between async tasks)[2024-01-04]
在一个方法中有多个await s没有任何问题。 事实上,这就是为什么你首先使用await ,真的 - 为你管理状态机和延续。 是的,控制权将返回给呼叫者。 但重点是,如果你正在使用await ,你需要一直使用await - 你所描述的行为只会在你的await链被一些不await某种异步方法的方法破坏时发生。 这就是问题所在,而不是await多次的async方法。 There's nothing wrong with having multiple awaits in one method. In fact, ... -
异步/等待和任务(Async/Await and Tasks)[2021-05-04]
这并不难理解,因为它有点像Node.JS的工作原理,除了Node使用了很多回调来实现这一点。 然而,这是我无法理解其优势的地方。 Node.js确实使用了回调,但它有另一个重要的方面,它真正简化了这些回调:它们都被序列化到同一个线程。 因此,当您在.NET中查看异步回调时,通常会处理多线程和异步编程( EAP样式的回调除外)。 使用回调的异步编程称为“继续传递样式”(CPS)。 它是Node.js唯一真正的选项,但它是.NET上的众多选项之一。 特别是,CPS代码可能变得极其复杂且难以维护,因此引入了asy ...