cljsrn

soxley 2021-09-09T00:38:08.188600Z

So, I haven’t been able to figure out how to get this to work still. I tried adding :target :bundle to my build.edn , but that didn’t seem to have an effect. I think part of the issue is that I’m not trying to import something from node_modules. I’m trying to import a JavaScript file from within my project. Relative to my core.cljs file, it’s located at ../../storybook/index.js. In JavaScript, I would import by doing something like import StorybookUIRoot from '../../storybook'. In Clojurescript, I’m not sure how to do that - I’ve tried lots of incantations and none of them worked (most of them I didn’t expect to work):

:require [storybook]
:require [../../storybook :as storybook]
:require [(symbol ../../storybook :as storybook]
(js/require "../../storybook")
Since I haven’t been able to find any documentation about how to require JavaScript that is within my project (and not in node_modules), I’m not sure where the problem lies. I’ll try to narrow it down through experimentation and maybe reading some code to understand how the different pieces are supposed to work.

raspasov 2021-09-09T02:38:06.188700Z

I’ve managed to require my own JavaScript by a creating a local npm module: https://docs.npmjs.com/creating-node-js-modules

👍 1
raspasov 2021-09-09T02:39:21.189100Z

After that, you can require it like any other JS library via package.json

"mylocalmodule": "./npm-local/mylocalmodule",

raspasov 2021-09-09T02:39:38.189300Z

yarn install (that’s required, I think)

raspasov 2021-09-09T02:40:27.189500Z

./npm-local/mylocalmodule is located in the top-level React Native directory of your project

raspasov 2021-09-09T02:40:58.189700Z

npm-local is not a required name, that’s just how I named it

raspasov 2021-09-09T02:43:41.189900Z

After that, from CLJS you should be able to:

(:require [mylocalmodule :as xyz])

soxley 2021-09-09T03:39:46.191900Z

Great idea! I thought of doing something like that with npm link or something but I think I like your idea even better, since it gives me more flexibility where I put my code. I’ll give that a try!

👍 1
thheller 2021-09-09T06:26:53.192300Z

the storybook npm library is the standalone CLI command you are supposed to use for storybook?

thheller 2021-09-09T06:27:07.192500Z

why are you trying to include it in a CLJS build? its not meant to be used as a library

thheller 2021-09-09T06:27:22.192700Z

(unless that has changed since I last looked)

thheller 2021-09-09T06:30:46.192900Z

oh nevermind. its your file not something from storybook

👍 1
soxley 2021-09-09T20:21:57.198500Z

Yes, more specifically it’s the file created by the storybook command:

npx -p @storybook/cli sb init --type react_native

dnolen 2021-09-09T13:02:27.196800Z

@soxley right, you cannot put paths in the ns form in ClojureScript - we could probably support some very restricted pattern - like foo/index.js for local node_module resolution?

dnolen 2021-09-09T13:12:57.198100Z

though ... probably least problematic thing to do and the most minimal change, is just to allow additional paths for node_modules indexing - seems like that would cover this problem

👍 1
gammarray 2021-09-09T21:09:30.200900Z

I’m trying to split my shadow-cljs + expo project into different namespaces for difference platforms, but coming up show on examples/documentation. Curious if and how this can be done?

thheller 2021-09-09T21:10:21.201300Z

whats the problem? you create the ns and then a second build config using that ns?

gammarray 2021-09-09T21:12:09.202700Z

So instead of :react-native as the :target, use :android, :ios, or :web?

thheller 2021-09-09T21:12:51.203500Z

ah you just mean expo target? I thought you meant actually switching the code that gets compiled, not what expo makes out of that

thheller 2021-09-09T21:13:18.204200Z

can't comment on the expo part. shadow-cljs stays with :target :react-native, you just start the expo thing differently I guess

gammarray 2021-09-09T21:15:05.206Z

Hm, maybe I need a dynamic require? The platform comes from the OS function on react-native/Platform

gammarray 2021-09-09T21:15:34.206700Z

I need to require based on platform

thheller 2021-09-09T21:16:01.207200Z

no, flip it. you build based on the target platform. and whatever you build directly requires that it needs

thheller 2021-09-09T21:16:22.207700Z

so you create a your.app.web your.app.android and/or your.app.ios namespace for each

thheller 2021-09-09T21:16:56.208500Z

and require whatever you need from there? each with its own build

thheller 2021-09-09T21:17:43.209Z

at least thats the theory. dunno how all that works combined with expo

gammarray 2021-09-09T21:19:44.209800Z

ok thanks! I'll give that a try

gammarray 2021-09-09T21:32:38.210200Z

this thread has relevant details: https://github.com/thheller/shadow-cljs/issues/651