Fork me on GitHub
#cljsrn
<
2021-09-09
>
soxley00:09:08

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.

raspasov02:09:06

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

👍 2
raspasov02:09:21

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

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

raspasov02:09:38

yarn install (that’s required, I think)

raspasov02:09:27

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

raspasov02:09:58

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

raspasov02:09:41

After that, from CLJS you should be able to:

(:require [mylocalmodule :as xyz])

soxley03:09:46

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!

👍 2
thheller06:09:53

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

thheller06:09:07

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

thheller06:09:22

(unless that has changed since I last looked)

thheller06:09:46

oh nevermind. its your file not something from storybook

👍 2
soxley20:09:57

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

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

dnolen13:09:27

@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?

dnolen13:09:57

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

👍 2
gammarray21:09:30

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?

thheller21:09:21

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

gammarray21:09:09

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

thheller21:09:51

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

thheller21:09:18

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

gammarray21:09:05

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

gammarray21:09:34

I need to require based on platform

thheller21:09:01

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

thheller21:09:22

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

thheller21:09:56

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

thheller21:09:43

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

gammarray21:09:44

ok thanks! I'll give that a try