Requiring CoffeeScript file from within another Co

2019-07-10 17:03发布

I was wondering if you are able to require a coffeescript from within another coffeescript.

My example code from file "user.coffee"

class UserObj
    constructor: (@name) ->
        console.log @name

My example code from main file

require "./user.coffee"

User = new UserObj "Example"

Is this possible from within a coffeescript file or just a js file?

3条回答
\"骚年 ilove
2楼-- · 2019-07-10 17:35

Yes it is possible.

user.coffee:

exports.UserObj = 
class UserObj
    constructor: (@name) ->
        console.log @name

main.coffee:

{UserObj} = require "./user"

User = new UserObj "Example"
查看更多
看我几分像从前
3楼-- · 2019-07-10 17:44

You can use this library coffee-stir to include other dependencies. Its a way around only using required from the web and it will add dependencies as you use it. FYI i made the lib when i was facing similar problems

查看更多
姐就是有狂的资本
4楼-- · 2019-07-10 17:53
登录 后发表回答