angular-cn/aio/dist/generated/docs/guide/service-worker-config.json

5 lines
23 KiB
JSON
Raw Permalink Normal View History

{
"id": "guide/service-worker-config",
"title": "Service worker configuration",
"contents": "\n\n\n<div class=\"github-links\">\n <a href=\"https://github.com/angular/angular/edit/master/aio/content/guide/service-worker-config.md?message=docs%3A%20describe%20your%20change...\" aria-label=\"Suggest Edits\" title=\"Suggest Edits\"><i class=\"material-icons\" aria-hidden=\"true\" role=\"img\">mode_edit</i></a>\n</div>\n\n\n<div class=\"content\">\n <h1 id=\"service-worker-configuration\">Service worker configuration<a title=\"Link to this heading\" class=\"header-link\" aria-hidden=\"true\" href=\"guide/service-worker-config#service-worker-configuration\"><i class=\"material-icons\">link</i></a></h1>\n<h4 id=\"prerequisites\">Prerequisites<a title=\"Link to this heading\" class=\"header-link\" aria-hidden=\"true\" href=\"guide/service-worker-config#prerequisites\"><i class=\"material-icons\">link</i></a></h4>\n<p>A basic understanding of the following:</p>\n<ul>\n<li><a href=\"guide/service-worker-devops\">Service Worker in Production</a>.</li>\n</ul>\n<hr>\n<p>The <code>ngsw-config.json</code> configuration file specifies which files and data URLs the Angular service\nworker should cache and how it should update the cached files and data. The <a href=\"cli\">Angular CLI</a>\nprocesses the configuration file during <code>ng build</code>. Manually, you can process it with the\n<code>ngsw-config</code> tool (where <code>&#x3C;project-name></code> is the name of the project being built):</p>\n<code-example language=\"sh\">\n./node_modules/.bin/ngsw-config ./dist/&#x3C;project-name> ./ngsw-config.json [/base/href]\n</code-example>\n<p>The configuration file uses the JSON format. All file paths must begin with <code>/</code>, which corresponds\nto the deployment directory—usually <code>dist/&#x3C;project-name></code> in CLI projects.</p>\n<a id=\"glob-patterns\"></a>\n<p>Unless otherwise noted, patterns use a limited glob format:</p>\n<ul>\n<li><code>**</code> matches 0 or more path segments.</li>\n<li><code>*</code> matches 0 or more characters excluding <code>/</code>.</li>\n<li><code>?</code> matches exactly one character excluding <code>/</code>.</li>\n<li>The <code>!</code> prefix marks the pattern as being negative, meaning that only files that don't match the pattern will be included.</li>\n</ul>\n<p>Example patterns:</p>\n<ul>\n<li><code>/**/*.html</code> specifies all HTML files.</li>\n<li><code>/*.html</code> specifies only HTML files in the root.</li>\n<li><code>!/**/*.map</code> exclude all sourcemaps.</li>\n</ul>\n<p>Each section of the configuration file is described below.</p>\n<h2 id=\"appdata\"><code>appData</code><a title=\"Link to this heading\" class=\"header-link\" aria-hidden=\"true\" href=\"guide/service-worker-config#appdata\"><i class=\"material-icons\">link</i></a></h2>\n<p>This section enables you to pass any data you want that describes this particular version of the app.\nThe <code><a href=\"api/service-worker/SwUpdate\" class=\"code-anchor\">SwUpdate</a></code> service includes that data in the update notifications. Many apps use this section to provide additional information for the display of UI popups, notifying users of the available update.</p>\n<a id=\"index-file\"></a>\n<h2 id=\"index\"><code>index</code><a title=\"Link to this heading\" class=\"header-link\" aria-hidden=\"true\" href=\"guide/service-worker-config#index\"><i class=\"material-icons\">link</i></a></h2>\n<p>Specifies the file that serves as the index page to satisfy navigation requests. Usually this is <code>/index.html</code>.</p>\n<h2 id=\"assetgroups\"><code>assetGroups</code><a title=\"Link to this heading\" class=\"header-link\" aria-hidden=\"true\" href=\"guide/service-worker-config#assetgroups\"><i class=\"material-icons\">link</i></a></h2>\n<p><em>Assets</em> are resources that are part of the app version that update along with the app. They can include resources loaded from the page's origin as well as third-party resources loaded from CDNs and other external URLs. As not all such external URLs may be known at build time, URL patterns can be matched.</p>\n<p>This field contains an array of a
}