Skip to content

Npm Size Reduction

spessasus edited this page Oct 15, 2024 · 2 revisions

NPM size reduction

The npm package works slightly differently than the standard install.

The problem

The library contains a lot of other functionality than just the synthesizer, which probably most people are going to use. This is wasted bandwith.

This is a problem, because it will be bundled by default when using bundlers such as webpack.

The solution

The solution is to use "tree shaking".

For example, webpack.config.js;

const path = require('path');

module.exports = {
    entry: './src/index.js',
    output: {
        filename: 'bundle.js',
        path: path.resolve(__dirname, 'dist'),
    },

    module: {
        rules: [
            {
                // this enables tree shaking
                sideEffects: false
            }
        ]
    },

    mode: 'production',
};

This prevents unused modules from being included when not necessary.