ericblade / quagga2

An advanced barcode-scanner written in Javascript and TypeScript - Continuation from https://github.com/serratus/quaggajs
MIT License
758 stars 85 forks source link

import types from the library without including it in the webpack builder #421

Closed SDAdham closed 2 years ago

SDAdham commented 2 years ago

Hi team,

I changed the following line from:

import Quagga, { QuaggaJSResultObject } from '@ericblade/quagga2';

to:

import { QuaggaJSResultObject, QuaggaJSStatic } from '@ericblade/quagga2/type-definitions/quagga';

to avoid including it in the build, however it's still be included, not sure how can I avoid including it? image

The reason behind doing this is because I dynamically import it separately rather bundling it within the vendor.js to reduce initial loading time and improve the apps performance.

Can you please help?

github-actions[bot] commented 2 years ago

Thank you for filing an issue! Please be patient. :-)

ericblade commented 2 years ago

Hi! If you're using TypeScript, recent versions add a "import type" capability

import { type QuaggaJSResultObject, type QuaggaJSStatic } from ...

which would allow you to reference it, and it would be stripped when TSC is done with it.

Otherwise, it sounds like some advanced webpack configuration that I'm afraid I know extremely little about.

SDAdham commented 2 years ago

Thanks @ericblade! I did that but it would be there still, so I knew I had to look somewhere else till I learned that I am using https://www.npmjs.com/package/ngx-barcode-scanner which adds it. Moving it's import to the right place helped me solving the problem.

Many thanks! Issue solved.

ericblade commented 2 years ago

great to hear!