boot-clj / boot-cljs

Boot task to compile ClojureScript programs.
Eclipse Public License 1.0
176 stars 40 forks source link

Example of :preprocess given recent updates #179

Open SevereOverfl0w opened 7 years ago

SevereOverfl0w commented 7 years ago

continuation of https://github.com/boot-clj/boot-cljs/issues/151

One annoyance is that :file in :foreign-libs is not prefixed on the classpath automatically to the relevant boot tmp files.

SevereOverfl0w commented 7 years ago

I think I got close, but got this error: Error: Cannot find module '@cljs-oss/module-deps'

Deraen commented 7 years ago

You need to run npm install @cljs-oss/module-deps to use module processing.

SevereOverfl0w commented 7 years ago

I see. That makes sense.

I made some further progress by removing the folder containing the js to compile out of my src directory (which felt a little wonky, is this expected?).

I couldn't manage to require react 15 (from node_modules) from that external js though however. I'd be quite happy to require the cljsjs.React, but that didn't seem possible either.

The error I saw was this:

TypeError: module$home$dominic$src$github_com$juxt$edge$node_modules$react$react.default is undefined[Learn More]
Deraen commented 7 years ago

Looks like you are trying to require React (CommonJS) from ES6 module. That doesn't work currently: https://github.com/google/closure-compiler/issues/2634

And foreign libs (cljsjs) are Cljs only, so they can't be used from module processing modules.

SevereOverfl0w commented 7 years ago

Okay, so if I convert the code to be commonjs throughout, that seems to be working. Unless I end up depending on a module which uses ES6 modules, I guess? (I'm not sure if that can happen)

I thought they might be cljs only, but figured I'd ask regardless.


I have this working now, which is great!

Things that seem to be missing:

  1. the input files have to be off the classpath else they conflict & you never get your transformed version. I think boot-cljs should be removing them from the fileset (just a hunch)
  2. As the input files are off the classpath, there's no file reloading. This might be fixed by 1.
  3. the foreign-libs requires the prefix src/ or wherever you keep your code, instead of using the classpath like other properties which are transformed automatically, this has been useful in dodging 1, but is probably not desired behaviour.

Are these things that boot-cljs should/would fix? Shall I open specific issue(s) to track them?

Deraen commented 7 years ago

You can depend on most ES6 modules, but not on those ES6 modules that use CJS.

CommonJS -> ES6 Works ES6 -> CommonJS Doesn't

I have only looked into case where using existing Node packages, which are always under node_modules, not sure what happens and should happen with local CJS or ES6 modules.