Comments (6)
from zbar-wasm.
@iBobik Apologies for my late reply, I have been on vacation. I cannot provide a simple solution to this issue; I can only present my findings, hoping that they are helpful.
CommonJS targets
The CommonJS build of @undecaf/zbar-wasm
(i.e. the WASM/CommonJS glue logic generated by Emscripten) does not allow to detect any dependency on zbar.wasm
(that filename is just an innocuous string literal), so IMHO all CommonJS projects will have to use a copy plugin for zbar.wasm
. Nevertheless, I hope someone can prove me wrong.
Rollup 3
I have not been able to make Rollup bundle zbar.wasm
automatically, no matter which target environment. @rollup/plugin-wasm
did not help either.
Webpack 5
The WASM/ESM glue logic in @undecaf/zbar-wasm
contains the instruction new URL('zbar.wasm', import.meta.url)
which makes Webpack bundle zbar.wasm
as an URL asset whenever it includes the ESM build of @undecaf/zbar-wasm
.
Unfortunately, making Webpack select the ESM build presently requires an resolve.alias
entry which is only a small improvement over a copy plugin. See this gist for example Webpack configurations.
Next steps for zbar-wasm
The export
conditions in package.json
of @undecaf/zbar-wasm
0.9.16 are quite a mess, so I understand that Webpack has to be forced to select the ESM build of zbar-wasm
over the CommonJS build.
But even after setting the export
conditions as documented for Webpack, I was not able to make Webpack select the ESM build of @undecaf/zbar-wasm
when appropriate.
As I am not too familiar with Webpack, any hints would be welcome.
from zbar-wasm.
I don't know if this is helpful for this specific issue, I apologize if it is not. As vite
uses rollup
under the hood, I figured I post a working config for it:
import { defineConfig } from "vite";
import wasm from "vite-plugin-wasm";
export default defineConfig({
plugins: [wasm()],
// config below makes the build work.
optimizeDeps: {
exclude: [
"@undecaf/zbar-wasm"
]
},
});
this works both in dev and prod, where the build puts out wasm
and properly externalizes module
.
vite v4.4.8 building for production...
[plugin:vite:resolve] Module "module" has been externalized for browser compatibility, imported by "<snip>/node_modules/@undecaf/zbar-wasm/dist/main.js". See http://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
✓ 1302 modules transformed.
dist/index.html 0.49 kB │ gzip: 0.32 kB
dist/assets/index-d465abb6.js 17.22 kB
dist/assets/zbar-d779f39f.wasm 239.02 kB
dist/assets/index-b4c9e5df.css 11.99 kB │ gzip: 3.02 kB
dist/assets/__vite-browser-external-b25bb000.js 0.03 kB │ gzip: 0.05 kB
dist/assets/index-dbe8b31c.js 186.93 kB │ gzip: 61.10 kB
✓ built in 1.32s
from zbar-wasm.
Thank you @fspoettel !
@iBobik Plugin @web/rollup-plugin-import-meta-assets
can include zbar.wasm
as an asset in Rollup 3. The module referencing @undecaf/zbar-wasm
must be an ES module, and the plugin needs option warnOnError: true
to be set. I provided a pull request so that this option is no longer needed.
Edit:
The latest version of @web/rollup-plugin-import-meta-assets
(2.0.2) includes the pull request and no longer needs option warnOnError: true
to be set.
from zbar-wasm.
@iBobik zbar-wasm v0.10.0 should resolve this issue.
PTAL at tests/rollup.config.js
which demonstrates several ways of bundling zbar-wasm with Rollup; I hope that one of them is suitable for your situation.
Closing this, please feel free to re-open.
from zbar-wasm.
@undecaf I am looking into it, but found I will probably need you to update also barcode-detector-polyfill.
from zbar-wasm.
Related Issues (13)
- big images cannot be scanned succesfully, in the first attempt. HOT 7
- webpack error migrating from 0.9.15 -> 0.9.16 HOT 5
- The barcode type DataMatrix is not supported HOT 1
- Please Help : Why i show this error when i tray import the package in Angular 16 HOT 1
- Build fails when using in Next.js App directory router. HOT 2
- __dirname is not defined with nextjs HOT 1
- Paused when failed to detect unsupported code type. HOT 2
- zbar-wasm doesn't work with nodejs 18
- TypeError: Failed to construct 'URL': Invalid URL HOT 5
- Issue with utf-8 HOT 13
- after 15 june this package giving an error HOT 2
- loading zbar-wasm as ES module fails in Node HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from zbar-wasm.