<legend id='wfe6o'><style id='wfe6o'><dir id='wfe6o'><q id='wfe6o'></q></dir></style></legend>

  1. <tfoot id='wfe6o'></tfoot>

  2. <small id='wfe6o'></small><noframes id='wfe6o'>

      <bdo id='wfe6o'></bdo><ul id='wfe6o'></ul>

    <i id='wfe6o'><tr id='wfe6o'><dt id='wfe6o'><q id='wfe6o'><span id='wfe6o'><b id='wfe6o'><form id='wfe6o'><ins id='wfe6o'></ins><ul id='wfe6o'></ul><sub id='wfe6o'></sub></form><legend id='wfe6o'></legend><bdo id='wfe6o'><pre id='wfe6o'><center id='wfe6o'></center></pre></bdo></b><th id='wfe6o'></th></span></q></dt></tr></i><div id='wfe6o'><tfoot id='wfe6o'></tfoot><dl id='wfe6o'><fieldset id='wfe6o'></fieldset></dl></div>

      从 JavaScript 文件或 REPL 中 require()'ing CoffeeScript 文件

      时间:2024-04-20

        <bdo id='teTXP'></bdo><ul id='teTXP'></ul>
      • <small id='teTXP'></small><noframes id='teTXP'>

          <tbody id='teTXP'></tbody>
      • <legend id='teTXP'><style id='teTXP'><dir id='teTXP'><q id='teTXP'></q></dir></style></legend>
      • <i id='teTXP'><tr id='teTXP'><dt id='teTXP'><q id='teTXP'><span id='teTXP'><b id='teTXP'><form id='teTXP'><ins id='teTXP'></ins><ul id='teTXP'></ul><sub id='teTXP'></sub></form><legend id='teTXP'></legend><bdo id='teTXP'><pre id='teTXP'><center id='teTXP'></center></pre></bdo></b><th id='teTXP'></th></span></q></dt></tr></i><div id='teTXP'><tfoot id='teTXP'></tfoot><dl id='teTXP'><fieldset id='teTXP'></fieldset></dl></div>
        <tfoot id='teTXP'></tfoot>

              • 本文介绍了从 JavaScript 文件或 REPL 中 require()'ing CoffeeScript 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我正在使用 Node.js 并希望将 CoffeeScript 合并到我的工作流程中.我有两个用例:

                I'm using Node.js and wanting to incorporate CoffeeScript into my workflow. I have two use-cases:

                1. 我希望能够编写 require() CoffeeScript 模块的 JavaScript 文件
                2. 我希望能够从节点 REPL 中加载 CoffeeScript 模块
                1. I want to be able to write JavaScript files which require() CoffeeScript modules
                2. I want to be able to load CoffeeScript modules from within the node REPL

                对于案例 #1: 我可以从 .coffee 编译为 .jsrequire().js 模块,作为一种解决方法.

                For case #1: I can just compile from .coffee to .js and require() the .js module, as a workaround.

                对于案例 #2: 现在我正在 eval() 处理 coffee-script.compile() 的输出.

                For case #2: Right now I'm eval()ing the output of coffee-script.compile().

                有没有更好、更统一的方法来做到这一点?

                Is there a better, more unified way to do this?

                推荐答案

                coffee-script 模块在需要时注册其扩展.

                The coffee-script module registers its extension once required.

                $ echo 'console.log "works"' > module.coffee
                
                $ echo '
                > require("coffee-script")
                > require("./module")
                > ' > test.js
                
                $ node test.js
                works
                
                $ node
                > require('coffee-script'); require('./module')
                works
                {}
                

                编辑:这种行为随着 CoffeeScript 1.7.0 的发布而改变.现在你需要做:

                Edit: This behaviour has changed with the relase of CoffeeScript 1.7.0. Now you need to do:

                require('coffee-script/register');
                

                这篇关于从 JavaScript 文件或 REPL 中 require()'ing CoffeeScript 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:CoffeeScript 中的三元运算 下一篇:CoffeeScript 中的函数声明

                相关文章

                • <bdo id='xgvaD'></bdo><ul id='xgvaD'></ul>

              • <tfoot id='xgvaD'></tfoot>
              • <i id='xgvaD'><tr id='xgvaD'><dt id='xgvaD'><q id='xgvaD'><span id='xgvaD'><b id='xgvaD'><form id='xgvaD'><ins id='xgvaD'></ins><ul id='xgvaD'></ul><sub id='xgvaD'></sub></form><legend id='xgvaD'></legend><bdo id='xgvaD'><pre id='xgvaD'><center id='xgvaD'></center></pre></bdo></b><th id='xgvaD'></th></span></q></dt></tr></i><div id='xgvaD'><tfoot id='xgvaD'></tfoot><dl id='xgvaD'><fieldset id='xgvaD'></fieldset></dl></div>
              • <legend id='xgvaD'><style id='xgvaD'><dir id='xgvaD'><q id='xgvaD'></q></dir></style></legend>

                <small id='xgvaD'></small><noframes id='xgvaD'>