how to use node.js module system on the clientside

前端 未结 7 1055
感情败类
感情败类 2020-11-27 13:48

I would like to use the CommonJS module system in a clientside javascript application. I chose nodejs as implementation but can\'t find any tutorial or docs on how to use no

7条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-27 14:01

    SubStack on github has a module called node-browserify.

    It will compress and bundle your modules and deliver it as a single js file, but you use it just like Node.js (example from module readme):

    
        
        
        
    
    
        foo = 
    
    
    

    From the module description:

    Browserify

    Browser-side require() for your node modules and npm packages**

    Browserify bundles everything ahead-of-time at the mount point you specify. None of this ajaxy module loading business.

    More features:

    • recursively bundle dependencies of npm modules
    • uses es5-shim for browsers that suck
    • filters for {min,ugl}ification
    • coffee script works too!

提交回复
热议问题