feat: add options.experimental_output#51
Conversation
README.md
Outdated
| // ... | ||
| contentScript: { | ||
| experimental_output: { | ||
| myContentScript: 'cs.js' |
There was a problem hiding this comment.
so cs.js refers to the output file for content_scripts within the root of the output path? like dist/cs.js?
There was a problem hiding this comment.
Yes, it will be an extra output file.
README.md
Outdated
| contentScript: { | ||
| experimental_output: { | ||
| myContentScript: (manifest, list) => { | ||
| manifest.content_scripts[0].js = list |
There was a problem hiding this comment.
could this handle more than one content_script defined in the manifest file? like which list would this be if I have a manifest.content_scripts[1].js?
There was a problem hiding this comment.
Yes, this is a function, so you can write any code to change your manifest.json (if you defined it via CopyPlugin or other webpack plugins).
{
myContentScript: (manifest, list) => {
manifest.content_scripts[0].js = list
manifest.content_scripts[1].js = list
},
myContentScript2: (manifest, list) => {
manifest.content_scripts[3].js = list
},
}|
I have updated the PR to expand the range to the background service worker. The API is not intuitive enough and I have no confidence with it, so I'll keep it experimental. |
|
2.1.0 released, you can have a try! |
|
you're a legend! |
close #50
options.experimental_output
This is an experimental API. API might change at any time. Please provide feedback!
TLDR: How to use this
string
If you don't strictly rely on run_at,
set it as the following
{ // ... "content_scripts": [ { "matches": ["..."], "js": ["cs.js"] } ] }function
If you cannot use asynchronous loading, set up like below.
This setup requires you to have a
manifest.jsonbeing emitted.object
Explanation
This is an experimental API.
API might change at any time.
Please provide feedback!
This option helps the initial chunk loading of content scripts/the background service worker,
usually needed when
optimization.runtimeChunkoroptimization.splitChunks.chunksis used.This option accepts an object, where the keys are the entry name,
and the value is described below.
This option replaces the HTMLWebpackPlugin where the background service worker and content scripts
do not use HTML to load files.
If the value is a
string(an output file name), for content scripts, it creates an extraentry file to load all initial chunks asynchronously via dynamic import.
This asynchronous loading behavior is limited to the platform limit and breaks
run_at.
If the value is a
string(an output file name), for the background service worker (specifiedvia
options.background.serviceWorkerEntry), it creates an extra entry file to load allinitial chunks synchronously.
The file name specified MUST NOT be any existing file.
If the value is a
function((manifest: any, chunks: string[]) => void), it requiresa "manifest.json" in the emitted files and lets you edit it on the fly to include all
the initial chunks. This option does not apply to the background service worker because
manifest.jsondoes not accept multiple files.If the value is an
object({ file: string; touch(manifest: any, file: string): void }),it generates a new file (see the behavior of
stringabove) and provides a callback toedit the
manifest.json(see the behavior offunctionabove).If the value is
false, it asserts that this entry does not have more than one initial file,otherwise, it will be a compile error.
If the value is
undefined, it silences the warning for the background service worker.You can also change your configuration to avoid
optimization.runtimeChunkoroptimization.splitChunks.chunks,in this case, webpack only generates 1 initial file so you don't need this option.