如何在没有编译css in react的情况下观看sass文件夹的更改(How to watch sass folder for changes without compiling in css in react)
Curreny我在package.json中的脚本如下所示:
"scripts": { "build-css": "node-sass-chokidar src/styles/ -o src/styles/", "watch-css": "npm run build-css && node-sass-chokidar src/styles/ -o src/styles/ --watch --recursive" }
当我键入npm run watch-css它监视并编译我的所有scss文件到css。 我在我的反应组件中导入已编译的css文件,如导入'../styles/component.css'
我需要找到一种方法来导入不是css文件而是scss文件,并使用特殊命令,如npm run watch-scss,查看我在scss文件中所做的所有更改。
PS:我正在使用create-react-app
Curreny my scripts in package.json looks like this:
"scripts": { "build-css": "node-sass-chokidar src/styles/ -o src/styles/", "watch-css": "npm run build-css && node-sass-chokidar src/styles/ -o src/styles/ --watch --recursive" }
When I type npm run watch-css It watches and compiles all my scss files into css. And I import compiled css file in my react component like this import '../styles/component.css'
I need to find a way to import not css file but scss file and with special command like npm run watch-scss see all the changes I make in my scss file.
PS: I'm using create-react-app
原文:https://stackoverflow.com/questions/46719828
最满意答案
这真的有必要吗?
如果您仍在使用手动内存管理。 如果没有保留,
returnObject
从数组中删除它就可以释放returnObject
。 可变数组保留它包含的对象,并在删除时释放它们。 在移除对象之前保留对象可防止对象被释放; 自动释放它允许对象保持足够长的时间以使调用方法接收它。如果您正在使用ARC(并且没有太多理由不这样做),您不必担心任何问题。 编译器将确定何时保留以及何时为您释放。
我的印象是运行时将在运行循环迭代结束时通过removeLastObject销毁从内容中删除的对象
如果NSMutableArray在移除对象时自动释放对象会发生这种情况,但我认为没有任何理由认为它确实存在。 如果
-removeLastObject
返回已删除的对象,则可以指望已删除的对象被自动释放,但它不会。 你永远不应该假设另一个对象对它拥有的对象做了什么。Is this really necessary?
It is if you're still using manual memory management. Without that retain,
returnObject
could be deallocated as soon as you remove it from the array. A mutable array retains the objects that it contains and releases them upon removal. Retaining an object before removing it prevents the object from being deallocated; autoreleasing it allows the object to stick around long enough for the calling method to receive it.If you're using ARC (and there aren't many reasons not to), you don't have to worry about any of that. The compiler will figure out when to retain and when to release for you.
I'm under the impression that the runtime will destroy the object removed from contents via removeLastObject at the end of a run-loop iteration
That's what would happen if NSMutableArray autoreleased objects when it removes them, but I don't see any reason to think that it does. You could count on the removed object being autoreleased if
-removeLastObject
returned the removed object, but it doesn't. You should never make assumptions about what another object does with the objects it owns.
相关问答
更多-
有一些开销,在极少数情况下(例如,微基准;)可能很重要,无论优化是否到位(其中有很多)。 但是,正常情况下,对于对象的引用计数的非争用操作进行了优化。 所以问题是,如果引用计数对于线程来说太过于糟糕,Objective-C如何做呢? 游戏中有多个锁,实际上,任何给定对象上的保留/释放都会为该对象选择一个随机锁(但始终是相同的锁)。 因此,减少了锁争用,而不需要每个对象一个锁。 (以及Catfish_man所说的;有些类将实现自己的引用计数方案,以使用特定于类的锁定原语来避免争用和/或针对其特定需求进行优化。 ...
-
CGRect,CGPoint等只是简单的结构,所以你可以通过值传递它们......你不需要在堆上分配它们。 但是,如果您确实在堆上分配它们,那么您将需要使用malloc / free来自行管理它们。 返回这些对象的大多数CoreGraphics函数只返回对象(例如CGRect )而不是指向它们的指针(例如CGRect* ),因此您不必担心它。 CGRect, CGPoint, etc. are just plain structs, so you can just pass them around by v ...
-
是的,你可以这样做。 这并不奇异。 在ARC:你只是使用它,它的工作原理。 请注意,如果将Objective-C数据成员放在没有构造函数或析构函数(“POD”类)的类中,您将收到警告,因为如果将该定义导入ARC和MRC代码,则会发生错误。 如果是这种情况的解决方案是添加虚拟构造函数或析构函数。 在MRC中:您需要按照实例变量的正常MRC内存管理规则来保留和释放它。 即如果您指定它,请确保释放先前的值并保留新值。 在类的析构函数中(如果没有析构函数,则添加析构函数),您需要释放它。 此外,在构造函数中,确保初 ...
-
选项1很好,因为全局变量myImportantString默认为strong 。 该字符串将永远不会被释放(这对全局来说很好)。 Option 1 is fine because the global variable myImportantString defaults to strong. The string will never be released (which is fine for a global).
-
在Objective-C中处理内存管理时要记住的第一个规则是,您负责(1)分配(使用alloc ),(2)new up(使用new ),(3)副本(使用copy ),或(4)保留(使用retain )。 在这四种情况下,您必须明确release (或autorelease )这些引用。 在您的示例中,由于您已分配recipeView,因此必须在将其添加到导航控制器后将其释放。 RecipeView * recipeView = [[RecipeView alloc] initWithNibName:@"Re ...
-
在呈现下一个UIViewController之前释放对象是不正常的。 假设您有一个NIB,它的内容将在您(或系统)第一次访问视图成员时加载。 您的视图控制器将调用loadView,然后调用viewDidLoad。 如果您想要以编程方式添加任何视图,则可以在loadView或viewDidLoad中执行此操作,如果要查询从NIB加载的对象,则可以在viewDidLoad中执行此操作。 加载后,除非发生内存不足警告,否则视图将保留在内存中。 那时它将被释放。 你会得到viewDidUnload。 你应该释放任何 ...
-
认为你的路径是错误的 - 我怀疑,引用计数(以及非iOS设备上的垃圾收集)如何工作的基本原理是嵌入到语言实现中,以使其成为现实的可能性。 我也不明白你为什么要这样做,除非你特别喜欢重新发明轮子。 Think you're on a wrong path - the fundamentals of how the reference counting (and indeed garbage collection on non iOS devices) work are, I suspect, too embe ...
-
这真的有必要吗? 如果您仍在使用手动内存管理。 如果没有保留, returnObject从数组中删除它就可以释放returnObject 。 可变数组保留它包含的对象,并在删除时释放它们。 在移除对象之前保留对象可防止对象被释放; 自动释放它允许对象保持足够长的时间以使调用方法接收它。 如果您正在使用ARC(并且没有太多理由不这样做),您不必担心任何问题。 编译器将确定何时保留以及何时为您释放。 我的印象是运行时将在运行循环迭代结束时通过removeLastObject销毁从内容中删除的对象 如果NSMut ...
-
- (void)aMethod { UIView *aView = [self createObject]; } - (UIView *)createObject { UIView *returnView = [[UIView alloc] initWithFrame:CGRectZero]; [returnView autorelease]; return returnView; } - (void)aMethod { UIView *aView = [self ...
-
静态分析器将通过检查代码而不运行代码来尝试查找代码中的错误。 当您意外发生分配错误时,它非常擅长发现时间。 它会告诉您无法引起问题的事情,以及当您超出正常Objective-C惯例的场合。 所以如果它突出显示某些您认为不会导致问题的东西,不一定会感到困惑 - Objective-C是规则和约定的组合,分析器会查找两者的违规情况。 仪器将在运行时查找泄漏的物体。 所以它只能找到实际发生的问题。 所以原则上你需要通过程序中的每一个潜在的使用路径来捕捉一切。 但它在实践中往往非常有用。 而且使用起来并不复杂。 只 ...