如果我从 NuGet 安装 SassAndCoffee.Core 包,然后要求 SassAndCoffee 编译一些 CoffeeScript,它似乎将“裸”选项传递给 CoffeeScript 编译器 - 即,它不会将我的脚本包装在 CoffeeScript 的常用 ( function() {
和 }).call(this);
书挡。
有没有办法让 SassAndCoffee 不使用“裸”选项?
注意:这是在桌面应用程序中,我明确调用 SassAndCoffee 的代码 --这不是 ASP.NET 站点中发生的神奇重写。
更多详细信息:这是我使用 SassAndCoffee 编译 CoffeeScript 的代码。
var sassCompiler = new CoffeeScriptCompiler();
var js = sassCompiler.Compile("alert 'Hello World'");
这会在 js
变量中产生以下(裸)输出:
alert('Hello World');
但是如果我编写一些简单的 JavaScript 来调用 官方 CoffeeScript 编译器,使用默认选项,例如此 HTML 文件(删除 coffee-script.js 到同一目录中):
<script src="coffee-script.js"></script>
<script>
document.write("<pre>")
document.write(CoffeeScript.compile("alert 'Hello World'"))
document.write("</pre>")
</script>
我得到了预期的、包装好的 JavaScript 输出:
(function() {
alert('Hello World');
}).call(this);
看起来 SassAndCoffee 正在调用CoffeeScript.compile(input, {bare: true})
而不仅仅是 CoffeeScript.compile(input)
。
我想使用 SassAndCoffee.Core 来支持 V8,但我希望能够在默认输出和裸输出之间进行选择。如果没有重写 SassAndCoffee 的 CoffeeScript 编译器(这会有点挫败使用 SassAndCoffee 的意义),或者手动添加和附加包装器代码(我觉得重复编译器应该做的工作很脏),有什么办法可以得到SassAndCoffee 输出非裸 JavaScript?
If I install the SassAndCoffee.Core package from NuGet, and then ask SassAndCoffee to compile some CoffeeScript, it seems to pass the "bare" option to the CoffeeScript compiler -- i.e., it does not wrap my script in CoffeeScript's usual (function() {
and }).call(this);
bookends.
Is there a way I can make SassAndCoffee not use the "bare" option?
Note: this is in a desktop app, and I'm explicitly calling into SassAndCoffee's code -- this is not the magic rewriting that happens in an ASP.NET site.
More details: Here's my code to compile CoffeeScript using SassAndCoffee.
var sassCompiler = new CoffeeScriptCompiler();
var js = sassCompiler.Compile("alert 'Hello World'");
which results in the following (bare) output in the js
variable:
alert('Hello World');
But if I write some straightforward JavaScript that calls the official CoffeeScript compiler with the default options, e.g. this HTML file (drop coffee-script.js into the same directory):
<script src="coffee-script.js"></script>
<script>
document.write("<pre>")
document.write(CoffeeScript.compile("alert 'Hello World'"))
document.write("</pre>")
</script>
I get the expected, wrapped JavaScript output:
(function() {
alert('Hello World');
}).call(this);
It looks like SassAndCoffee is calling CoffeeScript.compile(input, {bare: true})
instead of just CoffeeScript.compile(input)
.
I'd like to use SassAndCoffee.Core for its V8 support, but I want to be able to choose between default output and bare output. Short of rewriting SassAndCoffee's CoffeeScript compiler (which would kinda defeat the point of using SassAndCoffee), or manually prepending and appending the wrapper code (I'd feel dirty duplicating work that the compiler is supposed to do), is there any way I can get SassAndCoffee to output non-bare JavaScript?
发布评论
评论(1)
如果我没看错的话,这似乎是开发人员的明确决定:
https://github.com/xpaulbettsx/SassAndCoffee/blob/43300b7805db8b3dccf20cc71d1282ecfd8c76e1/SassAndCoffee.Core/CoffeeScript/coffee-script.js
这也可能为您提供需要更改的文件来修改它符合您的需求。
作为替代方案,以防万一您遇到困难,我使用 Mindscape Web Workbench 作为 Visual Studio该插件似乎可以完成 SassAndCoffee 为您完成的大部分工作。
If I'm reading this right, it seems to be an explicit decision by the developers:
https://github.com/xpaulbettsx/SassAndCoffee/blob/43300b7805db8b3dccf20cc71d1282ecfd8c76e1/SassAndCoffee.Core/CoffeeScript/coffee-script.js
That might also provide you the file you need to change to modify it to your needs.
As an alternative, in case you get stuck, I use Mindscape Web Workbench as a Visual Studio plugin that seems to do most of what it appears SassAndCoffee accomplishes for you.