Fork me on GitHub
#cljs-dev
<
2019-05-16
>
cfleming04:05:15

I’d like to detect if some JS code is compiled CLJS - can I do that to any degree of reliability? Is the imul fix still prepended to all compiled CLJS?

lilactown04:05:39

I posted a write-up / some questions on the gist. Hope it’s constructive!

thheller07:05:05

@dnolen yes its important to be able to control how something resolves. In shadow-cljs this is done via :resolve config which matches what webpack does. https://shadow-cljs.github.io/docs/UsersGuide.html#js-resolve

dnolen11:05:56

@cfleming only for compiled builds

dnolen11:05:57

@lilactown thanks for the questions I left some answers

thheller12:05:38

FWIW I created a simple example repo using code-splitting which I had difficulty with when trying to use webpack to do the splits https://github.com/thheller/code-splitting-challenge

thheller12:05:47

If someone wants to work through webpack config a bit I'm sure there is an acceptable solution somewhere

dnolen12:05:09

@thheller thanks, very helpful

dnolen12:05:56

@thheller in that scenario you don't say outright here what was wrong

thheller13:05:15

I can't remember the details but the issues where either that webpack would include dependencies multiple times or create extra chunks with little info on how to load them or their dependencies

dnolen12:05:24

react-table & react-select get moved to main in Webpack?

dnolen12:05:45

huh wow I've definitely been out of the Webpack loop - I guess they have Rollup style tree shaking now?

thheller13:05:13

yeah chrome tooling is fantastic

thheller13:05:49

webpack got tree shaking a while ago yes but its fairly limited in the type of packages it supports

thheller13:05:07

some libraries instead came up with their own way to do this ... eg. https://github.com/ant-design/babel-plugin-import

thheller13:05:12

so its a total mess ....

thheller13:05:12

but at least things are starting to get somewhat clearer now that multiple JS bundlers support this construct

thheller13:05:38

I'm a bit concerned that everything is moving towards dynamic import() but the closure compiler folks started work on adding support for that

thheller13:05:56

so I guess we'll see how that all works out

dnolen13:05:03

even libs?

thheller13:05:11

yeah unfortunately

lilactown13:05:01

React is pushing using dynamic imports a lot with React.lazy. I would imagine once there’s prolific support for it that you might even see UI libraries leveraging it

thheller13:05:04

yeah ... some lib on npm already started doing that for react. can't remember the name.

lilactown14:05:58

this is irrelevant to the discussion at hand, but I want to know how BuckleScript / PureScript / Elm et. al. handle mapping their lang’s namespaces to JS modules for tree shake-ability

thheller14:05:28

don't they all just emit ES6?

lilactown14:05:30

I guess Elm has their own thing, but I know BuckleScript expects that you are bundling it yourself. they simply do a source -> source compile

Roman Liutikov14:05:03

afaik Elm is doing DCE before emitting JS

lilactown14:05:27

yeah, I remembered that Elm implements their own whole-app optimizer / bundler

dnolen15:05:38

so folks are doing lazy imports and assuming Webpack will do sensible chunks so you don't just end up with a lot of network requests?

thheller15:05:14

that appears to be the direction they are going with yes

dnolen19:05:48

I just pushed a small change to master, goog.global is now explicitly mapped to Node.js global when compiling Node.js target. Useful when deploying hybrid Webpack / Node.js stuff

thheller19:05:10

actually thats not that simple

thheller19:05:33

goog/base.js already uses goog.global several times when loading

thheller19:05:59

so if you bind it in cljs.core some of the goog defines it does end up on the wrong object

thheller19:05:05

ie. goog.DEBUG

dnolen19:05:12

this is only if COMPILED is true

dnolen19:05:29

goog.DEBUG is a define

dnolen19:05:57

I can't think of scenario where this would matter in Node.js but if you want to enumerate something more specific - I'm all ears

dnolen19:05:19

re: I also had a thought about default w/o futzing around (too much) with the ns form

dnolen19:05:49

Clojure does a thing for inlined classes Foo$Bar, which I kind of adopted for foo$macros

dnolen19:05:01

but actually this seems like a good option for default, foo$default

thheller19:05:24

no clue what you mean. can you provide an actual example?

dnolen19:05:33

hrm, I guess I was thinking about the problems we encountered w/ Closure processing, and import and the need to go through default property for the default export

dnolen19:05:57

is this not a concern with A) Node.js because native ES6 support and B) Webpack handles it

thheller19:05:54

closure processing will rewrite all commonjs to one single .default property yes. but this is not relevant here.

thheller19:05:15

JS packages will still have a default export, and in fact the strict mode webpack will also do the rewrite to .default for commonjs

thheller19:05:19

import {foo, bar} from "./common.js" is not allowed

thheller19:05:38

webpack still accept it I believe unless you are setting strict mode

dnolen19:05:42

@thheller hrm then revisiting what you were saying yesterday about reshaping I guess we don't need reshaping if we consistently support invoking the imported lib as a fn?

dnolen19:05:11

that's the only other annoying case

dnolen19:05:42

actually I guess sometimes people export a ctor?

dnolen19:05:26

but I guess that could be covered by support invoke always and making sure we don't prevent using it as ctor for some reason

thheller19:05:21

people do all kinds of weird stuff

thheller19:05:06

JS for some reason doesn't support combining :as and :refer

thheller19:05:29

so (:require [some-npm-lib :as x :refer (Foo Bar)]) can't be expressed in import

thheller19:05:02

doesn't matter for us as a compile-to-js language but this seems to be leading people down strange roads

thheller19:05:40

where the do import Something from "x"; and then actually having all the names exported on Something so Something.Foo

thheller19:05:02

in actual ESM, not in weird rewritten commonjs

dnolen19:05:02

@thheller so you have import twice? for :as + :refer?

thheller19:05:37

import {foo, bar} from "lib"; and import * as x from "lib"; yes

dnolen19:05:00

import * as x, {foo, bar} from "lib"; is invalid?

thheller19:05:07

yep, not allowed

thheller19:05:01

but * is bad for webpack tree shaking anyways so its use is discouraged anyways

thheller19:05:44

although the article is about dynamic import it applies just as much to static import

thheller19:05:20

the annoying thing is __esModule which is still supported in webpack4 but I believe might be going away in 5

thheller19:05:43

closure compiler folks do not support it at all and treat the files as commonjs