Skip to content

Commit c2c29e8

Browse files
refactor(template): generate a template with less empty lines
1 parent 99ee0b0 commit c2c29e8

4 files changed

Lines changed: 23 additions & 53 deletions

File tree

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

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,9 @@ import WorkboxWebpackPlugin from "workbox-webpack-plugin";<% } %>
1010

1111
const __filename = fileURLToPath(import.meta.url);
1212
const __dirname = path.dirname(__filename);
13-
const isProduction = process.env.NODE_ENV === "production";
14-
<% if (cssType !== "none") { %>
15-
<% if (extractPlugin === "Yes") { %>
16-
const stylesHandler = MiniCssExtractPlugin.loader;
17-
<% } else if (extractPlugin === "Only for Production") { %>
18-
const stylesHandler = isProduction ? MiniCssExtractPlugin.loader : "style-loader";
19-
<% } else { %>
13+
const isProduction = process.env.NODE_ENV === "production";<% if (cssType !== "none") { %><% if (extractPlugin === "Yes") { %>
14+
const stylesHandler = MiniCssExtractPlugin.loader;<% } else if (extractPlugin === "Only for Production") { %>
15+
const stylesHandler = isProduction ? MiniCssExtractPlugin.loader : "style-loader";<% } else { %>
2016
const stylesHandler = "style-loader";<% } %><% } %>
2117

2218
/** @type {import("webpack").Configuration} */
@@ -31,10 +27,8 @@ const config <% if (langType === "Typescript") { %>: Configuration <% } %>= {
3127
plugins: [<% if (htmlWebpackPlugin) { %>
3228
new HtmlWebpackPlugin({
3329
template: "index.html",
34-
}),
35-
<% } %><% if (extractPlugin === "Yes") { %>
36-
new MiniCssExtractPlugin(),
37-
<% } %>
30+
}),<% } %><% if (extractPlugin === "Yes") { %>
31+
new MiniCssExtractPlugin(),<% } %>
3832
// Add your plugins here
3933
// Learn more about plugins from https://webpack.js.org/configuration/plugins/
4034
],

packages/create-webpack-app/templates/init/react/webpack.config.js.tpl renamed to packages/create-webpack-app/templates/init/react/webpack.config.tpl

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,10 @@ import WorkboxWebpackPlugin from "workbox-webpack-plugin";<% } %>
88

99
const __filename = fileURLToPath(import.meta.url);
1010
const __dirname = path.dirname(__filename);
11-
const isProduction = process.env.NODE_ENV === "production";
12-
<% if (cssType !== "none") { %>
13-
<% if (extractPlugin === "Yes") { %>
14-
const stylesHandler = MiniCssExtractPlugin.loader;
15-
<% } else if (extractPlugin === "Only for Production") { %>
16-
const stylesHandler = isProduction ? MiniCssExtractPlugin.loader : "style-loader";
17-
<% } else { %>
18-
const stylesHandler = "style-loader";
19-
<% } %>
20-
<% } %>
11+
const isProduction = process.env.NODE_ENV === "production";<% if (cssType !== "none") { %><% if (extractPlugin === "Yes") { %>
12+
const stylesHandler = MiniCssExtractPlugin.loader;<% } else if (extractPlugin === "Only for Production") { %>
13+
const stylesHandler = isProduction ? MiniCssExtractPlugin.loader : "style-loader";<% } else { %>
14+
const stylesHandler = "style-loader";<% } %><% } %>
2115

2216
/** @type {import("webpack").Configuration} */
2317
const config = {
@@ -31,10 +25,8 @@ const config = {
3125
plugins: [<% if (htmlWebpackPlugin) { %>
3226
new HtmlWebpackPlugin({
3327
template: "index.html",
34-
}),
35-
<% } %><% if (extractPlugin === "Yes") { %>
36-
new MiniCssExtractPlugin(),
37-
<% } %>
28+
}),<% } %><% if (extractPlugin === "Yes") { %>
29+
new MiniCssExtractPlugin(),<% } %>
3830
// Add your plugins here
3931
// Learn more about plugins from https://webpack.js.org/configuration/plugins/
4032
],
@@ -94,13 +86,9 @@ const config = {
9486

9587
export default () => {
9688
if (isProduction) {
97-
config.mode = "production";
98-
<% if (extractPlugin === "Only for Production") { %>
99-
config.plugins.push(new MiniCssExtractPlugin());
100-
<% } %>
101-
<% if (workboxWebpackPlugin) { %>
102-
config.plugins.push(new WorkboxWebpackPlugin.GenerateSW());
103-
<% } %>
89+
config.mode = "production";<% if (extractPlugin === "Only for Production") { %>
90+
config.plugins.push(new MiniCssExtractPlugin());<% } %><% if (workboxWebpackPlugin) { %>
91+
config.plugins.push(new WorkboxWebpackPlugin.GenerateSW());<% } %>
10492
} else {
10593
config.mode = "development";
10694
}

packages/create-webpack-app/templates/init/svelte/webpack.config.js.tpl renamed to packages/create-webpack-app/templates/init/svelte/webpack.config.tpl

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,10 @@ import WorkboxWebpackPlugin from "workbox-webpack-plugin";<% } %>
88

99
const __filename = fileURLToPath(import.meta.url);
1010
const __dirname = path.dirname(__filename);
11-
const isProduction = process.env.NODE_ENV === "production";
12-
<% if (cssType !== "none") { %>
13-
<% if (extractPlugin === "Yes") { %>
14-
const stylesHandler = MiniCssExtractPlugin.loader;
15-
<% } else if (extractPlugin === "Only for Production") { %>
16-
const stylesHandler = isProduction ? MiniCssExtractPlugin.loader : "style-loader";
17-
<% } else { %>
18-
const stylesHandler = "style-loader";
19-
<% } %>
20-
<% } %>
11+
const isProduction = process.env.NODE_ENV === "production";<% if (cssType !== "none") { %><% if (extractPlugin === "Yes") { %>
12+
const stylesHandler = MiniCssExtractPlugin.loader;<% } else if (extractPlugin === "Only for Production") { %>
13+
const stylesHandler = isProduction ? MiniCssExtractPlugin.loader : "style-loader";<% } else { %>
14+
const stylesHandler = "style-loader";<% } %><% } %>
2115

2216
/** @type {import("webpack").Configuration} */
2317
const config = {
@@ -31,10 +25,8 @@ const config = {
3125
plugins: [<% if (htmlWebpackPlugin) { %>
3226
new HtmlWebpackPlugin({
3327
template: "./index.html",
34-
}),
35-
<% } %><% if (extractPlugin === "Yes") { %>
36-
new MiniCssExtractPlugin(),
37-
<% } %>
28+
}),<% } %><% if (extractPlugin === "Yes") { %>
29+
new MiniCssExtractPlugin(),<% } %>
3830
// Add your plugins here
3931
// Learn more about plugins from https://webpack.js.org/configuration/plugins/
4032
],
@@ -108,13 +100,9 @@ const config = {
108100

109101
export default () => {
110102
if (isProduction) {
111-
config.mode = "production";
112-
<% if (extractPlugin === "Only for Production") { %>
113-
config.plugins.push(new MiniCssExtractPlugin());
114-
<% } %>
115-
<% if (workboxWebpackPlugin) { %>
116-
config.plugins.push(new WorkboxWebpackPlugin.GenerateSW());
117-
<% } %>
103+
config.mode = "production";<% if (extractPlugin === "Only for Production") { %>
104+
config.plugins.push(new MiniCssExtractPlugin());<% } %><% if (workboxWebpackPlugin) { %>
105+
config.plugins.push(new WorkboxWebpackPlugin.GenerateSW());<% } %>
118106
} else {
119107
config.mode = "development";
120108
}

packages/create-webpack-app/templates/init/vue/webpack.config.js.tpl renamed to packages/create-webpack-app/templates/init/vue/webpack.config.tpl

File renamed without changes.

0 commit comments

Comments
 (0)