This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-06-26
Channels
- # babashka (63)
- # beginners (27)
- # calva (17)
- # cider (1)
- # clojure (23)
- # clojure-europe (6)
- # clojure-norway (4)
- # clojurescript (9)
- # cursive (8)
- # data-oriented-programming (9)
- # data-science (7)
- # fulcro (14)
- # graalvm (3)
- # helix (3)
- # introduce-yourself (1)
- # jobs-discuss (7)
- # membrane (40)
- # missionary (4)
- # off-topic (32)
- # pathom (60)
- # react (6)
- # releases (2)
- # shadow-cljs (4)
@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 () {
// CLJS-COMPILED-OUTPUT-HERE
%s
return main;
}));"}
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"}}