Coder Social home page Coder Social logo

Comments (1)

davidgilbertson avatar davidgilbertson commented on May 28, 2024

This turned into a bit of a Webpack vs Rollup exercise.

Webpack won. 4% smaller bundle and less painful config.

For posterity...

Webpack

Webpack's documentation was as baffling as always, of course there's 600 ways of using externals and I'm sure it's perfectly obvious which one to use if you already know which one to use.

Bundle size: 4.159 KB

Config:

const path = require('path');
const { peerDependencies } = require('./package.json');

module.exports = {
  mode: 'production',
  entry: path.resolve(__dirname, 'src/index.js'),
  output: {
    filename: 'index.js',
    path: path.resolve(__dirname, 'dist'),
    libraryTarget: 'umd',
  },
  module: {
    rules: [
      {
        test: /\.js$/,
        use: 'babel-loader',
      },
    ],
  },
  externals: Object.keys(peerDependencies),
};

Rollup

Rollup needs 4 plugins and the associated reading material just to work. I wound up copy/pasting from react-redux. And it throws 'circular reference' warnings, which is not confidence inspiring.

Bundle size: 4.335 KB

Config:

import babelPlugin from 'rollup-plugin-babel';
import nodeResolvePlugin from 'rollup-plugin-node-resolve';
import commonJsPlugin from 'rollup-plugin-commonjs';
import { uglify } from 'rollup-plugin-uglify';
import { peerDependencies } from './package.json';

export default {
  input: './src/index.js',
  output: {
    file: './dist/index.js',
    format: 'umd',
    name: 'ReactRecollect',
  },
  external: Object.keys(peerDependencies),
  plugins: [
    nodeResolvePlugin(),
    babelPlugin({
      exclude: '**/node_modules/**',
      runtimeHelpers: true,
    }),
    commonJsPlugin(),
    uglify({
      compress: {
        pure_getters: true,
        unsafe: true,
        unsafe_comps: true,
        warnings: false,
      },
    }),
  ],
};

Parcel

Was a non-starter, since it seems it can exclude externals (e.g. react).

from react-recollect.

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.