preload-webpack-plugin icon indicating copy to clipboard operation
preload-webpack-plugin copied to clipboard

Ignore chunk via webpack comment

Open CzBiX opened this issue 4 years ago • 3 comments

I tried add webpack comment to disable prefetch/preload, but the chunck still builded into html as rel="prefetch". Is it possible to disable it without modify blacklist in webpack config?

My code:

await import(/* webpackPrefetch: false */ 'some-module')

CzBiX avatar Mar 17 '20 10:03 CzBiX

I am facing the same issue. /* webpackChunkName: "IntlPolyfill" */ works fine, but /* webpackPrefetch: false */ is simply ignored. Would be great if this can be fixed!

plehnen avatar Sep 24 '20 08:09 plehnen

I am having the same issues as described above. Seems the webpack commend webpackPrefetch is ignored. This is a real blocker for me as I want to lazy load the dynamic imports when required but having prefetch always true means all my dynamic imports are loaded even if I do not need them.

Has anyone got any ideas on how/where this should be fixed?

Thanks all

EDIT: For now I have created a workaround by configuring the prefetch plugin to ignore chunks starting with "noprefetch". Then adding a webpack comment like /* webpackChunkName: "noprefetch-[request]" */

Plugin configuration

config.plugin("prefetch").tap(options => {
      options[0].fileBlacklist = options[0].fileBlacklist || [];
      options[0].fileBlacklist.push(/\.map$/);
      options[0].fileBlacklist.push(/hot-update\.js$/);

      // Force prefetch to not grab bundles marked as noprefetch.
      options[0].fileBlacklist.push(/noprefetch.*\.js/);   <====================HERE

      return options;
    });

penance316 avatar Dec 28 '20 15:12 penance316

This feels like a requirement for my use case: We want to async import() some modules in dev, test, staging envs only. We do not want those modules in production code. With vanilla webpack, modules are not prefetched unless you opt-in, so we can avoid bundling and shipping those modules by not using /* webpackPrefetch: true */ . In vue-cli webpack, modules are ALWAYS prefetched, and there is no way to /* webpackPrefetch: false */.

signal-intrusion avatar Mar 24 '21 12:03 signal-intrusion