Code Monkey home page Code Monkey logo

Comments (12)

martinklepsch avatar martinklepsch commented on July 20, 2024

Hey, thanks for the extensive write-up!

I can do PR to merge them here.

Happy to merge.

import-js I think currently runs every time watch is triggered

Meant to make this also run only once but didn't get to it yet.

We could check if java.class.path has changed after previous run?

Sounds like a good test. Probably (get-env :dependencies) would also work (?)

In production build the target path has no meaning and the files need not be present on .jar. Thus add-source should be used instead of add-resource to add the files to fileset.

Are you saying this with CDNs in mind? I think I'd actually prefer to just serve one combined preamble from my domain vs. loading multiple files from Javascript CDNs. Probably there is a way to support both scenarios. Maybe just not run the tasks for production? But then externs would be missing.

from boot-cljsjs.

martinklepsch avatar martinklepsch commented on July 20, 2024

Maybe import-js could just be (combine-preamble :output-to "public/preamble.js)

from boot-cljsjs.

martinklepsch avatar martinklepsch commented on July 20, 2024

[01:41:54] you're probably right about the concatenation, I still don't see an issue with it but it's a separate thing reall
[01:42:12] No issue but no advantage in this case I think

The advantage to me was that no matter how many .inc.js files there are you can just include that one file and it'll contain them. So HTML is same for no optimisations and advanced. Also you can add .inc.js files and they'll be loaded without you needing to add script tags.

from boot-cljsjs.

martinklepsch avatar martinklepsch commented on July 20, 2024

Maybe it'd make sense to put all the helpers to move files from classpath into fileset into one namespace.

from boot-cljsjs.

Deraen avatar Deraen commented on July 20, 2024

Okay, for output there could be at least following options:

  1. Development, :unified-mode true, :optimizations :none
    • Cljs task finds all the .inc.js and .lib.js files and writes shim shile which will load these files -> no need for separate htmls
    • One script tag
    • Classpath should contain all these files because they need to be served to browser separately in dev mode: add-resource
  2. Production, normal cljsbuild, preamble files are concatenaed into the output file which contains the whole application
    • One script tag
    • Classpath only needs to contain the output file because .inc.js & co are already concatenaed onto it
  3. Production, with preamble in different file for CDN
    • Two script tags
    • Like 3. but concatenate task would run before cljs
      • Find all files and concatenate
      • *.inc.js -> some.js which shouldn't be named .inc.js because cljs shouldn't concatenate them into output file
      • *.inc.js files should be removed so cljs doesn't see them
      • *.lib.js should maybe be left untouched. Separating them would require some magic with Closure compiler I think
      • *.ext.js don't need to be touched at all

Case 3. is only where the is multiple script tags required. Perhaps simples way to solve this would be that your app contained an empty file with the same path in development mode, thus you could use the same index.html for both and don't need to do concatenation for development.

from boot-cljsjs.

Deraen avatar Deraen commented on July 20, 2024

And, it might be that cljsjs isn't the proper place to do concatenation at all: If boot-cljs will support shadow-build like modules, it would handle the concatenation into multiple files.

I'm not really familar with shadow-build but I think something like this would work there, and would create one file with external libraries concatenated and other with only the app code:

:modules [{:name :preamble
           :main empty-ns}
          {:name :the-app
           :depends-on #{:preamble}}]

This would also take care of Closure stuff requires for *.lib.js files. If empty-ns did import stuff from Closure libraries, code from those libs would be written to preamble.

from boot-cljsjs.

Deraen avatar Deraen commented on July 20, 2024

Seeing thet e.g. cljsjs react is now packaged as separate jars for development and minified build.

How would user automatically use non-minified for development flow and minified for packaged build? The development and minified react builds differ hugely because minified version eliminates some important debugging stuff.

from boot-cljsjs.

martinklepsch avatar martinklepsch commented on July 20, 2024

Cljs task finds all the .inc.js and .lib.js files and writes shim shile which will load these files -> no need for separate htmls

Is boot-cljs handling shims for inc.js files? I thought boot-cljs dropped any special handling of .inc.js files.

How would user automatically use non-minified for development flow and minified for packaged build?

You'd just set the dependencies in a dev and prod task where you use whatever variant you want.

from boot-cljsjs.

Deraen avatar Deraen commented on July 20, 2024

Yes, the shim written by boot-cljs includes .inc.js files: https://github.com/adzerk/boot-cljs/blob/master/src/adzerk/boot_cljs.clj#L39-L40

from boot-cljsjs.

martinklepsch avatar martinklepsch commented on July 20, 2024

Production, normal cljsbuild, preamble files are concatenaed into the output file which contains the whole application

I somehow think that splitting preamble and application code is the way to go so I probably wouldn't use this. Still if it can be implemented without much pain it's probably a nice-to-have.

And, it might be that cljsjs isn't the proper place to do concatenation at all: If boot-cljs will support shadow-build like modules, it would handle the concatenation into multiple files.

I'm not sure if it's worth thinking about this just yet. I'd like to get cljsjs in a usable and somewhat stable state so people can start using it, so this also means

Tasks

So roughly we end up with these three kinds of tasks:

  1. Packaging tasks to make CLJSJS compatible jars
  2. Import tasks that add files form classpath to files
  3. Concat tasks that combine multiple files into one.

The third one is fairly trivial so while it could be a separate project I don't see an issue of just having the implementation within boot-cljsjs.

Does that sound right to you?

from boot-cljsjs.

Deraen avatar Deraen commented on July 20, 2024

I somehow think that splitting preamble and application code is the way to go so I probably wouldn't use this. Still if it can be implemented without much pain it's probably a nice-to-have.

That is the part that is already working fine, :advanced compilation just cocnatenates any .inc.js files to output file. And I would probably use this :) I dont regularly use CDN's and preamble is usually so small it doesn't matter (especially for intranet stuff) to just download it again whenever the app code changes.

No issue in having concat tasks here, probably good to have most of JS tasks here. They just should be separate tasks and everything would work without using them.

from boot-cljsjs.

martinklepsch avatar martinklepsch commented on July 20, 2024

That is the part that is already working fine

Oh dang. Wasn't aware of that. I somehow thought all handling of inc.js files has been removed from the cljs task.

from boot-cljsjs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.