Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Supporting :module-type compiler option #29

Closed
shaunlebron opened this issue Jan 23, 2016 · 10 comments
Closed

Supporting :module-type compiler option #29

shaunlebron opened this issue Jan 23, 2016 · 10 comments
Assignees

Comments

@shaunlebron
Copy link

I think it would be ideal to replace this (which doesn't even work on Node):

(ns example.core
  (:require cljsjs.foo))

;; how to use in the Browser
(def foo js/foo)

;; how to use in Node (can't?)
(def foo (js/require "????"))  ;; content is unnamed somewhere in our compiled code

with this, by allowing an option {:module-type :common-js}:

(ns example.core
  (:require [cljs.foo :as foo])) ;; works in Browser and Node

This option enables us to have the Closure compiler transform the library into a Closure module, rather than just pasting the library into the compiled output. Pending a future patch for a bug found in this process, I think supporting this new module-type option would be nice.

Background references:

@martinklepsch
Copy link
Member

@shaunlebron this sounds great, I assume this doesn't have any impact on externs (i.e. they're still required)?

@plexus
Copy link

plexus commented Sep 15, 2016

Externs are no longer required in this case. The CommonJS/AMD/ES2015 module gets converted into a Google Closure Compiler module and can be consumed as such.

@Deraen
Copy link
Member

Deraen commented Sep 15, 2016

Blocked by: http://dev.clojure.org/jira/browse/CLJS-1762 and probably other bugs will be found once Closure compiler has been updated.

Currently module-type support is not good for other than very simple tests cases. For example npm modules can't be used.

@Deraen Deraen self-assigned this Sep 15, 2016
@kommen
Copy link

kommen commented Mar 16, 2017

Now that there's :module-type support in ClojureScript since 1.9.454 (https://clojurescript.org/reference/javascript-module-support) would the be interest to support this option in cljsjs?

@Deraen
Copy link
Member

Deraen commented Mar 16, 2017

Closure/ClojureScript doesn't currently support Node module resolution in classpath (e.g. Cljsjs JARs). Either files would need to be copied to filesystem in Cljs compiler, or something (Cljs, Cljsjs) should provide Closure node module resolution implementation which works with classpath.

@kommen
Copy link

kommen commented Mar 16, 2017

I see, thanks.

@burn2delete
Copy link

Does the :npm-deps option solve this now?

@Deraen
Copy link
Member

Deraen commented Mar 19, 2017

It doesn't solve this, it works around this.

I'd still prefer solution which doesn't involve calling npm and instead packages the files to JARs.

@Deraen
Copy link
Member

Deraen commented Mar 19, 2017

Also, when using :npm-deps, it doesn't make much sense to provide those in packages, it is easy for user to declare :npm-deps in the project. But for this use case we could provide separate externs packages.

@Deraen
Copy link
Member

Deraen commented Dec 12, 2017

I don't think there is anything to do related to Cljsjs here. Deps.cljs can be generated with :module-type entries, but I think ClojureScript compiler and Closure only work if those files are available in filesystem, not classpath. This will need to be fixed elsewhere.

@Deraen Deraen closed this as completed Dec 12, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants