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

Importing a single codec when using a browser build #9

Closed
jbms opened this issue Jun 25, 2020 · 2 comments · Fixed by #11
Closed

Importing a single codec when using a browser build #9

jbms opened this issue Jun 25, 2020 · 2 comments · Fixed by #11

Comments

@jbms
Copy link

jbms commented Jun 25, 2020

From node.js it is possible to import just a single codec, but this does not seem to work from a browser-targeted build using typescript/webpack. Typescript gives the error:

import {Blosc} from 'numcodecs/blosc';
Cannot find module 'numcodecs/blosc' or its corresponding type declarations.

Using

import {Blosc} from 'numcodecs';

works but also pulls in pako, which increases the bundle size a fair bit.

@manzt
Copy link
Owner

manzt commented Jun 25, 2020

Hi, thanks for opening the issue. Yes, Node's conditional exports are not well supported by blunders currently (unfortunately). There is an issue here fore rollup, but it seems like it's landed in Webpack 5 from what I've been able to find.

Each codec is bundled separately using code splitting, and is the default export from module, so the import shouldn't have the brackets.

import Blosc from 'numcodecs/blosc';
// not { Blosc }

I'm not sure if webpack has tree-shaking, but it shouldn't have a hard time doing so. The main entry point is just exporting each of the separate codecs.

export { Codec, CompressorConfig } from './types';
export { default as GZip } from './gzip';
export { default as Zlib } from './zlib';
export { default as Blosc } from './blosc';

@manzt
Copy link
Owner

manzt commented Jun 25, 2020

If you continue to have issues with configuring webpack, you can import the esm module for blosc directly:

import Blosc from './node_modules/numcodecs/dist/blosc.mjs';

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

Successfully merging a pull request may close this issue.

2 participants