@@ -19,8 +19,6 @@ import type {PluginOptions} from '@docusaurus/plugin-pwa';
19
19
20
20
const PluginName = 'docusaurus-plugin-pwa' ;
21
21
22
- const isProd = process . env . NODE_ENV === 'production' ;
23
-
24
22
function getSWBabelLoader ( ) {
25
23
return {
26
24
loader : 'babel-loader' ,
@@ -45,12 +43,21 @@ function getSWBabelLoader() {
45
43
export default function pluginPWA (
46
44
context : LoadContext ,
47
45
options : PluginOptions ,
48
- ) : Plugin < void > {
46
+ ) : Plugin < void > | null {
47
+ if ( process . env . NODE_ENV !== 'production' ) {
48
+ return null ;
49
+ }
50
+ if ( context . siteConfig . future . experimental_router === 'hash' ) {
51
+ logger . warn (
52
+ `${ PluginName } does not support the Hash Router and will be disabled.` ,
53
+ ) ;
54
+ return null ;
55
+ }
56
+
49
57
const {
50
58
outDir,
51
59
baseUrl,
52
60
i18n : { currentLocale} ,
53
- siteConfig,
54
61
} = context ;
55
62
const {
56
63
debug,
@@ -61,13 +68,6 @@ export default function pluginPWA(
61
68
swRegister,
62
69
} = options ;
63
70
64
- if ( siteConfig . future . experimental_router === 'hash' ) {
65
- logger . warn (
66
- `${ PluginName } does not support the Hash Router and will be disabled.` ,
67
- ) ;
68
- return { name : PluginName } ;
69
- }
70
-
71
71
return {
72
72
name : PluginName ,
73
73
@@ -79,7 +79,7 @@ export default function pluginPWA(
79
79
} ,
80
80
81
81
getClientModules ( ) {
82
- return isProd && swRegister ? [ swRegister ] : [ ] ;
82
+ return swRegister ? [ swRegister ] : [ ] ;
83
83
} ,
84
84
85
85
getDefaultCodeTranslationMessages ( ) {
@@ -90,10 +90,6 @@ export default function pluginPWA(
90
90
} ,
91
91
92
92
configureWebpack ( config ) {
93
- if ( ! isProd ) {
94
- return { } ;
95
- }
96
-
97
93
return {
98
94
plugins : [
99
95
new webpack . EnvironmentPlugin ( {
@@ -111,37 +107,31 @@ export default function pluginPWA(
111
107
112
108
injectHtmlTags ( ) {
113
109
const headTags : HtmlTags = [ ] ;
114
- if ( isProd ) {
115
- pwaHead . forEach ( ( { tagName, ...attributes } ) => {
116
- ( [ 'href' , 'content' ] as const ) . forEach ( ( attribute ) => {
117
- const attributeValue = attributes [ attribute ] ;
118
-
119
- if ( ! attributeValue ) {
120
- return ;
121
- }
122
-
123
- const attributePath =
124
- ! ! path . extname ( attributeValue ) && attributeValue ;
125
-
126
- if ( attributePath && ! attributePath . startsWith ( baseUrl ) ) {
127
- attributes [ attribute ] = normalizeUrl ( [ baseUrl , attributeValue ] ) ;
128
- }
129
- } ) ;
130
-
131
- return headTags . push ( {
132
- tagName,
133
- attributes,
134
- } ) ;
110
+ pwaHead . forEach ( ( { tagName, ...attributes } ) => {
111
+ ( [ 'href' , 'content' ] as const ) . forEach ( ( attribute ) => {
112
+ const attributeValue = attributes [ attribute ] ;
113
+
114
+ if ( ! attributeValue ) {
115
+ return ;
116
+ }
117
+
118
+ const attributePath =
119
+ ! ! path . extname ( attributeValue ) && attributeValue ;
120
+
121
+ if ( attributePath && ! attributePath . startsWith ( baseUrl ) ) {
122
+ attributes [ attribute ] = normalizeUrl ( [ baseUrl , attributeValue ] ) ;
123
+ }
124
+ } ) ;
125
+
126
+ return headTags . push ( {
127
+ tagName,
128
+ attributes,
135
129
} ) ;
136
- }
130
+ } ) ;
137
131
return { headTags} ;
138
132
} ,
139
133
140
134
async postBuild ( props ) {
141
- if ( ! isProd ) {
142
- return ;
143
- }
144
-
145
135
const swSourceFileTest = / \. m ? j s $ / ;
146
136
147
137
const swWebpackConfig : Configuration = {
0 commit comments