@@ -45,7 +45,7 @@ export default class InitGenerator extends Generator {
45
45
public constructor ( args , opts ) {
46
46
super ( args , opts ) ;
47
47
48
- this . usingDefaults = false ;
48
+ this . usingDefaults = true ;
49
49
this . autoGenerateConfig = opts . autoSetDefaults ? true : false ;
50
50
51
51
this . dependencies = [ "webpack" , "webpack-cli" , "babel-plugin-syntax-dynamic-import" ] ;
@@ -122,7 +122,7 @@ export default class InitGenerator extends Generator {
122
122
self ,
123
123
"outputDir" ,
124
124
"In which folder do you want to store your generated bundles?" ,
125
- "dist" ,
125
+ "' dist' " ,
126
126
this . autoGenerateConfig
127
127
) ;
128
128
@@ -131,13 +131,7 @@ export default class InitGenerator extends Generator {
131
131
if ( ! this . usingDefaults ) {
132
132
this . configuration . config . webpackOptions . output = {
133
133
chunkFilename : "'[name].[chunkhash].js'" ,
134
- filename : "'[name].[chunkhash].js'" ,
135
- path : `path.resolve(__dirname, '${ outputDir } ')`
136
- } ;
137
- } else {
138
- this . configuration . config . webpackOptions . output = {
139
- filename : "'bundle.js'" ,
140
- path : `path.resolve(__dirname, '${ outputDir } ')`
134
+ filename : "'[name].[chunkhash].js'"
141
135
} ;
142
136
}
143
137
@@ -164,13 +158,13 @@ export default class InitGenerator extends Generator {
164
158
165
159
( { ExtractUseProps, regExpForStyles } = styleQuestionHandler ( self , stylingType ) ) ;
166
160
167
- if ( this . isProd ) {
161
+ if ( this . usingDefaults ) {
168
162
// Ask if the user wants to use extractPlugin
169
163
const { useExtractPlugin } = await Input (
170
164
self ,
171
165
"useExtractPlugin" ,
172
166
"If you want to bundle your CSS files, what will you name the bundle? (press enter to skip)" ,
173
- "null " ,
167
+ "'main.css' " ,
174
168
this . autoGenerateConfig
175
169
) ;
176
170
@@ -205,7 +199,8 @@ export default class InitGenerator extends Generator {
205
199
} ) ;
206
200
}
207
201
}
208
- if ( ! this . isProd ) {
202
+ if ( this . usingDefaults ) {
203
+ // Html webpack Plugin
209
204
this . dependencies . push ( "html-webpack-plugin" ) ;
210
205
const htmlWebpackDependency = "html-webpack-plugin" ;
211
206
const htmlwebpackPlugin = generatePluginName ( htmlWebpackDependency ) ;
@@ -214,25 +209,37 @@ export default class InitGenerator extends Generator {
214
209
"\n" ,
215
210
tooltip . html ( )
216
211
) ;
217
- ( this . configuration . config . webpackOptions . plugins as string [ ] ) . push ( `new ${ htmlwebpackPlugin } ()` ) ;
218
- }
212
+ ( this . configuration . config . webpackOptions . plugins as string [ ] ) . push ( `new ${ htmlwebpackPlugin } ({
213
+ template: 'index.html'
214
+ })` ) ;
219
215
220
- if ( ! this . usingDefaults ) {
216
+ // webpack Dev Server
221
217
this . dependencies . push ( "webpack-dev-server" ) ;
222
218
this . configuration . config . webpackOptions . devServer = {
223
219
open : true
224
220
} ;
225
- } else {
226
- this . dependencies . push ( "terser-webpack-plugin" ) ;
227
- this . configuration . config . topScope . push (
228
- tooltip . terser ( ) ,
229
- "const TerserPlugin = require('terser-webpack-plugin');" ,
230
- "\n"
231
- ) ;
232
221
}
233
- this . configuration . config . webpackOptions . optimization = getDefaultOptimization ( this . usingDefaults ) ;
234
- this . configuration . config . webpackOptions . mode = this . usingDefaults ? "'development'" : "'production'" ;
235
222
223
+ // TerserPlugin
224
+ this . dependencies . push ( "terser-webpack-plugin" ) ;
225
+ this . configuration . config . topScope . push (
226
+ tooltip . terser ( ) ,
227
+ "const TerserPlugin = require('terser-webpack-plugin');" ,
228
+ "\n"
229
+ ) ;
230
+
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: false,
238
+ })` ) ;
239
+
240
+ // Chunksplitting
241
+ this . configuration . config . webpackOptions . optimization = getDefaultOptimization ( this . usingDefaults ) ;
242
+ this . configuration . config . webpackOptions . mode = this . usingDefaults ? "'production'" : "'development'" ;
236
243
done ( ) ;
237
244
}
238
245
@@ -250,15 +257,15 @@ export default class InitGenerator extends Generator {
250
257
this . config . set ( "configuration" , this . configuration ) ;
251
258
252
259
const packageJsonTemplatePath = "./templates/package.json.js" ;
253
- this . fs . extendJSON ( this . destinationPath ( "package.json" ) , require ( packageJsonTemplatePath ) ( this . isProd ) ) ;
260
+ this . fs . extendJSON ( this . destinationPath ( "package.json" ) , require ( packageJsonTemplatePath ) ( this . usingDefaults ) ) ;
254
261
255
262
const generateEntryFile = ( entryPath : string , name : string ) : void => {
256
263
entryPath = entryPath . replace ( / ' / g, "" ) ;
257
264
this . fs . copyTpl ( path . resolve ( __dirname , "./templates/index.js" ) , this . destinationPath ( entryPath ) , { name } ) ;
258
265
} ;
259
266
260
267
// Generate entry file/files
261
- const entry = this . configuration . config . webpackOptions . entry ;
268
+ const entry = this . configuration . config . webpackOptions . entry || "./src/index.js" ;
262
269
if ( typeof entry === "string" ) {
263
270
generateEntryFile ( entry , "your main file!" ) ;
264
271
} else if ( typeof entry === "object" ) {
@@ -268,6 +275,15 @@ export default class InitGenerator extends Generator {
268
275
// Generate README
269
276
this . fs . copyTpl ( path . resolve ( __dirname , "./templates/README.md" ) , this . destinationPath ( "README.md" ) , { } ) ;
270
277
278
+ // Generate HTML template file
279
+ if ( this . usingDefaults ) {
280
+ this . fs . copyTpl (
281
+ path . resolve ( __dirname , "./templates/template.html" ) ,
282
+ this . destinationPath ( "index.html" ) ,
283
+ { }
284
+ ) ;
285
+ }
286
+
271
287
// Genrate tsconfig
272
288
if ( this . langType === LangType . Typescript ) {
273
289
const tsConfigTemplatePath = "./templates/tsconfig.json.js" ;
0 commit comments