|
| 1 | +# Importing TinyBase |
| 2 | + |
| 3 | +This guide provides a quick aside about importing TinyBase into your |
| 4 | +application. |
| 5 | + |
| 6 | +## Targets and formats |
| 7 | + |
| 8 | +The overall package includes a number of different versions of TinyBase, |
| 9 | +transpiled for different targets and formats. You'll find them all in the |
| 10 | +`./lib` folder of the package, and you can directly import them as follows: |
| 11 | + |
| 12 | +| Directory | Target | Format | Minified | Import | |
| 13 | +| ----------- | ------ | ------ | -------- | ------------------------------------ | |
| 14 | +| lib | esnext | esm | yes | `import {...} from tinybase` | |
| 15 | +| lib/debug | esnext | esm | no | `import {...} from tinybase/debug` | |
| 16 | +| lib/umd | esnext | umd | yes | `import {...} from tinybase/umd` | |
| 17 | +| lib/cjs | esnext | cjs | yes | `import {...} from tinybase/cjs` | |
| 18 | +| lib/es6 | es6 | esm | yes | `import {...} from tinybase/es6` | |
| 19 | +| lib/umd-es6 | es6 | umd | yes | `import {...} from tinybase/umd-es6` | |
| 20 | +| lib/cjs-es6 | es6 | cjs | yes | `import {...} from tinybase/cjs-es6` | |
| 21 | + |
| 22 | +## Using TinyBase submodules |
| 23 | + |
| 24 | +The tinybase module is the master package of all the functionality together |
| 25 | +(except the ui-react module and tools module, which always remain standalone |
| 26 | +options). Since many of the submodules share compiled-in dependencies, the |
| 27 | +master package is smaller to include than including all of the submodules |
| 28 | +separately. |
| 29 | + |
| 30 | +However, for a very minimal set of submodules, you may save size by including |
| 31 | +them piecemeal. If you only wanted a Store and a Metrics object, for example, |
| 32 | +you could import them alone like this: |
| 33 | + |
| 34 | +```js yolo |
| 35 | +import {createStore} from 'tinybase/store'; |
| 36 | +import {createMetrics} from 'tinybase/metrics'; |
| 37 | +// ... |
| 38 | +``` |
| 39 | + |
| 40 | +You can also import single packages in other targets and formats. For example: |
| 41 | + |
| 42 | +```js yolo |
| 43 | +import {createStore} from 'tinybase/es6/store'; |
| 44 | +import {createMetrics} from 'tinybase/es6/metrics'; |
| 45 | +import {useCell} from 'tinybase/es6/ui-react'; |
| 46 | +// ... |
| 47 | +``` |
| 48 | + |
| 49 | +## React Native |
| 50 | + |
| 51 | +If you are using [React Native](https://reactnative.dev/) - for example with |
| 52 | +[Expo](https://expo.dev/) - be aware that the |
| 53 | +[Metro](https://facebook.github.io/metro/) bundler does not currently support |
| 54 | +module resolution very well. You may have to add in the `lib` portion of the |
| 55 | +path to be explicit about your imports: |
| 56 | + |
| 57 | +```js yolo |
| 58 | +import {createStore} from 'tinybase/lib'; |
| 59 | +import {useCell} from 'tinybase/lib/ui-react'; |
| 60 | +``` |
| 61 | + |
| 62 | +OK, enough with the `import` shenanigans. Next we will show how you can quickly |
| 63 | +build user interfaces on top of a Store, and for that, it's time to proceed to |
| 64 | +the Building UIs guide. |
0 commit comments