Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use object api #6

Open
milahu opened this issue Nov 12, 2021 · 5 comments
Open

use object api #6

milahu opened this issue Nov 12, 2021 · 5 comments
Labels
enhancement New feature or request

Comments

@milahu
Copy link

milahu commented Nov 12, 2021

actual

// vite.config.js

import wasmPack from 'vite-plugin-wasm-pack';

  // only use local crate
  plugins: [
    wasmPack(['./my-local-crate']),
  ],

  // only use npm crate, leave the first param to an empty array
  plugins: [
    wasmPack([], ['test-npm-crate']),
  ],

  // use both local and npm crate
  plugins: [
    wasmPack(['./my-local-crate'], ['test-npm-crate']),
  ],

expected

// vite.config.js

import wasmPack from 'vite-plugin-wasm-pack';

  // only use local crate
  plugins: [
    wasmPack({ local: ['./my-local-crate'] }),
  ],

  // only use npm crate
  plugins: [
    wasmPack({ npm: ['test-npm-crate'] }),
  ],

  // use both local and npm crate
  plugins: [
    wasmPack({ local: ['./my-local-crate'], npm: ['test-npm-crate'] }),
  ],
// index.d.ts

//import type { Plugin } from 'vite';
type Plugin = any;

export default function vitePluginWasmPack(options: {
  local?: string[],
  npm?: string[],
}): Plugin;
@nshen
Copy link
Owner

nshen commented Nov 12, 2021

hi, @milahu

looks great, would you like to create a pull request?

@milahu
Copy link
Author

milahu commented Nov 12, 2021

nope sorry : /

im only using vite-plugin-wasm-pack
as a base for my vite-plugin-emscripten / vite-plugin-treesitter

the api could be even simpler, for example ...
this would make it easier to generalize the code for multiple wasm compilers

// vite.config.js

import wasmPack from 'vite-plugin-wasm-pack';

  // use both local and npm crate
  plugins: [
    wasmPack(
      // list of packages
      [
        './my-local-crate', // local paths start with ./
        'test-npm-crate',
        '@org/pkg',
        { path: './a/b/c', type: 'emscripten', src: /\.(c|cc|cpp)$/ }, // local options for one packages
        { path: 'another-npm-package', type: 'makefile' },
      ],
      // global options for all packages
      {
        globalOption1: '...',
        globalOption2: '...',
      }
    ),
  ],

the resolveId(id) seems to be a noop, since all my ids start with /node_modules/
so that (path.basename(localPathList[i]) === id) is always false

@milahu
Copy link
Author

milahu commented Nov 12, 2021

im only using vite-plugin-wasm-pack
as a base for my vite-plugin-emscripten / vite-plugin-treesitter

https://github.com/milahu/vite-plugin-tree-sitter/blob/master/index.js

@nshen nshen added the enhancement New feature or request label Nov 27, 2021
@alensiljak
Copy link

I'm trying to use this plugin to see if it resolves using wasm-pack-ed packages with Quasar.
Unfortunately, Quasar only supports passing the parameters in object notation: https://quasar.dev/quasar-cli-vite/handling-vite#adding-vite-plugins

Solving this issue would also allow using the plugin with the Quasar framework.

The suggestion seems to me like a breaking change, though. Would that be ok?

@alensiljak
Copy link

I tried it here: https://github.com/alensiljak/vite-plugin-wasm-pack/tree/object-params
but something is wrong with the expected parameters. I'm passing the package name, as listed in package.json. There, it points to the local folder.
Will have to continue this at another time, unfortunately.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants