Skip to content

Enhanced JavaScript Module Support

David Nolen edited this page Sep 10, 2015 · 10 revisions

Problems

There are many JavaScript module formats in the wild. The variety of formats present challenges for ClojureScript consumption as ClojureScript is designed to work with the Google Closure Compiler. Maria Geller's Google Summer of Code work addressesed fundamental support issues by patching the Closure Compiler as well the ClojureScript compiler. This work allows JavaScript module formats to be processed much like the way we process ClojureScript - into Google Closure namespaces. However challenges remain with respect to intuitive usage for the end user. These are some of the issues present today:

  • :module-type cannot be applied to :libs
  • :libs only supports files or directories, not library specs (maps)
  • :language-in & :language-out cannot be specified at module level
  • missing source mapping support

This page outlines some approaches to potential solutions.

Solution(s)

Support :language-in and :language-out in :libs and :foreign-libs

{:foreign-libs [{:file "./path/to/my/foo.js"
                 :provides ["my.foo"]
                 :language-in :ecmascript6
                 :language-out :ecmascript5}]}

Support specs in :libs

We could support library specs in :libs instead of only supporting a vector strings specifying files (individual files or directories):

{:libs ["./path/to/my/closure/libs",
        {:path "./node_modules/react/src"
         :module-type :commonjs
         :language-in :ecmascript5
         :preprocess :jsx}]}

Unlike :foreign-libs, :libs entries provide dependency information in the source file. This is true for any JavaScript using a popular module format that we support. This means that we can support directory "entry points" and simply compile all JavaScript files under the given directory using the provided options.

As with existing :libs support we can simply compile to :output-to preserving the directory structure. This would avoid the file name clash issues.

Source Mapping Support

This is a nice follow up to have. We have existing support for merging source maps, we should simply do the same for all :libs.

Clone this wiki locally