我也可以在客户端使用 Coffeescript 吗?

发布于 2024-11-25 23:54:21 字数 31 浏览 0 评论 0原文

有没有办法在客户端使用CoffeeScript?

Is there any way to use CoffeeScript in client side?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

巷子口的你 2024-12-02 23:54:21

有两种方法:

  1. 将 CoffeeScript 编译为 JavaScript 并像部署任何 JavaScript 文件一样部署它,或者
  2. 使用 coffee- script.js,它允许您在页面中放置

不建议将后者用于生产用途,但这对或用于在线编辑器,如下所示:

<script crossorigin src="https://coffeescript.org/v2/browser-compiler-legacy/coffeescript.js"></script>

<script type="text/coffeescript">
console.log 'Hello World!'
</script>

请参阅相关问题: 有没有办法将 CoffeeScript 发送到客户端的浏览器并让它编译为 JavaScript *那里*?

There are two ways:

  1. Compile the CoffeeScript to JavaScript and deploy it as you would any JavaScript file, or
  2. Use coffee-script.js, which allows you to put <script type="text/coffeescript> tags in your page.

The latter isn't recommended for production use, but it's nice for development. Or for usage in online editors like these:

<script crossorigin src="https://coffeescript.org/v2/browser-compiler-legacy/coffeescript.js"></script>

<script type="text/coffeescript">
console.log 'Hello World!'
</script>

See the related question: Is there a way to send CoffeeScript to the client's browser and have it compiled to JavaScript *there*?

来日方长 2024-12-02 23:54:21

另请参阅 CoffeeScript 的 Webmake 插件 -> https://github.com/medikoo/webmake-coffee

它允许您以 Node.js 风格组织咖啡模块并将其捆绑到浏览器中。它提供源映射支持,因此您可以直接在浏览器中按原样调试 CoffeeScript 文件。

See also Webmake plugin for CoffeeScript -> https://github.com/medikoo/webmake-coffee

It allows you to organize coffee modules in Node.js style and bundle it for browser. It provides source maps support, so you can debug CoffeeScript files as they are, directly in a browser.

顾冷 2024-12-02 23:54:21

如果不想每次都编译,可以使用 -w 参数,coffee 会在每次文件更改时编译该文件

coffee -wco src/ public/js

To not compile everytime you can use -w param and coffee will compile the file everytime file change

coffee -wco src/ public/js
小草泠泠 2024-12-02 23:54:21

是的,可以通过将 CoffeeScript src 标记添加到 html 页面的 head 部分来完成。

从以下路径下载 CoffeeScript 源代码:http://coffeescript.org/extras/coffee-script。 js

复制并粘贴以下代码并尝试在浏览器中运行:

<html>
<head>
<script type="text/javascript">
function printHelloJava(){
alert("Hello Javascript");
}
</script>
<script src="coffee-script.js"></script>
<script type="text/coffeescript">
@printHello = ->
  alert "Hello Coffee Script"
</script>
</head>
<body>
<h1>Coffee Script on client side</h1>
<input type="button" onclick="printHelloJava();" value="Hello Java">
<br>
<input type="button" onclick="printHello()" value="Hello Coffee">
</body>
</html>

Yes, it can be done by adding a CoffeeScript src tag to the head section of your html page.

Download the CoffeeScript source from this path: http://coffeescript.org/extras/coffee-script.js

Copy and paste the below code and try to run in a browser:

<html>
<head>
<script type="text/javascript">
function printHelloJava(){
alert("Hello Javascript");
}
</script>
<script src="coffee-script.js"></script>
<script type="text/coffeescript">
@printHello = ->
  alert "Hello Coffee Script"
</script>
</head>
<body>
<h1>Coffee Script on client side</h1>
<input type="button" onclick="printHelloJava();" value="Hello Java">
<br>
<input type="button" onclick="printHello()" value="Hello Coffee">
</body>
</html>
北风几吹夏 2024-12-02 23:54:21

您还可以使用 CDN CoffeeScript 获得更好更快的性能。

<script src="http://cdnjs.cloudflare.com/ajax/libs/coffee-script/1.7.1/coffee-script.min.js"></script>

或者

<script src="https://cdn.rawgit.com/jashkenas/coffeescript/1.11.1/extras/coffee-script.js"></script>

然后使用 type="text/coffeescript" 编译 Coffee Script

<script type="text/coffeescript">
    // add code here
</script>

You can also use CDN coffeescript for better and faster performance.

<script src="http://cdnjs.cloudflare.com/ajax/libs/coffee-script/1.7.1/coffee-script.min.js"></script>

or

<script src="https://cdn.rawgit.com/jashkenas/coffeescript/1.11.1/extras/coffee-script.js"></script>

Then use type="text/coffeescript" for compile Coffee Script.

<script type="text/coffeescript">
    // add code here
</script>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文