1
1
import * as path from 'path' ;
2
2
import * as webpack from 'webpack' ;
3
3
import * as fs from 'fs' ;
4
+ import * as semver from 'semver' ;
4
5
import { stripIndent } from 'common-tags' ;
5
6
import { StaticAssetPlugin } from '../../plugins/static-asset' ;
6
7
import { GlobCopyWebpackPlugin } from '../../plugins/glob-copy-webpack-plugin' ;
@@ -26,6 +27,19 @@ export const getProdConfig = function (wco: WebpackConfigOptions) {
26
27
` ) ;
27
28
}
28
29
30
+ // Read the version of @angular /service-worker and throw if it doesn't match the
31
+ // expected version.
32
+ const allowedVersion = '>= 1.0.0-beta.5 < 2.0.0' ;
33
+ const swPackageJson = fs . readFileSync ( `${ swModule } /package.json` ) . toString ( ) ;
34
+ const swVersion = JSON . parse ( swPackageJson ) [ 'version' ] ;
35
+ if ( ! semver . satisfies ( swVersion , allowedVersion ) ) {
36
+ throw new Error ( stripIndent `
37
+ The installed version of @angular/service-worker is ${ swVersion } . This version of the CLI
38
+ requires the @angular/service-worker version to satisfy ${ allowedVersion } . Please upgrade
39
+ your service worker version.
40
+ ` ) ;
41
+ }
42
+
29
43
// Path to the worker script itself.
30
44
const workerPath = path . resolve ( swModule , 'bundles/worker-basic.min.js' ) ;
31
45
@@ -52,7 +66,9 @@ export const getProdConfig = function (wco: WebpackConfigOptions) {
52
66
// Load the Webpack plugin for manifest generation and install it.
53
67
const AngularServiceWorkerPlugin = require ( '@angular/service-worker/build/webpack' )
54
68
. AngularServiceWorkerPlugin ;
55
- extraPlugins . push ( new AngularServiceWorkerPlugin ( ) ) ;
69
+ extraPlugins . push ( new AngularServiceWorkerPlugin ( {
70
+ baseHref : buildOptions . baseHref || '/' ,
71
+ } ) ) ;
56
72
57
73
// Copy the worker script into assets.
58
74
const workerContents = fs . readFileSync ( workerPath ) . toString ( ) ;
0 commit comments