Possible for me to write a plugin for chrome extension manifest.json files? #62
davidmurdoch
started this conversation in
General
Replies: 2 comments 2 replies
-
|
Hello @davidmurdoch, I have already thought and prepared the opportunity to extract all output assets. |
Beta Was this translation helpful? Give feedback.
0 replies
-
|
See here the stages where what you can doo: The afterEmit hook receives the This is an array of objects containing all dependencies used in the entry object. {
apply(compiler) {
const pluginName = 'myPlugin';
compiler.hooks.compilation.tap(pluginName, (compilation) => {
const hooks = HtmlBundlerPlugin.getHooks(compilation);
hooks.afterEmit.tap(pluginName, (entries, options) => {
// output the structure of the entries object
console.dir(entries, { depth: 8 })
// TODO: write your own function to walk through the entries and generate an JSON object what you need
//const assets = manifest(entries);
// TODO: write manifest to disk
const saveAs = path.join(__dirname, 'dist/manifest.json');
//const data = JSON.stringify(assets, null, ' ');
//fs.writeFileSync(saveAs, data);
});
});
},
}See please the working |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment

Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
A
manifest.jsonis a required document for Chrome/Firefox extensions. It has a few fields that describe application entry points. A basic example ofmanifest.jsonfile might have entry points like:There are some interesting rules around these entry points. For example, the file
document_start.jsin thecontent_scriptssection might get split byruntimeorsplitChunkssettings, if that happens thejsarray should be updated to contain the runtime/chunks. Similarly, withinpage.jsin theweb_accessible_resourcesarray (though this one gets complicated, as inpage.js might be dynamically injected into a browser tab bydocument_start.js-- and updating the dynamic injection to add runtime/chunk loading is likely not feasible).The
background.htmlin thebackgroundhtml section should be treated as an entry point.I'm currently writing a helper function to parse this document in order to collect entry points to add to my webpack config. I was thinking this could be nice to have as a webpack plugin.
This seems doable to me, but I again don't know where to start. I was thinking the test case at https://github.com/webdiscus/html-bundler-webpack-plugin/blob/master/test/cases/hook-beforeEmit-rtlcss/webpack.config.js#L49 would be a good pattern to follow, but I'm unsure how to get a final list of the runtime/chunks that'd need to be inserted back into the manifest.json file.
What do you think? Is this feasible?
Beta Was this translation helpful? Give feedback.
All reactions