Skip to content
This repository has been archived by the owner on Jun 25, 2020. It is now read-only.

Global override lazy in test environment to prevent chunking #22

Open
rosskevin opened this issue Jun 9, 2016 · 4 comments
Open

Global override lazy in test environment to prevent chunking #22

rosskevin opened this issue Jun 9, 2016 · 4 comments
Assignees

Comments

@rosskevin
Copy link

I'm using lazy loading for code splitting with great success!

import Dashboard from 'bundle?lazy!./components/Dashboard'

The problem comes during testing:

WARNING in ./~/bundle-loader?lazy!./src/routes/Home/components/Dashboard.js
There is another module with an equal name when case is ignored.
This can lead to unexpected behavior when compiling on a filesystem with other case-semantic.
Rename module if multiple modules are expected or use equal casing if one module is expected.

If it's a test environment, I'd like to be able to globally disable lazy loading. Due to the nature of static ES6 imports, I cannot parameterize the import.

Is this something that would seem useful as a PR?

Are there other ways of solving this (while leaving my import as-is.)? NOTE: I don't want to configure an implicit bundle-loader based on path, I want the explicit import.

@rosskevin rosskevin changed the title Global override lazy in test environment Global override lazy in test environment to prevent chunking Jun 9, 2016
@rosskevin
Copy link
Author

This would also be really helpful to work around the inability to hot-reload async components at the present time:

@michael-ciniawsky
Copy link
Member

@rosskevin Please feel free to send PR for further discussion 😛

@julienR2
Copy link

julienR2 commented Aug 14, 2017

Hi ! I run into this trouble too. More specifically using Angular 2 Universal for which I wanted the server part not to be chunked (angular/angular-cli#7187)

I just find a workaround using webpack max-chunk option like this

new webpack.optimize.LimitChunkCountPlugin({maxChunks: 1})

(https://github.com/webpack/docs/wiki/optimization#chunks)

I hope it can help !

@rogersp
Copy link

rogersp commented Nov 2, 2017

In my case, bundle-loader (as used in React Router v4 code splitting demo) was breaking react hot reloading in development. I was unable to resolve the issue with LimitChunkCountPlugin.

What did work however, was NormalModuleReplacementPlugin to take a path like this:

import loadDashboard from 'bundle?lazy!./components/Dashboard'

and in development, turn it into:

import loadDashboard from './components/Dashboard'

Then you can wrap calls to loadDashboard in a function like this, to handle both scenarios:

function loadBundle (loaderFn, callback) {
  if (process.NODE_ENV == 'development') {
    // component is available immediately, since it didn't go through bundle-loader
    callback(loaderFn);
    return;
  }
  // component gets loaded through bundle-loader
  loaderFn(function(mod) {
    callback(mod.default ? mod.default : mod);
  });
}

and call it like:

loadBundle(loadDashboard, function (Dashboard) {
  // Dashboard component available for use!
});

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants