Skip to content

Commit 418f434

Browse files
refactor(init): update tests and format the template to remove extra line
1 parent 35458fb commit 418f434

2 files changed

Lines changed: 8 additions & 42 deletions

File tree

packages/create-webpack-app/templates/init/default/webpack.config.tpl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
// Generated using webpack-cli https://github.com/webpack/webpack-cli
22

33
import path from "node:path";
4-
import { fileURLToPath } from "node:url";
5-
<% if (langType === "Typescript") { %>import { Configuration } from "webpack";
6-
<% if (devServer) { %>import "webpack-dev-server";<% } %><% } %>
7-
<% if (htmlWebpackPlugin) { %>import HtmlWebpackPlugin from "html-webpack-plugin";<% } %><% if (extractPlugin !== "No") { %>
4+
import { fileURLToPath } from "node:url";<% if (langType === "Typescript") { %>
5+
import { Configuration } from "webpack";<% if (devServer) { %>
6+
import "webpack-dev-server";<% } %><% } %><% if (htmlWebpackPlugin) { %>
7+
import HtmlWebpackPlugin from "html-webpack-plugin";<% } %><% if (extractPlugin !== "No") { %>
88
import MiniCssExtractPlugin from "mini-css-extract-plugin";<% } %><% if (workboxWebpackPlugin) { %>
99
import WorkboxWebpackPlugin from "workbox-webpack-plugin";<% } %>
1010

@@ -90,9 +90,9 @@ const config <% if (langType === "Typescript") { %>: Configuration<% } %>= {
9090

9191
export default () => {
9292
if (isProduction) {
93-
config.mode = "production";
94-
<% if (extractPlugin === "Only for Production") { %>config.plugins!.push(new MiniCssExtractPlugin());<% } %>
95-
<% if (workboxWebpackPlugin) { %>config.plugins!.push(new WorkboxWebpackPlugin.GenerateSW());<% } %>
93+
config.mode = "production";<% if (extractPlugin === "Only for Production") { %>
94+
config.plugins!.push(new MiniCssExtractPlugin());<% } %><% if (workboxWebpackPlugin) { %>
95+
config.plugins!.push(new WorkboxWebpackPlugin.GenerateSW());<% } %>
9696
} else {
9797
config.mode = "development";
9898
}

test/create-webpack-app/init/__snapshots__/init.test.js.snap.webpack5

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,6 @@ exports[`create-webpack-app cli should configure WDS as opted 2`] = `
7272
import path from "node:path";
7373
import { fileURLToPath } from "node:url";
7474

75-
76-
7775
const __filename = fileURLToPath(import.meta.url);
7876
const __dirname = path.dirname(__filename);
7977
const isProduction = process.env.NODE_ENV === "production";
@@ -109,8 +107,6 @@ const config = {
109107
export default () => {
110108
if (isProduction) {
111109
config.mode = "production";
112-
113-
114110
} else {
115111
config.mode = "development";
116112
}
@@ -144,7 +140,6 @@ exports[`create-webpack-app cli should configure html-webpack-plugin as opted 2`
144140

145141
import path from "node:path";
146142
import { fileURLToPath } from "node:url";
147-
148143
import HtmlWebpackPlugin from "html-webpack-plugin";
149144

150145
const __filename = fileURLToPath(import.meta.url);
@@ -187,8 +182,6 @@ const config = {
187182
export default () => {
188183
if (isProduction) {
189184
config.mode = "production";
190-
191-
192185
} else {
193186
config.mode = "development";
194187
}
@@ -223,7 +216,6 @@ exports[`create-webpack-app cli should configure workbox-webpack-plugin as opted
223216

224217
import path from "node:path";
225218
import { fileURLToPath } from "node:url";
226-
227219
import HtmlWebpackPlugin from "html-webpack-plugin";
228220
import WorkboxWebpackPlugin from "workbox-webpack-plugin";
229221

@@ -267,7 +259,6 @@ const config = {
267259
export default () => {
268260
if (isProduction) {
269261
config.mode = "production";
270-
271262
config.plugins!.push(new WorkboxWebpackPlugin.GenerateSW());
272263
} else {
273264
config.mode = "development";
@@ -304,8 +295,6 @@ exports[`create-webpack-app cli should generate ES6 project correctly 2`] = `
304295
import path from "node:path";
305296
import { fileURLToPath } from "node:url";
306297

307-
308-
309298
const __filename = fileURLToPath(import.meta.url);
310299
const __dirname = path.dirname(__filename);
311300
const isProduction = process.env.NODE_ENV === "production";
@@ -342,8 +331,6 @@ const config = {
342331
export default () => {
343332
if (isProduction) {
344333
config.mode = "production";
345-
346-
347334
} else {
348335
config.mode = "development";
349336
}
@@ -380,7 +367,6 @@ exports[`create-webpack-app cli should generate default project when nothing is
380367

381368
import path from "node:path";
382369
import { fileURLToPath } from "node:url";
383-
384370
import HtmlWebpackPlugin from "html-webpack-plugin";
385371
import WorkboxWebpackPlugin from "workbox-webpack-plugin";
386372

@@ -427,7 +413,6 @@ const config = {
427413
export default () => {
428414
if (isProduction) {
429415
config.mode = "production";
430-
431416
config.plugins!.push(new WorkboxWebpackPlugin.GenerateSW());
432417
} else {
433418
config.mode = "development";
@@ -465,7 +450,6 @@ exports[`create-webpack-app cli should generate default project when nothing is
465450

466451
import path from "node:path";
467452
import { fileURLToPath } from "node:url";
468-
469453
import HtmlWebpackPlugin from "html-webpack-plugin";
470454
import WorkboxWebpackPlugin from "workbox-webpack-plugin";
471455

@@ -512,7 +496,6 @@ const config = {
512496
export default () => {
513497
if (isProduction) {
514498
config.mode = "production";
515-
516499
config.plugins!.push(new WorkboxWebpackPlugin.GenerateSW());
517500
} else {
518501
config.mode = "development";
@@ -548,7 +531,6 @@ exports[`create-webpack-app cli should generate default project when nothing is
548531

549532
import path from "node:path";
550533
import { fileURLToPath } from "node:url";
551-
552534
import HtmlWebpackPlugin from "html-webpack-plugin";
553535
import WorkboxWebpackPlugin from "workbox-webpack-plugin";
554536

@@ -595,7 +577,6 @@ const config = {
595577
export default () => {
596578
if (isProduction) {
597579
config.mode = "production";
598-
599580
config.plugins!.push(new WorkboxWebpackPlugin.GenerateSW());
600581
} else {
601582
config.mode = "development";
@@ -633,7 +614,6 @@ exports[`create-webpack-app cli should generate default project when nothing is
633614

634615
import path from "node:path";
635616
import { fileURLToPath } from "node:url";
636-
637617
import HtmlWebpackPlugin from "html-webpack-plugin";
638618
import WorkboxWebpackPlugin from "workbox-webpack-plugin";
639619

@@ -680,7 +660,6 @@ const config = {
680660
export default () => {
681661
if (isProduction) {
682662
config.mode = "production";
683-
684663
config.plugins!.push(new WorkboxWebpackPlugin.GenerateSW());
685664
} else {
686665
config.mode = "development";
@@ -718,7 +697,6 @@ exports[`create-webpack-app cli should generate default project when nothing is
718697

719698
import path from "node:path";
720699
import { fileURLToPath } from "node:url";
721-
722700
import HtmlWebpackPlugin from "html-webpack-plugin";
723701
import WorkboxWebpackPlugin from "workbox-webpack-plugin";
724702

@@ -765,7 +743,6 @@ const config = {
765743
export default () => {
766744
if (isProduction) {
767745
config.mode = "production";
768-
769746
config.plugins!.push(new WorkboxWebpackPlugin.GenerateSW());
770747
} else {
771748
config.mode = "development";
@@ -1076,7 +1053,6 @@ exports[`create-webpack-app cli should generate typescript project correctly 1`]
10761053
"description": "My webpack project",
10771054
"devDependencies": {
10781055
"ts-loader": "x.x.x",
1079-
"ts-node": "x.x.x",
10801056
"typescript": "x.x.x",
10811057
"webpack": "x.x.x",
10821058
"webpack-cli": "x.x.x",
@@ -1097,9 +1073,7 @@ exports[`create-webpack-app cli should generate typescript project correctly 2`]
10971073

10981074
import path from "node:path";
10991075
import { fileURLToPath } from "node:url";
1100-
import { Configuration } from "webpack";
1101-
1102-
1076+
import { Configuration } from "webpack";
11031077

11041078
const __filename = fileURLToPath(import.meta.url);
11051079
const __dirname = path.dirname(__filename);
@@ -1141,8 +1115,6 @@ const config : Configuration= {
11411115
export default () => {
11421116
if (isProduction) {
11431117
config.mode = "production";
1144-
1145-
11461118
} else {
11471119
config.mode = "development";
11481120
}
@@ -1308,8 +1280,6 @@ exports[`create-webpack-app cli should use css preprocessor and css with postcss
13081280

13091281
import path from "node:path";
13101282
import { fileURLToPath } from "node:url";
1311-
1312-
13131283
import MiniCssExtractPlugin from "mini-css-extract-plugin";
13141284

13151285
const __filename = fileURLToPath(import.meta.url);
@@ -1356,7 +1326,6 @@ export default () => {
13561326
if (isProduction) {
13571327
config.mode = "production";
13581328
config.plugins!.push(new MiniCssExtractPlugin());
1359-
13601329
} else {
13611330
config.mode = "development";
13621331
}
@@ -1396,8 +1365,6 @@ exports[`create-webpack-app cli should use to use css preprocessor with postcss
13961365

13971366
import path from "node:path";
13981367
import { fileURLToPath } from "node:url";
1399-
1400-
14011368
import MiniCssExtractPlugin from "mini-css-extract-plugin";
14021369

14031370
const __filename = fileURLToPath(import.meta.url);
@@ -1440,7 +1407,6 @@ export default () => {
14401407
if (isProduction) {
14411408
config.mode = "production";
14421409
config.plugins!.push(new MiniCssExtractPlugin());
1443-
14441410
} else {
14451411
config.mode = "development";
14461412
}

0 commit comments

Comments
 (0)