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

add sideEffects === false for webpack #11

Merged
merged 1 commit into from Jul 12, 2020
Merged

add sideEffects === false for webpack #11

merged 1 commit into from Jul 12, 2020

Conversation

manzt
Copy link
Owner

@manzt manzt commented Jul 10, 2020

I'm not very experienced with webpack, but I saw this in the docs on tree-shaking:

The new webpack 4 release expands on this capability with a way to provide hints to the compiler via the "sideEffects" package.json property to denote which files in your project are "pure" and therefore safe to prune if unused.

Since all exports (codecs) are side effect free in numcodecs, I added this to the repo's package.json. This seemed to fix #9, removing unused codecs from the final webpack bundle in my brief experimenting:

index.js

import { Blosc } from 'numcodecs';

const codec = new Blosc();

webpack.config.js

const path = require('path');

module.exports = {
  entry: 'index.js',
  output: {
    filename: 'bundle.js',
    path: path.resolve(__dirname, 'dist'),
  },
  mode: 'production',
  optimization: {
    minimize: false // just so I could inspect the bundled output
  }
}

@manzt
Copy link
Owner Author

manzt commented Jul 10, 2020

@jbms - would you mind editing node_modules/numcodecs.js/package.json for your project, adding "sideEffects": false, and seeing if it fixes your issues? I will then merge and make a new release for you.

@manzt
Copy link
Owner Author

manzt commented Jul 10, 2020

The "sideEffects" property also seems to be used by @rollup/plugin-node-resolve:

index.js

import { Blosc } from 'numcodecs';

const codec = new Blosc();

rollup.config.js

import resolve from '@rollup/plugin-node-resolve';

export default {
  input: './index.js',
  output: {
    file: './bundle.js',
    format: 'es'
  },
  plugins: [
    resolve()
  ]
}

$ rollup -c now produces an output with only blosc codec (which it did not before).

@jbms
Copy link

jbms commented Jul 10, 2020

Thanks for looking into this. Yes, I can confirm that setting "sideEffects": false fixes the issue.

@manzt
Copy link
Owner Author

manzt commented Jul 12, 2020

Great, thanks for checking!

@manzt manzt merged commit 3cc9b95 into main Jul 12, 2020
@manzt manzt deleted the no-sideeffects branch July 12, 2020 17:34
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 this pull request may close these issues.

Importing a single codec when using a browser build
2 participants