ui-router/core

Circular dependency cause tree-shaking not working.

YuhangGe opened this issue · 3 comments

The entry file is simple:

import {
  UIRouter
} from '@uirouter/core';

console.log('yes');

The rollup config file is:

/* eslint-env node */
import resolve from 'rollup-plugin-node-resolve';

export default {
  input: './test.js',
  output: {
    file: `./dist/bundle.rollup.js`,
    format: 'iife'
  },
  plugins: [resolve()]
};

The output 'bundle.rollup.js' include all uirouter code, even we never use the imported UIRouter. Rollup warn some circular dependency info:

(!) Circular dependency: ../../node_modules/@uirouter/core/lib-esm/state/index.js -> ../../node_modules/@uirouter/core/lib-esm/state/stateService.js -> ../../node_modules/@uirouter/core/lib-esm/transition/transitionService.js -> ../../node_modules/@uirouter/core/lib-esm/hooks/coreResolvables.js -> ../../node_modules/@uirouter/core/lib-esm/router.js -> ../../node_modules/@uirouter/core/lib-esm/url/urlService.js -> ../../node_modules/@uirouter/core/lib-esm/url/urlRules.js -> ../../node_modules/@uirouter/core/lib-esm/state/index.js

I guess it's the Circular dependency that case three-shaking not working.

When I use wepack in production mode, the tree-shaking also not working.

How does this issue affect you? I don't know if any code in core is actually tree shakable. I believe it's all used. What symbols do you expect to get tree shaked away?

I'm trying to implement a mvvm framework(just for play & experiment). As I used ui-router a lot and like it's state-based concept, I wanna to use @uirouter/core as router core then I do not need to implement route logic by my self. But I found that even I do not use router, just a "hello-world" example, the output bundle is very large.

I have got plan B to move all router function to another package to solve this issue, just like react-router~

thanks.

This is creating issues in fuse-box, please reopen. Circular dependencies are a nightmare for bundlers/loaders, it should really not be allowed into the code.

I'm getting an undefined StateService and TransitionService because of this, please can we properly modularise things so this doesn't have to be an issue.