TrySound / rollup-plugin-size-snapshot

Track your library bundles size and its treeshakability with less effort
MIT License
163 stars 12 forks source link

Experimental code splitting support #23

Open PatNeedham opened 5 years ago

PatNeedham commented 5 years ago

I'm getting an error like this:

[!] (size-snapshot plugin) Error: output file in rollup options should be specified
Error: output file in rollup options should be specified
    at Object.renderChunk (/me/my-sweet-project/node_modules/rollup-plugin-size-snapshot/dist/index.js:66:15)
    at /me/my-sweet-project/node_modules/rollup/dist/rollup.js:20962:25
    at <anonymous>

The beginning of renderChunk inside sizeSnapshot function for this plugin looks like:

    renderChunk(source, chunk, outputOptions) {
      const format = outputOptions.format;
      const output = outputOptions.file;
      const shouldTreeshake = format === "es" || format === "esm";

      if (typeof output !== "string") {
        throw Error("output file in rollup options should be specified");
      }

I believe it should be checking if top-level experimentalCodeSplitting property of the rollup config is set to true, in which case output.dir exists instead of output.file. So that error checking could possibly be changed to

if (typeof output !== "string" && outputOptions.dir !== "string") {
  throw Error("Either output file or dir in rollup options should be specified");
}

However, I see that output variable is used later on in the code, so I tried changing it to

const snapshotParams = {
  snapshotPath,
  name: output || dir,
  data: sizes,
  threshold
};

just to see what happens, and ended up getting a different error after running npx rollup -c:

[!] (size-snapshot plugin) Error: Could not resolve './chunk-1d12f2bd.js' from ../../../../__size_snapshot_bundle__.js
Error: Could not resolve './chunk-1d12f2bd.js' from ../../../../__size_snapshot_bundle__.js
    at error (/me/my-sweet-project/node_modules/rollup/dist/rollup.js:3460:30)
    at /me/my-sweet-project/node_modules/rollup/dist/rollup.js:21854:25
    at <anonymous>

@TrySound not sure if this issue is related to one you posted on July 26, Test treeshaking with code splitting. Linking that one just in case

TrySound commented 5 years ago

I meant webpack code splitting. This plugin was not created with rollup code splitting in mind.

I think you need something simpler to track your chunks size. They can be already minified and your will need to apply only gzip. This way you will not spend time and memory for useless minification.