GithubHelp home page GithubHelp logo

Comments (5)

hyrious avatar hyrious commented on May 16, 2024

I doubt your webpack config is not tweaked well to do tree shaking.
I also made some experiment with bundlers:

Setup

mkdir test-date-fns && cd test-date-fns
npm init -y
npm i -D date-fns esbuild rollup @rollup/plugin-node-resolve webpack webpack-cli

index.js

import { format } from "date-fns";
import { addBusinessDays } from "date-fns/fp";

// `console.log` is required for rollup to mark side effects
console.log(format, addBusinessDays);

webpack.config.js 😒

module.exports = {
    entry: './index.js',
    output: {
        filename: 'bundle.webpack.js',
        path: __dirname,
    },
    mode: 'development',
    devtool: false, // required to make `eval(string)` shorter
    optimization: {
        usedExports: true,
    }
}

Let's see:

npx esbuild index.js --bundle --outfile=bundle.esbuild.js

  bundle.esbuild.js  51.7kb

Done in 252ms
npx rollup -i index.js -p node-resolve -o bundle.rollup.js

index.js → bundle.rollup.js...
created bundle.rollup.js in 3.8s
ls bundle.rollup.js
88,941 bundle.rollup.js
npx webpack
asset bundle.webpack.js 140 KiB [compared for emit] (name: main)
orphan modules 533 KiB [orphan] 467 modules
runtime modules 396 bytes 2 modules
cacheable modules 92.2 KiB
...
file size description
bundle.esbuild.js 51.7kb esbuild strips comments by default
bundle.rollup.js 88.94kb -
bundle.webpack.js 140kb webpack inserts a lot of runtime codes

The difference is webpack generates a lot of /* harmony export */ things and esbuild strips comments. In short, they both do tree shaking well.

To make it fair, I also include minified results here (rollup use terser plugin, esbuild use itself):

file size
bundle.esbuild.js 22,54kb
bundle.rollup.js 21.95kb
bundle.webpack.js 21.77kb

As you can see, they are almost the same.

from flat.

BlackHole1 avatar BlackHole1 commented on May 16, 2024

@hyrious
i will try again in the near future, following your webpack config.

from flat.

stale avatar stale commented on May 16, 2024

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

from flat.

stale avatar stale commented on May 16, 2024

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

from flat.

stale avatar stale commented on May 16, 2024

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

from flat.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.