将 CoffeeScript 项目转换为 JavaScript(无需缩小)?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10441452/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 01:19:53  来源:igfitidea点击:

Convert a CoffeeScript project to JavaScript (without minification)?

javascriptjsonnode.jscoffeescriptnpm

提问by blong

We're using a particular jQuery pluginwritten in CoffeeScript at work and I'm hoping I can convert the project into somewhat normal looking JavaScript. The library looks like it's structured really well (good OOP practices), but I'd really like it if I could explore it's source code without having to learn all the tricks that CoffeeScript entails.

我们在工作中使用了一个用 CoffeeScript 编写的特定 jQuery插件,我希望我可以将项目转换为看起来有些正常的 JavaScript。该库的结构看起来非常好(良好的 OOP 实践),但如果我可以探索它的源代码而不必学习 CoffeeScript 需要的所有技巧,我真的很喜欢它。

回答by Michelle Tilley

Compiling CoffeeScript into JavaScript usually results in JS that is fairly readable. You can convert snippets on the fly on the "Try CoffeeScript" tab of the CoffeeScript homepage, or via the CoffeeScript command line tool.

将 CoffeeScript 编译成 JavaScript 通常会生成具有相当可读性的 JS。您可以在 CoffeeScript 主页的“试用 CoffeeScript”选项卡上或通过CoffeeScript 命令行工具即时转换代码片段。

There are also tools like decaffeinatethat convert CoffeeScript source to modern JavaScript.

还有像decaffeinate这样的工具可以将 CoffeeScript 源代码转换为现代 JavaScript。

If you know JavaScript and just want to be able to read the source of a file, a perusal of the CoffeeScript homepage will probably give you enough understanding of CoffeeScript to read CoffeeScript sources fairly easily.

如果您了解 JavaScript 并且只想能够读取文件的源代码,仔细阅读 CoffeeScript 主页可能会让您对 CoffeeScript 有足够的了解,从而可以相当轻松地阅读 CoffeeScript 源代码。

回答by 250R

There's also this online compiler http://js2coffee.org/that can convert coffeescript to and from javascript

还有这个在线编译器http://js2coffee.org/可以将 coffeescript 与 javascript 相互转换

回答by Jon

On http://coffeescript.org/there is a tab - try CoffeeScript

http://coffeescript.org/ 上有一个选项卡 - 试试 CoffeeScript

Stick the coffee in the left side and JS pops up on the left

把咖啡粘在左边,左边弹出JS

回答by SethWhite

BinaryMusepointed you to the CoffeeScript command line tool, but I'd thought I post the actual command for posterity:

BinaryMuse 将指向 CoffeeScript 命令行工具,但我想我为后代发布了实际命令:

  • Compile a directory tree of .coffee files in src into a parallel tree of .js files in lib:

    coffee --compile --output lib/ src/

  • 将 src 中 .coffee 文件的目录树编译成 lib 中 .js 文件的并行树:

    咖啡 --compile --output lib/ src/

回答by jwold

You could also try Depercolator which wraps up a bunch of commands together (includes decafinate, cjsx-transform, react-codemod, prettier).

您还可以尝试将一堆命令打包在一起的 Depercolator(包括 decafinate、cjsx-transform、react-codemod、prettier)。

The writeup: https://blog.bugsnag.com/converting-a-large-react-codebase-from-coffeescript-to-es6/and GH repo: https://github.com/bugsnag/depercolator

文章:https: //blog.bugsnag.com/converting-a-large-react-codebase-from-coffeescript-to-es6/和 GH repo:https: //github.com/bugsnag/depercolator

回答by alvincrespo

Your best bet is to convert confeescript into JavaScript using their compiler, once you have that - you can go ahead and structure the JavaScript according to your style guide.

最好的办法是使用他们的编译器将 confeescript 转换为 JavaScript,一旦你有了它 - 你可以继续根据你的风格指南构建 JavaScript。

Hope that helps.

希望有帮助。