File tree Expand file tree Collapse file tree 2 files changed +37
-10
lines changed Expand file tree Collapse file tree 2 files changed +37
-10
lines changed Original file line number Diff line number Diff line change @@ -200,6 +200,7 @@ export default class InitGenerator extends Generator {
200200 }
201201 }
202202 if ( this . usingDefaults ) {
203+ // Html webpack Plugin
203204 this . dependencies . push ( "html-webpack-plugin" ) ;
204205 const htmlWebpackDependency = "html-webpack-plugin" ;
205206 const htmlwebpackPlugin = generatePluginName ( htmlWebpackDependency ) ;
@@ -211,22 +212,34 @@ export default class InitGenerator extends Generator {
211212 ( this . configuration . config . webpackOptions . plugins as string [ ] ) . push ( `new ${ htmlwebpackPlugin } ({
212213 template: 'index.html'
213214 })` ) ;
215+
216+ // webpack Dev Server
214217 this . dependencies . push ( "webpack-dev-server" ) ;
215218 this . configuration . config . webpackOptions . devServer = {
216219 open : true
217220 } ;
218221 }
219222
223+ // TerserPlugin
220224 this . dependencies . push ( "terser-webpack-plugin" ) ;
221225 this . configuration . config . topScope . push (
222226 tooltip . terser ( ) ,
223227 "const TerserPlugin = require('terser-webpack-plugin');" ,
224228 "\n"
225229 ) ;
226230
231+ // PWA + offline support
232+ this . configuration . config . topScope . push ( "const workboxPlugin = require('workbox-webpack-plugin');" , "\n" ) ;
233+ this . dependencies . push ( "workbox-webpack-plugin" ) ;
234+ ( this . configuration . config . webpackOptions . plugins as string [ ] ) . push ( `new workboxPlugin.GenerateSW({
235+ swDest: 'sw.js',
236+ clientsClaim: true,
237+ skipWaiting: true,
238+ })` ) ;
239+
240+ // Chunksplitting
227241 this . configuration . config . webpackOptions . optimization = getDefaultOptimization ( this . usingDefaults ) ;
228242 this . configuration . config . webpackOptions . mode = this . usingDefaults ? "'production'" : "'development'" ;
229-
230243 done ( ) ;
231244 }
232245
Original file line number Diff line number Diff line change 11<!DOCTYPE html>
22< html >
3- < head >
4- < meta charset ="utf-8 ">
5- < title > Webpack App</ title >
6- </ head >
7- < body >
8- < h1 > Hello world!</ h1 >
9- < h2 > Tip: Check your console</ h2 >
10- </ body >
11- </ html >
3+ < head >
4+ < meta charset ="utf-8 " />
5+ < title > Webpack App</ title >
6+ </ head >
7+ < body >
8+ < h1 > Hello world!</ h1 >
9+ < h2 > Tip: Check your console</ h2 >
10+ < script >
11+ if ( "serviceWorker" in navigator ) {
12+ window . addEventListener ( "load" , ( ) => {
13+ navigator . serviceWorker
14+ . register ( "/sw.js" )
15+ . then ( registration => {
16+ console . log ( "SW registered: " , registration ) ;
17+ } )
18+ . catch ( registrationError => {
19+ console . log ( "SW registration failed: " , registrationError ) ;
20+ } ) ;
21+ } ) ;
22+ }
23+ </ script >
24+ </ body >
25+ </ html >
You can’t perform that action at this time.
0 commit comments