question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow to create a script tag with src attribute for chunk manifest file

See original GitHub issue

Currently the chunk manifest is always inlined into generated html files. It’s ok if there are not that many pages/chunks, but in my prototype with ~500 pages the uncompressed chunk-manifest.json file has already size of ~30kB (12kB gzipped) and I can assume that with ~5000 pages that we got in total, it will be ~10x larger.

That’s why it might be a good idea to add an option to generate a chunk-manifest.js file and a script tag with src attribute pointing to it.

So far I came up with something like this:

This generates chunk-manifest.js file based on contents of chunk-manifest.json file:

// /src/utils/webpack.config.js
new ChunkManifestPlugin({
  filename: `chunk-manifest.json`,
  manifestVariable: `webpackManifest`
}), 
{
  apply: function (compiler) {
    compiler.plugin(`emit`, function (compilation, callback) {
      compilation.assets[`chunk-manifest.js`] = new ConcatSource(
        `window.webpackManifest = `,
        compilation.assets[`chunk-manifest.json`],
        `;`
      );
      callback();
    });
  }
},

This decides if it should create script tag with inlined contents of chunk-manifest.json file or with src attribute pointing to chunk-manifest.js file:

// /cache-dir/static-entry.js
if (some condition) {
  const chunkManifest = require(`!file?name=[name].[hash].[ext]!../public/chunk-manifest.js`)

  headComponents.unshift( <
    script id = "webpack-manifest"
    key = "webpack-manifest"
    src = {chunkManifest}
    />
  )
} else {
  const chunkManifest = require(`!raw!../public/chunk-manifest.json`)

  headComponents.unshift( <
    script id = "webpack-manifest"
    key = "webpack-manifest"
    dangerouslySetInnerHTML = {
      {
        __html: `
            //<![CDATA[
            window.webpackManifest = ${chunkManifest}
            //]]>
            `,
      }
    }
    />
  )
}

It’s just an initial version, which probably has some issues, e.g. require(!file...) will probably emit chunk-manifest.[hash].js as many times as there are pages (though maybe node caching mechanism kicks in here for require calls and it will do it just once), pathPrefix is not taken into account (though it should be an easy fix) etc.

Please let me know if it’s something you’d be interested in and what’s the best way to specify an option to decide if chunk manifest should be inlined or not and I’ll prepare a PR.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
KyleAMathewscommented, Nov 28, 2017
  1. The total size of this manifest will shrink soon as we won’t be managing the results of GraphQL queries through webpack like we are now
  2. we’ll also soon be splitting and lazy loading manifests so we’ll only inline what’s necessary to bootstrap webpack on the initial page
1reaction
KyleAMathewscommented, Nov 28, 2017

Will be putting together a new roadmap for this stuff in coming weeks.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Injecting a script tag from a content script to an iframe with ...
I'm using manifest v3 and I have a content script that injects a script ... The issue comes when we have an iframe...
Read more >
Link types: preload - HTML: HyperText Markup Language | MDN
The preload value of the element's rel attribute lets you declare fetch requests in the HTML's , specifying resources that your page will ......
Read more >
Content security policy - web.dev
We specified only script-src in our earlier examples, which means that images, fonts, and so on can be loaded from any origin. The...
Read more >
chunks-webpack-plugin - npm
Create HTML files with entrypoints and chunks relations to serve your ... HTML style tags with CDN prefix and defer attribute const scripts...
Read more >
Backend Integration - Vite
In your Vite config, configure the entry and enable build manifest: ... <script type="module" src="http://localhost:5173/@vite/client"></script> <script ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found