FrigadeHQ / remote-storage

remoteStorage is a simple library that combines the localStorage API with a remote server to persist data across sessions, devices, and browsers. It works as a simple key value database store and backend with support for React, Next.js, Vue, Node, or any Javascript stack
https://remote.storage
MIT License
1.21k stars 27 forks source link

Is it possible to use this in the browser? #13

Closed jaquer closed 5 months ago

jaquer commented 8 months ago

Is it possible to use this library in the browser? I'm too much of a JS/node newbie to figure it out.

What I've tried:


1) Using skypack.dev, which according to their site:

operates like your favorite CDN but with an important difference: packages are preoptimized for browser use.

<script type="module">
  import { RemoteStorage } from "https://cdn.skypack.dev/remote-storage"
</script>

I get Uncaught ReferenceError: RemoteStorage is not defined in the browser console.


2) Using https://browserify.org/ with any of these versions of main.js

var RemoteStorage = require('remote-storage');
var RemoteStorage = require('remote-storage');
global.window.RemoteStorage = RemoteStorage;
var RemoteStorage = require('remote-storage').RemoteStorage;
global.window.RemoteStorage = RemoteStorage;

I get this error:

$ browserify main.js -o bundle.js
ParseError: 'import' and 'export' may appear only with 'sourceType: module'

Like I said, not too experienced with the stack. Any help is greatly appreciated.

christianmat commented 8 months ago

The issue is that the npm dependencies will not get injected when using this approach. I can make a minified version that has the dependencies baked in. Stay tuned!

christianmat commented 5 months ago

Hey @jaquer this is now resolved. Simply add this to your browser-based app:

<script src="https://unpkg.com/remote-storage@latest/dist/remote-storage.min.js" sync></script>
jaquer commented 5 months ago

Awesome. Thank you!