File watcher: “An output directory must be specified when compiling a directory”

旧街凉风 提交于 2020-02-02 16:33:07

问题


cmd.exe /D /C call C:\Users\sebas\AppData\Roaming\npm\node-sass.cmd style.scss:style.css An output directory must be specified when compiling a directory

The scss file I want the file watcher to watch is placed at the root of my project.

Watch the error appear: gif_link

How do I fix this error?


回答1:


If you like the .css files to be generated in the same folder as original file, try the following settings:

Note the Create output file from stdout option - it has to be enabled, as node-sass writes CSS to stdout unless the -o option is passed.

If you like to place generated files in a separate folder, use the -o option:




回答2:


Although @lena answer has nothing wrong in my opinion, I would like to add some information to (Compress) minify the node-sass output into a file with a different name and eventually at a different directory.

It seems the documentation at node-sass page is not completely accurate. Options don't always go before the input filename. Option --output-style, for example, has to be placed AFTER the output definition. Looks like any option starting with --o or -o before the input filename, generates the error described in the question.

On the other hand, node-sass generates the compiled file at the source directory by default, unless the -o option is used to modify the target directory (Check -o, --output Output directory at node-sass Command Line Interface).

That option (-o) exists only to change the target directory, NOT the filename, which is normally not expected and should not be included in the argument. It is by default the same source filename with extension css.

Now, to modify also the output filename and eventually the target directory, do not use node-sass -o option and CHECK (Enable) the PhpStorm/WebStorm Create output file from stdout option as described in @Lena answer 1st image.

Example:
To get a COMPRESSED (minified) output file ending with .min.css at the parent directory, the watcher "Arguments" field should contain:
$FileName$ $FileParentDir$/$FileNameWithoutExtension$.min.css --output-style compressed

If the parent directory is CSS and the source file is example.scss at any sub-directory, the compiler will generate example.min.css at CSS directory.

This is an example using watchers macros, but you can change directories and filenames as appropriate.



来源:https://stackoverflow.com/questions/57102994/file-watcher-an-output-directory-must-be-specified-when-compiling-a-directory

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!