@@ -363,6 +363,170 @@ const WorkboxWebpackPlugin = require('workbox-webpack-plugin');
363363const isProduction = process.env.NODE_ENV === 'production';
364364
365365
366+ /** @type {import("webpack").Configuration} */
367+ const config = {
368+ entry: './src/index.js',
369+ output: {
370+ path: path.resolve(__dirname, 'dist'),
371+ },
372+ devServer: {
373+ open: true,
374+ host: 'localhost',
375+ },
376+ plugins: [
377+ new HtmlWebpackPlugin({
378+ template: 'index.html',
379+ }),
380+
381+ // Add your plugins here
382+ // Learn more about plugins from https://webpack.js.org/configuration/plugins/
383+ ],
384+ module: {
385+ rules: [
386+ {
387+ test: /\\.(eot|svg|ttf|woff|woff2|png|jpg|gif)$/i,
388+ type: 'asset',
389+ },
390+
391+ {
392+ test: /\\.html$/i,
393+ use: ['html-loader'],
394+ },
395+
396+ // Add your rules for custom modules here
397+ // Learn more about loaders from https://webpack.js.org/loaders/
398+ ],
399+ },
400+ };
401+
402+ module.exports = () => {
403+ if (isProduction) {
404+ config.mode = 'production';
405+
406+
407+ config.plugins.push(new WorkboxWebpackPlugin.GenerateSW());
408+
409+ } else {
410+ config.mode = 'development';
411+ }
412+ return config;
413+ };
414+ "
415+ `;
416+
417+ exports[`create-webpack-app cli should generate default project when nothing is passed and handle conflicts 1`] = `
418+ {
419+ "description": "My webpack project",
420+ "devDependencies": {
421+ "html-loader": "x.x.x",
422+ "html-webpack-plugin": "x.x.x",
423+ "webpack": "x.x.x",
424+ "webpack-cli": "x.x.x",
425+ "webpack-dev-server": "x.x.x",
426+ "workbox-webpack-plugin": "x.x.x",
427+ },
428+ "name": "webpack-project",
429+ "scripts": {
430+ "build": "webpack --mode=production --config-node-env=production",
431+ "build:dev": "webpack --mode=development",
432+ "serve": "webpack serve",
433+ "watch": "webpack --watch",
434+ },
435+ "version": "1.0.0",
436+ }
437+ `;
438+
439+ exports[`create-webpack-app cli should generate default project when nothing is passed and handle conflicts 2`] = `
440+ "// Generated using webpack-cli https://github.com/webpack/webpack-cli
441+
442+ const path = require('path');
443+ const HtmlWebpackPlugin = require('html-webpack-plugin');
444+ const WorkboxWebpackPlugin = require('workbox-webpack-plugin');
445+
446+ const isProduction = process.env.NODE_ENV === 'production';
447+
448+
449+ /** @type {import("webpack").Configuration} */
450+ const config = {
451+ entry: './src/index.js',
452+ output: {
453+ path: path.resolve(__dirname, 'dist'),
454+ },
455+ devServer: {
456+ open: true,
457+ host: 'localhost',
458+ },
459+ plugins: [
460+ new HtmlWebpackPlugin({
461+ template: 'index.html',
462+ }),
463+
464+ // Add your plugins here
465+ // Learn more about plugins from https://webpack.js.org/configuration/plugins/
466+ ],
467+ module: {
468+ rules: [
469+ {
470+ test: /\\.(eot|svg|ttf|woff|woff2|png|jpg|gif)$/i,
471+ type: 'asset',
472+ },
473+
474+ {
475+ test: /\\.html$/i,
476+ use: ['html-loader'],
477+ },
478+
479+ // Add your rules for custom modules here
480+ // Learn more about loaders from https://webpack.js.org/loaders/
481+ ],
482+ },
483+ };
484+
485+ module.exports = () => {
486+ if (isProduction) {
487+ config.mode = 'production';
488+
489+
490+ config.plugins.push(new WorkboxWebpackPlugin.GenerateSW());
491+
492+ } else {
493+ config.mode = 'development';
494+ }
495+ return config;
496+ };
497+ "
498+ `;
499+
500+ exports[`create-webpack-app cli should generate default project when nothing is passed and handle conflicts 3`] = `
501+ {
502+ "description": "My webpack project",
503+ "devDependencies": {
504+ "@babel/core": "x.x.x",
505+ "@babel/preset-env": "x.x.x",
506+ "babel-loader": "x.x.x",
507+ "webpack": "x.x.x",
508+ "webpack-cli": "x.x.x",
509+ },
510+ "name": "webpack-project",
511+ "scripts": {
512+ "build": "webpack --mode=production --config-node-env=production",
513+ "build:dev": "webpack --mode=development",
514+ "watch": "webpack --watch",
515+ },
516+ "version": "1.0.0",
517+ }
518+ `;
519+
520+ exports[`create-webpack-app cli should generate default project when nothing is passed and handle conflicts 4`] = `
521+ "// Generated using webpack-cli https://github.com/webpack/webpack-cli
522+
523+ const path = require('path');
524+ const HtmlWebpackPlugin = require('html-webpack-plugin');
525+ const WorkboxWebpackPlugin = require('workbox-webpack-plugin');
526+
527+ const isProduction = process.env.NODE_ENV === 'production';
528+
529+
366530/** @type {import("webpack").Configuration} */
367531const config = {
368532 entry: './src/index.js',
0 commit comments