JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 7
  • Score
    100M100P100Q54584F
  • License ISC

JS libraries for KMP

Package Exports

  • @devs-studio/kmp-js
  • @devs-studio/kmp-js/dist/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@devs-studio/kmp-js) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

This page is based on [SQL.js Web Worker]: https://sqldelight.github.io/sqldelight/2.0.2/js_sqlite/sqljs_worker/. Follow the instructions in that page before do this.

SQL.js Web Worker

To include the SQL.js worker in your project, first add a dependency on the worker package along with a dependency on SQL.js.

kotlin {
  sourceSets.jsMain.dependencies {
    implementation(npm("@devs-studio/kmp-js", "1.0.0"))
    implementation(npm("sql.js", "1.8.0"))
  }
}

The SQL.js package includes a WebAssembly binary that must be copied into your application's output. In your project, add an additional Webpack configuration file to configure the copying of the binary to your assembled project.

// {project}/webpack.config.d/sqljs.js
config.resolve = {
    fallback: {
        fs: false,
        path: false,
        crypto: false,
    }
};

const CopyWebpackPlugin = require('copy-webpack-plugin');
config.plugins.push(
    new CopyWebpackPlugin({
        patterns: [
            '../../node_modules/sql.js/dist/sql-wasm.wasm'
        ]
    })
);

Using the Worker

The worker script is called sqljs-custom.worker.js and can be referenced in code like this:

val driver = WebWorkerDriver(
  Worker(
    js("""new URL("@devs-studio/kmp-js/dist/sqldelight/sqljs-custom.worker.js", import.meta.url)""")
  )
)

See "Using a Web Worker" for more details.