bartosz-m / livescript-esm-loader

Livescript loader for node.js
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

How to compile? #1

Open michael-brade opened 6 years ago

michael-brade commented 6 years ago

Hi, this looks like great work!

Now I would like to try it by compiling a LiveScript source with import statements to JavaScript, ideally so that webpack can create a bundle for the browser.

I understand how to start node and load ls files on the fly. But how can I get hold of the transpiled code? Do you have any examples? Thanks :)

bartosz-m commented 6 years ago

livescript-esm-loader is meant for runtime loading modules into node.js and it is very WIP at the moment. The easiest way to accomplished what you are asking would be to use livescript-transform-esm (loader is using it under the hood) Give few minutes and I'll ensure it works from cli and then I'll write how to use it.

michael-brade commented 6 years ago

lovely! :)

bartosz-m commented 6 years ago

Ok got it working with little gotchas (livescript from git is required and need to specify source-map type)

livescript-transform-esm has register file which hooks into livescript compiler. So to make it work simply require it during compilation.

First install livescript and transfrom-esm

npm i -D https://github.com/gkz/LiveScript livescript-transform-esm

next assuming transpilation from src to tmp

node_modules/.bin/lsc -r livescript-transform-esm/register -cm linked -o tmp src 
bartosz-m commented 6 years ago

just fixed problem with source-map, they're no longer necessary also added readme with some examples of extra features check npm or github

michael-brade commented 6 years ago

Amazing! This looks perfect. Will try soon and report back.

michael-brade commented 6 years ago

Wow, how simple! It works rather good, thanks for all your work! I was fighting with babel and some other issues for hours :( So that's why I'm answering late. I found just one thing worth changing: this export

export class HtmlGenerator

is transpiled to

var export$;
export { export$ }
export$ = HtmlGenerator = (function(){

which means I have to require('html-generator').export$. And I'm not even sure it would work with babel since it would expect export$ to be called HtmlGenerator. So should this be renamed? If I do export default ... I get the expected result: export { export$ as default }

bartosz-m commented 6 years ago

I've created issue at livescript-transform-esm repo. I'll work in the morning (UTC+01:00)

michael-brade commented 6 years ago

No worries! Same here, I need sleep....