项目作者: wasm-tool

项目描述 :
webpack plugin for Rust
高级语言: JavaScript
项目地址: git://github.com/wasm-tool/wasm-pack-plugin.git
创建时间: 2018-07-28T14:39:05Z
项目社区:https://github.com/wasm-tool/wasm-pack-plugin

开源协议:MIT License

下载


@wasm-tool/wasm-pack-plugin

webpack plugin for Rust

Installation

With npm:

  1. npm install --save-dev @wasm-tool/wasm-pack-plugin

Or with Yarn:

  1. yarn add --dev @wasm-tool/wasm-pack-plugin

wasm-pack

We expect wasm-pack to be in your $PATH. See installation here.

The minimum required wasm-pack version is 0.8.0

Linting

This project uses the prettier with default configuration. Fo manually format the code run the lint:fix script.

Usage

Add the loader in your webpack.config.js:

  1. const path = require('path')
  2. const WasmPackPlugin = require('@wasm-tool/wasm-pack-plugin')
  3. module.exports = {
  4. // ...
  5. plugins: [
  6. new WasmPackPlugin({
  7. crateDirectory: path.resolve(__dirname, 'crate'),
  8. // Check https://rustwasm.github.io/wasm-pack/book/commands/build.html for
  9. // the available set of arguments.
  10. //
  11. // Optional space delimited arguments to appear before the wasm-pack
  12. // command. Default arguments are `--verbose`.
  13. args: '--log-level warn',
  14. // Default arguments are `--typescript --target browser --mode normal`.
  15. extraArgs: '--no-typescript',
  16. // Optional array of absolute paths to directories, changes to which
  17. // will trigger the build.
  18. // watchDirectories: [
  19. // path.resolve(__dirname, "another-crate/src")
  20. // ],
  21. // The same as the `--out-dir` option for `wasm-pack`
  22. // outDir: "pkg",
  23. // The same as the `--out-name` option for `wasm-pack`
  24. // outName: "index",
  25. // If defined, `forceWatch` will force activate/deactivate watch mode for
  26. // `.rs` files.
  27. //
  28. // The default (not set) aligns watch mode for `.rs` files to Webpack's
  29. // watch mode.
  30. // forceWatch: true,
  31. // If defined, `forceMode` will force the compilation mode for `wasm-pack`
  32. //
  33. // Possible values are `development` and `production`.
  34. //
  35. // the mode `development` makes `wasm-pack` build in `debug` mode.
  36. // the mode `production` makes `wasm-pack` build in `release` mode.
  37. // forceMode: "development",
  38. // Controls plugin output verbosity, either 'info' or 'error'.
  39. // Defaults to 'info'.
  40. // pluginLogLevel: 'info'
  41. }),
  42. ],
  43. // ...
  44. }

and then import your pkg folder from wasm-pack:

  1. import('./path/to/your/pkg').then((module) => {
  2. module.run()
  3. })