10000 perf(npm): reduce bundle size (#9) · homebaseio/homebase-react@ea3316e · GitHub
[go: up one dir, main page]

Skip to content

Commit ea3316e

Browse files
perf(npm): reduce bundle size (#9)
- reduce bundle by compiling with release flag and fixing advanced compilation errors - organize npm build code - test release build in CI - add .npmingnore
1 parent 5c79b0f commit ea3316e

File tree

10 files changed

+92
-46
lines changed

10 files changed

+92
-46
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ jobs:
4646

4747
- run: yarn install --frozen-lockfile
4848

49-
- run: yarn shadow-cljs compile npm-dist
49+
- run: yarn shadow-cljs release npm
5050
- run: yarn shadow-cljs compile test
5151

5252
- run: node out/node-tests.js

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ dist/
99
/src/js_gen/tests
1010

1111
package-lock.json
12+
report.html
1213
pom.xml
1314
pom.xml.asc
1415
*.iml

.npmignore

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
node_modules/
2+
public/js
3+
out/
4+
5+
/target
6+
/checkouts
7+
/src/gen
8+
/src/js_gen/tests
9+
10+
package-lock.json
11+
report.html
12+
pom.xml
13+
pom.xml.asc
14+
*.iml
15+
*.jar
16+
*.log
17+
*.orig
18+
.shadow-cljs
19+
.idea
20+
.lein-*
21+
.nrepl-*
22+
.DS_Store
23+
.calva
24+
25+
.hgignore
26+
.hg/

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
## v0.0.1
2+
- React component to provide a declarative relational DB with minimal fuss.
3+
- React hooks for transact, query and find one entity.
4+
- Make Datascript's syntax more JS and React friendly.

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# Homebase React
22

33
[![CI](https://github.com/homebaseio/homebase-react/workflows/CI/badge.svg)](https://github.com/homebaseio/homebase-react/actions?query=workflow%3ACI)
4-
[![NPM Version](https://badge.fury.io/js/homebase-react.svg)](https://badge.fury.io/js/homebase-react)
4+
[![NPM Version](https://img.shields.io/npm/v/homebase-react)](https://www.npmjs.com/package/homebase-react)
5+
[![Bundle Size](https://img.shields.io/bundlephobia/minzip/homebase-react)](https://www.npmjs.com/package/homebase-react)
56
[![License](https://img.shields.io/github/license/homebaseio/homebase-react.svg)](LICENSE)
67

7-
8-
> The graph database for delightful React state management
8+
*The graph database for delightful React state management*
99

1010
## Installation
1111

@@ -154,7 +154,7 @@ todos
154154

155155
```bash
156156
yarn install
157-
yarn shadow-cljs watch :dev
157+
yarn dev
158158
```
159159

160160
Open http://localhost:3000

js/tests/benchmarks.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import React from 'react';
33
import Enzyme, { mount } from 'enzyme';
44
import Benchmark from 'react-component-benchmark';
55
import Adapter from "enzyme-adapter-react-16";
6-
import { HomebaseProvider, useTransact, useEntity } from '../../dist/homebase.react';
6+
import { HomebaseProvider, useTransact, useEntity } from '../../dist/js/homebase.react';
77

88
const config = {
99
initialData: [{

package.json

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,21 @@
44
"version": "0.0.1",
55
"license": "MIT",
66
"homepage": "https://github.com/homebaseio/homebase-react",
7-
"repository": {
8-
"type": "git",
9-
"url": "git+https://github.com/homebaseio/homebase-react.git"
7+
"main": "./dist/js/homebase.react.js",
8+
"scripts": {
9+
"dev": "shadow-cljs watch dev",
10+
"build": "rm -rf dist && shadow-cljs release npm",
11+
"build:dev": "rm -rf dist && shadow-cljs compile npm",
12+
"test:js": "yarn build && jest js/tests",
13+
"test:js:dev": "yarn build:dev && jest js/tests",
14+
"test:cljs": "shadow-cljs compile test && node out/node-tests.js",
15+
"test": "yarn test:cljs && yarn test:js",
16+
"test:dev": "yarn test:cljs && yarn test:js:dev",
17+
"report": "rm -rf dist && shadow-cljs run shadow.cljs.build-report npm report.html"
18+
},
19+
"dependencies": {
20+
"react": "16.14.0"
1021
},
11-
"keywords": [
12-
"react",
13-
"database",
14-
"datalog",
15-
"state",
16-
"graph"
17-
],
18-
"main": "./dist/homebase.react.js",
1922
"devDependencies": {
2023
"@babel/cli": "7.11.6",
2124
"@babel/core": "7.11.6",
@@ -28,19 +31,30 @@
2831
"highlight.js": "10.2.1",
2932
"jest": "26.6.0",
3033
"marked": "1.2.0",
31-
"react": "16.14.0",
3234
"react-component-benchmark": "0.0.4",
3335
"react-dom": "16.14.0",
3436
"shadow-cljs": "2.11.4"
3537
},
36-
"dependencies": {},
38+
"keywords": [
39+
"react",
40+
"relational",
41+
"database",
42+
"datalog",
43+
"state",
44+
"graph"
45+
],
46+
"repository": {
47+
"type": "git",
48+
"url": "git+https://github.com/homebaseio/homebase-react.git"
49+
},
3750
"bugs": {
3851
"url": "https://github.com/homebaseio/homebase-react/issues"
3952
},
40-
"scripts": {
41-
"test-js": "shadow-cljs compile npm-dist && jest js/tests",
42-
"test-cljs": "shadow-cljs compile test && node out/node-tests.js",
43-
"test": "yarn test-cljs && yarn test-js"
53+
"publishConfig": {
54+
"registry": "https://npm.pkg.github.com/"
4455
},
45-
"author": ""
56+
"author": "Chris Smothers <chris@homebase.io> (https://homebase.io)",
57+
"contributors": [
58+
"JB Rubinovitz <jb@homebase.io> (https://homebase.io)"
59+
]
4660
}

shadow-cljs.edn

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323
:output-to "out/node-tests.js"
2424
:ns-regexp "-test$"
2525
:autorun false}
26-
:npm-dist {:target :npm-module
27-
:output-dir "dist"
28-
:output-to "dist/lib.js"
29-
:entries [homebase.react]
30-
:compiler-options {:optimizations :advanced
31-
:source-map false}}}}
26+
:npm {:target :npm-module
27+
:output-dir "dist/js"
28+
:entries [homebase.react]
29+
:compiler-options {:optimizations :advanced
30+
:output-wrapper false
31+
:source-map false}}}}

src/homebase/js.cljs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@
169169

170170

171171
(defn humanize-transact-error [error]
172-
(condp re-find (.-message error)
172+
(condp re-find (goog.object/get error "message")
173173
#"\[object Object\] is not ISeqable"
174174
"Expected an array of transactions.
175175
\nFor example: transact([
@@ -192,7 +192,7 @@
192192
"Expected a numerical id.
193193
\nFor example: transact([['retractEntity', 123]])
194194
"
195-
(.-message error)))
195+
(goog.object/get error "message")))
196196

197197
(defn transact! [conn txs]
198198
(try
@@ -202,12 +202,12 @@
202202

203203

204204
(defn humanize-entity-error [error]
205-
(condp re-find (.-message error)
205+
(condp re-find (goog.object/get error "message")
206206
#"Lookup ref attribute should be marked as :db/unique: \[:([\w-]+)/([\w-]+) ((?!\]).+)\]"
207207
:>> (fn [[_ nmspc attr v]]
208208
(str "The `" nmspc "." attr "` attribute should be marked as unique if you want to lookup entities by it."
209209
"\n\nAdd this to your config: { schema: { " nmspc ": { " attr ": { unique: 'identity' }}}\n"))
210-
(.-message error)))
210+
(goog.object/get error "message")))
211211

212212
(defn entity [conn lookup]
213213
(try
@@ -226,7 +226,7 @@ For example: query({
226226
")))
227227

228228
(defn humanize-q-error [error]
229-
(condp re-find (.-message error)
229+
(condp re-find (goog.object/get error "message")
230230
#"Query should be a vector or a map"
231231
(str "Expected query to be in the form of an object or datalog string."
232232
(example-js-query))
@@ -245,7 +245,7 @@ For example: query({
245245
:>> (fn [[_ v]]
246246
(str "Expected $where clause to be a nested object, not " v "."
247247
(example-js-query)))
248-
(.-message error)))
248+
(goog.object/get error "message")))
249249

250250
(defn q [query conn & args]
251251
(try

src/homebase/react.cljs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,27 @@
1010
(catch js/Error e
1111
(throw
1212
(js/Error
13-
(str (.-message e) "\n"
14-
(some->> (.-stack e)
13+
(str (goog.object/get e "message") "\n"
14+
(some->> (goog.object/get e "stack")
1515
(re-find (re-pattern (str hook-name ".*\\n(.*)\\n?")))
1616
(second)
1717
(clojure.string/trim))))))))
1818

19-
(defonce homebase-context (react/createContext))
19+
(defonce ^:export homebase-context (react/createContext))
2020

2121
(def base-schema
2222
{:db/ident {:db/unique :db.unique/identity}})
2323

2424
(defn ^:export HomebaseProvider [props]
25-
(let [config (.-config props)
26-
conn (d/create-conn (if (.-schema config)
27-
(merge (hbjs/js->schema (.-schema config)) base-schema)
25+
(let [conn (d/create-conn (if-let [schema (goog.object/getValueByKeys props #js ["config" "schema"])]
26+
(merge (hbjs/js->schema schema) base-schema)
2827
base-schema))]
29-
(when (.-initialData config) (hbjs/transact! conn (.-initialData config)))
28+
(when-let [tx (goog.object/getValueByKeys props #js ["config" "initialData"])]
29+
(hbjs/transact! conn tx))
3030
(react/createElement
31-
(.-Provider homebase-context) #js {:value conn}
32-
(.-children props))))
31+
(goog.object/get homebase-context "Provider")
32+
#js {:value conn}
33+
(goog.object/get props "children"))))
3334

3435
(defn ^:export useEntity [lookup]
3536
(let [conn (react/useContext homebase-context)
@@ -58,4 +59,4 @@
5859
(defn ^:export useTransact []
5960
(let [conn (react/useContext homebase-context)
6061
transact (fn transact [txs] (try-hook "useTransact" #(hbjs/transact! conn txs)))]
61-
[transact]))
62+
[transact]))

0 commit comments

Comments
 (0)
0