Fork me on GitHub

@zane, I tangled with this for a while, this is the compiler config that worked:

{:target        :nodejs
 :output-to     "out/nodejs/package/my-package.js"
 :output-dir    "out/nodejs/build"
 :main          main
 :optimizations :simple
 :pretty-print  false
 :install-deps  true
 :npm-deps      {}
 :hashbang      false
 :output-wrapper "(function (root, factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define([], factory);
} else if (typeof module === 'object' && module.exports) {
// Node. Does not work with strict CommonJS, but
// only CommonJS-like environments that support module.exports,
// like Node.
module.exports = factory();
} else {
// Browser globals (root is window)
root.returnExports = factory();
}(this, function () {


return main;


That gives you a UMD module that works in Node


I spent a decent amount of time trying to get :target :bundle to work, but I gave up and went with this in the end.


Thanks so much! I wound up going the same route in the end, but there are some subtleties to your implementation that I'm going to borrow.


This has forced me to understand AMD modules and the Google Closure Compiler a lot better, and my current read is that it's actually not possible for :target :bundle to build AMD modules in conjunction with Webpack without a huge amount of work on the Webpack internals.


When building for the browser we use a separate config that does use :target :bundle

{:output-to          "out/browser/index.js"
 :output-dir         "out/browser"
 :target             :bundle
 :main               main
 :optimizations      :advanced
 :optimize-constants false
 :pretty-print       false
 :pseudo-names       false
 :infer-externs      true
 :install-deps       true
 :npm-deps           {}
 :bundle-cmd         {:none    ["npx" "webpack" "--config" "./webpack.browser.config.js" "--mode=development"]
                      :default ["npx" "webpack" "--config" "./webpack.browser.config.js"]}
 :closure-defines    {cljs.core/*global* "window"}}


This approach may be overkill, we build a separate node, browser, and clojure package from the same source code.


Hi. It seems there is no resolving-require in cljs yet?


there never will be. well, rather unlikely given that regular builds don't have the compiler available and all IO is async.