How to include one CoffeeScript file in another in

2019-09-14 00:30发布

I'm unable to get CoffeeScript in Jasmine to include another file. I'd like to share common functions amongst Jasmine specs which are written in CoffeeScript.

I'm sure I'm getting the syntax wrong, I've tried require and include, I've tried putting the file in the same folder just to be sure, I've tried # = syntax too.

I'm looking for something similar to include in php, i.e. go here -> compile this -> come back so the compile this step can easily be shared.

NB, I am not talking about inclusion in the compiled source, but inclusion before / during the compile step - I am also running these scripts as part of a Jasmine / Evergreen setup, accessing the URL in the browser.

1条回答
我想做一个坏孩纸
2楼-- · 2019-09-14 01:07

What you're looking for is a build system, which Coffeescript is not. Coffeescript can translate the syntax of a single file only into plain Javascript, it does not concern itself with concatenating or bundling additional external resources. There are a metric ton of Javascript build systems which can inline require calls; personally I'm very happy with Duo at the moment, but Grunt is the de facto kitchen sink in Javascript build systems, so have a look at both and others.

查看更多
登录 后发表回答