GithubHelp home page GithubHelp logo

shadow-cljs-with-react-native-note's Introduction

Use shadow-cljs with React Native

Brief

Thanks to @thheller (author of shadow-cljs), just got it to work with React Native. Comparing to re-natal or expo-cljs-template, we now can use the built-in HMR. It’s faster and don’t need heavy shim work. e.g. figwheel-bridge.js. Also we have a REPL :)

Source map seems still not work.

Followings is the steps to make they work. Currently, this is not a good solution, the steps are complex. But if all this work can be done with shadow-cljs automatically, that will be awesome.

How

Install react-native command-line tools with npm i -g react-native-cli.

Install shadow-cljs command-line tools with npm i -g shadow-cljs.

create the project with react-native init Hello.

cd Hello.

Initialize a shadow-cljs config file with shadow-cljs init.

edit shadow-cljs.edn.

{:source-paths
 ["src"]

 :dependencies
 []

 :builds
 {:app {:target :npm-module
        :output-dir "js/"
        :runtime :browser
        :devtools {:devtools-url "http://<host-ip>:9630"}}}}  ;; This will let client connect our machine, so that we can have a repl.

create a cljs file, src/hello/core.cljs.

(ns hello.core)

(defn foo []
  (js/alert "Hello from CLJS!"))

start repl client in index.cljs.

import './js/shadow.cljs.devtools.client.browser';

Using foo will like this:

import { foo } from './js/hello.core';

foo();

Start shadow-cljs, I use shadow-cljs clj-repl. Then we can start the build:

shadow.user => (shadow/watch :app)
shadow.user => (shadow/repl :app)

react-native run-ios!

At end, after client loaded, you will see an error for document is not defined. since shadow-cljs support A good way to hack, we can fix like this:

mkdir -p src/shadow/cljs/devtools/client

wget https://github.com/thheller/shadow-cljs/blob/master/src/main/shadow/cljs/devtools/client/browser.cljs src/shadow/cljs/devtools/client/browser.cljs

we edit this file, modify script-eval function to

(defn script-eval
  [code])

Now you try on REPL and HMR.

shadow-cljs-with-react-native-note's People

Contributors

doglooksgood avatar

Stargazers

 avatar Dima Novotochinov avatar Darong Mean avatar Brian Dunn avatar c4605 avatar yāλu avatar

Watchers

Brian Dunn avatar James Cloos avatar  avatar

Forkers

clojure-land

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.