This repository has been archived by the owner on Aug 10, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updates to reflect the latest Workbox webpack plugin options. (#5677)
* Updates to reflect the latest Workbox webpack plugin options. * Linting
- Loading branch information
1 parent
13571f0
commit 6bf2f55
Showing
7 changed files
with
338 additions
and
260 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
121 changes: 121 additions & 0 deletions
121
src/content/en/tools/workbox/guides/_shared/common-webpack.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
<tr> | ||
<td> | ||
<p>chunks</p> | ||
</td> | ||
<td> | ||
<p> | ||
<em>Optional <code>Array</code> of <code>String</code>, defaulting to <code>[]</code></em> | ||
</p> | ||
<p> | ||
By default, Workbox will precache assets regardless of which <code>chunk</code> the asset is | ||
part of. | ||
</p> | ||
<p> | ||
If you would like to override this behavior via a whitelist, specify one or more | ||
<code>chunk</code> names. Only assets belonging to those <code>chunk</code>s will be | ||
precached; any assets belonging to another <code>chunk</code> or without a <code>chunk</code> | ||
association will be skipped. | ||
</p> | ||
<p> | ||
<strong>Example:</strong> | ||
</p> | ||
<pre class="prettyprint">// *Only* include assets that belong to these chunks: | ||
chunks: ['chunk-name-1', 'chunk-name-2']</pre> | ||
</td> | ||
</tr> | ||
|
||
<tr> | ||
<td> | ||
<p>exclude</p> | ||
</td> | ||
<td> | ||
<p> | ||
<em>Optional <code>Array</code> of <code>RegExp</code> or <code>String</code>, | ||
defaulting to <code>[/\.map$/, /^manifest.*\.js(?:on)?$/]</code></em> | ||
</p> | ||
<p> | ||
This allows you to specifically omit assets matching any of the provided criteria from being | ||
included in the precache manifest. It provides a filename-based approach to filtering. | ||
</p> | ||
<p> | ||
This filtering takes place <em>after</em> any <code>chunk</code>-based filtering is applied. | ||
</p> | ||
<p> | ||
<strong>Example:</strong> | ||
</p> | ||
<pre class="prettyprint">// Exclude JPG and PNG assets from precaching: | ||
exclude: [/\.jpg$/, /\.png$/]</pre> | ||
</td> | ||
</tr> | ||
|
||
<tr> | ||
<td> | ||
<p>excludeChunks</p> | ||
</td> | ||
<td> | ||
<p> | ||
<em>Optional <code>Array</code> of <code>String</code>, defaulting to <code>[]</code></em> | ||
</p> | ||
<p> | ||
By default, Workbox will precache all assets generated by the webpack compilation, regardless | ||
of which <code>chunk</code> the asset is part of. | ||
</p> | ||
<p> | ||
If you would like to override this behavior via a blacklist, specify one or more | ||
<code>chunk</code> names. Any assets belonging to those <code>chunks</code> will be skipped. | ||
</p> | ||
<p> | ||
<strong>Example:</strong> | ||
</p> | ||
<pre class="prettyprint">// Exclude assets that belong to these chunks: | ||
excludeChunks: ['chunk-name-1', 'chunk-name-2']</pre> | ||
</td> | ||
</tr> | ||
|
||
<tr> | ||
<td> | ||
<p>include</p> | ||
</td> | ||
<td> | ||
<p> | ||
<em>Optional <code>Array</code> of <code>RegExp</code> or <code>String</code></em> | ||
</p> | ||
<p> | ||
This allows you to only include assets matching any of the provided criteria when creating the | ||
precache manifest. It provides a filename-based approach to filtering. | ||
</p> | ||
<p> | ||
This filtering takes place <em>after</em> any <code>chunk</code>-based filtering is applied. | ||
</p> | ||
<p> | ||
In keeping with | ||
<a href="https://webpack.js.org/configuration/module/#condition">webpack convention</a>, | ||
the option `test` can be used as an alias/alternative to `include`. | ||
</p> | ||
<p> | ||
<strong>Example:</strong> | ||
</p> | ||
<pre class="prettyprint">// Only include HTML and JS assets when precaching: | ||
include: [/\.html$/, /\.js$/]</pre> | ||
</td> | ||
</tr> | ||
|
||
<tr> | ||
<td> | ||
<p>swDest</p> | ||
</td> | ||
<td> | ||
<p> | ||
<em>Optional <code>String</code>, defaulting to `'service-worker.js'`</em> | ||
</p> | ||
<p> | ||
The path and filename of the service worker file that will be created by the build process, | ||
relative to the webpack output directory. | ||
</p> | ||
<p> | ||
<strong>Example:</strong> | ||
</p> | ||
<pre class="prettyprint">swDest: 'custom-sw-name.js'</pre> | ||
</td> | ||
</tr> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
src/content/en/tools/workbox/guides/_shared/webpack-generate-sw.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<tr> | ||
<td> | ||
<p>importWorkboxFrom</p> | ||
</td> | ||
<td> | ||
<p> | ||
<em>Optional <code>String</code>, defaulting to 'cdn'</em> | ||
</p> | ||
<ul> | ||
<li> | ||
<code>'cdn'</code>, the default, will use a URL for the Workbox runtime libraries hosted on | ||
a highly-available <a href="https://cloud.google.com/storage/">Google Cloud Storage</a> | ||
instance. | ||
</li> | ||
<li> | ||
<code>'local'</code> will copy <em>all</em> of the Workbox runtime libraries into a | ||
versioned directory alongside your generated service worker, and configure the service | ||
worker to use those local copies. This option is provided for developers who would prefer | ||
to host everything themselves and not rely on the Google Cloud Storage CDN. | ||
</li> | ||
<li> | ||
<code>'disabled'</code> will opt-out automatic behavior. It's up to you to host a local copy | ||
of the Workbox libraries at your preferred URL, and to pass in the correct path to | ||
<code>workbox-sw.js</code> via the <code>importScripts</code> configuration option. | ||
</li> | ||
<li> | ||
Passing in a string corresponding to the webpack chunk name containing a custom Workbox | ||
runtime library bundle is also supported. | ||
</li> | ||
</ul> | ||
<p> | ||
<strong>Example:</strong> | ||
</p> | ||
<pre class="prettyprint">importWorkboxFrom: 'name-of-workbox-chunk'</pre> | ||
</td> | ||
</tr> |
64 changes: 64 additions & 0 deletions
64
src/content/en/tools/workbox/guides/_shared/webpack-inject-manifest.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<tr> | ||
<td> | ||
<p>importWorkboxFrom</p> | ||
</td> | ||
<td> | ||
<p> | ||
<em>Optional <code>String</code>, defaulting to 'cdn'</em> | ||
</p> | ||
<ul> | ||
<li> | ||
<code>'cdn'</code>, the default, will use a URL for the Workbox runtime libraries hosted on | ||
a highly-available <a href="https://cloud.google.com/storage/">Google Cloud Storage</a> | ||
instance. | ||
</li> | ||
<li> | ||
<code>'disabled'</code> will opt-out automatic behavior. It's up to you to host a local copy | ||
of the Workbox libraries at your preferred URL, and ensure that they are loaded via | ||
<code>importScripts()</code>. | ||
</li> | ||
<li> | ||
Passing in a string corresponding to the webpack chunk name containing a custom Workbox | ||
runtime library bundle is also supported. | ||
</li> | ||
</ul> | ||
<p> | ||
<strong>Example:</strong> | ||
</p> | ||
<pre class="prettyprint">importWorkboxFrom: 'name-of-workbox-chunk'</pre> | ||
</td> | ||
</tr> | ||
|
||
|
||
<tr> | ||
<td> | ||
<p>swSrc</p> | ||
</td> | ||
<td> | ||
<p> | ||
<em>Required <code>String</code></em> | ||
</p> | ||
<p> | ||
If <code>swSrc</code> is left <code>undefined</code>, the plugin will generate a brand-new | ||
service worker file as part of each compilation, configured based on the options provided. | ||
</p> | ||
<p> | ||
If <code>swSrc</code> is provided, the plugin assumes it refers to an existing service worker | ||
file. The code in this file will be included as-is, with one addition: a call to | ||
<a href="https://developer.mozilla.org/en-US/docs/Web/API/WorkerGlobalScope/importScripts" class="external"><code>importScripts()</code></a> | ||
will be prepended to the existing code, automatically configured to import the generated | ||
<code>manifestFilename</code> file, as well as the necessary Workbox runtime library code. | ||
</p> | ||
<p> | ||
When providing <code>swSrc</code>, your service worker code can reference the | ||
<code>self.__precacheManifest</code> variable to obtain a list of | ||
<a href="/web/tools/workbox/reference-docs/prerelease/module-workbox-build#.ManifestEntry"><code>ManifestEntry</code>s</a> | ||
obtained as part of the compilation: | ||
<code>workbox.precaching.precacheAndRoute(self.__precacheManifest)</code> | ||
</p> | ||
<p> | ||
<strong>Example:</strong> | ||
</p> | ||
<pre class="prettyprint">swSrc: path.join('dev', 'sw.js')</pre> | ||
</td> | ||
</tr> |
Oops, something went wrong.