node.jsbrowserifylivescript

LiveScript's "require 'mymodule'" is not working in browser


I need to modularize my LiveScript project just like prelude-ls project does.

Here is my test project:

git clone https://bitbucket.org/ceremcem/livescript-module-test

In the Readme.md I included the steps to reproduce the problem:

Run server code:

  $ lsc server.ls

You will see the proper output.

Run client code:

  $ lsc -c myapp.ls
  $ lsc -c mymodule.ls
  $ browserify -r ./mymodule.js > mymodule-browser.js
  $ firefox index.html

Open firebug, you will see the error:

  Error: Cannot find module './mymodule'

  ...eturn a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");...

Solution

  • After examining prelude-ls project a bit deeper and with the helps of loganfsmyth, here is the example code and [here is the recipe] to build a browser version of a module:

    Run server code:

    $ lsc server.ls
    

    You will see the proper output:

    this is server script, running with lsc
    my test function has been called
    

    Run client code:

    $ lsc -c myapp.ls
    $ lsc -c mymodule.ls
    $ browserify -r ./mymodule.js:mymodule > mymodule-browser.js
    $ firefox index.html
    

    Open firebug, you will see the proper output:

    my app is running
    my test function has been called