FormidableLabs / redux-little-router

A tiny router for Redux that lets the URL do the talking.
MIT License
1.04k stars 113 forks source link

[BUG] Webpack tree-shaking isn't working for root imports. #262

Closed ryan-roemer closed 6 years ago

ryan-roemer commented 6 years ago

Overview

Webpack tree-shaking at least as of 3.10 just isn't working is the short answer. I have a new experiment repository up at: https://github.com/FormidableLabs/rlr-tree-shaking-experiment

This mean a couple of things:

  1. Any builds importing like import { something } from 'redux-little-router' is likely getting a lot more code and maybe even other dependencies than they should.
  2. This explains the behavior in https://github.com/FormidableLabs/redux-little-router/issues/261 that shouldn't be happening.

Workarounds

The present workaround to all of this is one-off imports, which means something like instead of:

import { routerForBrowser } from 'redux-little-router';

do:

import routerForBrowser from 'redux-little-router/es/environment/browser-router';

in your frontend code and:

import routerForBrowser from 'redux-little-router/lib/environment/browser-router';

in your node code.

This is problematic for universal code which instead should probably do something like:

import routerForBrowser from 'redux-little-router/environment/browser-router';

in universal code and something like:

const path = require('path');

alias: {
  'redux-little-router': path.dirname(require.resolve('redux-little-router/es/index'))
}

in webpack config.

Task

/cc @tptee

ryan-roemer commented 6 years ago

Fixed in https://github.com/FormidableLabs/redux-little-router/releases/tag/v15.0.0 with the caveat that you need webpack@4+.