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

Code splits limitation #52

Open
FranckFreiburger opened this issue Nov 2, 2018 · 1 comment
Open

Code splits limitation #52

FranckFreiburger opened this issue Nov 2, 2018 · 1 comment

Comments

@FranckFreiburger
Copy link

FranckFreiburger commented Nov 2, 2018

Detailed Description

Since code split creates multiple independent chunks, prepack can only apply optimizations to chunk "shells", not modules contained in these chunks (maybe except for entry chunk).
I wondering if there is any workaround for this ?

Possible Implementation

call __optimize(module) for each module in a chunk
eg: https://prepack.io/repl.html#GYVwdgxgLglg9mABAWzgExAGwKYEYAUAlIgN4BQiioksCVccRpFliATtlCG0gOTANeAbhYBfFtWjwkAIwCGbJuVbtO3PvLbCxLDlx71GxANSJNREeLIB9a3AAOsZDABe2fKgw5chMkA

@FranckFreiburger
Copy link
Author

    compiler.hooks.thisCompilation.tap('PrepackPlugin', compilation => {

      compilation.chunkTemplate.hooks.render.tap(
        {
          name: 'PrepackPlugin',
          stage: 9999, // stage:9999 // need to be at latest stage
        },
        (source, chunk, module) => {

          const jsonpFunction = compilation.chunkTemplate.outputOptions.jsonpFunction;
          const globalObject = compilation.chunkTemplate.outputOptions.globalObject;

          source.add(`;(function(){
            var chunkModuleList = ${globalObject}[${JSON.stringify(jsonpFunction)}].slice(-1)[0][1];
            for (var id in chunkModuleList)
              __optimize(chunkModuleList[id]);
          })()`);
        }
      )
    });

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

1 participant