Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to use glob patterns with chunk names? How to preload specific chunks? #5

Open
milky2028 opened this issue Jan 28, 2020 · 4 comments

Comments

@milky2028
Copy link

I'm attempting to preload initial chunks, as well as some worker scripts using webpack chain in Vue, but I'm struggling to get it to work. Is there something I'm missing here?

    if (config.plugins.has('preload')) {
      config.plugin('preload').tap((options) => {
        options[0] = {
          rel: 'preload',
          include: {
            chunks: ['*.worker.js'],
            type: 'initial'
          },
          fileBlacklist: [/\.map$/, /hot-update\.js$/]
        };
        return options;
      });
    }
@morr
Copy link

morr commented Aug 25, 2020

@milky2028 did you find any solution?

@milky2028
Copy link
Author

milky2028 commented Aug 25, 2020

@morr Unfortunately I did not. My solution was to switch to Rollup and use that for my entire build. Much easier to work with.

@morr
Copy link

morr commented Aug 25, 2020

@milky2028 Well, I already found solution. Here is my working example

    config.plugin('preload').tap(options => {
      options[0].include = {
        type: 'allChunks',
        chunks: ['app', 'chunk-vendors', 'landing', 'landing-styles']
      };
      return options;
    });

Chunks filtering is done by the function https://github.com/vuejs/preload-webpack-plugin/blob/master/src/lib/extract-chunks.js#L51

So I run vue-cli serve with debugger node --inspect-brk ./node_modules/.bin/vue-cli-service serve spend few minutes to see how extractChunks works, and it became obvious what options should be passed there to get the result I want.

@tomchen
Copy link

tomchen commented Mar 25, 2021

Not sure if this can solve your problem but in case anyone needs it, here's the config that can include everything then use fileBlacklist as a white list to include png and jpeg files:

include: 'all',
fileBlacklist: [/\.(?!(png$|jpe?g$)).*$/],

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

No branches or pull requests

3 participants