11// Generated using webpack-cli https://github.com/webpack/webpack-cli
22
33import path from "node:path";
4- import { fileURLToPath } from "node:url";<% if (htmlWebpackPlugin) { %>
4+ import { fileURLToPath } from "node:url";<% if (langType === "Typescript") { %>
5+ import { type Configuration } from "webpack";<% if (devServer) { %>
6+ import " webpack-dev-server" ;<% } %><% } %><% if (htmlWebpackPlugin) { %>
57import HtmlWebpackPlugin from " html-webpack-plugin" ;<% } %><% if (extractPlugin !== "No") { %>
68import MiniCssExtractPlugin from " mini-css-extract-plugin" ;<% } %><% if (workboxWebpackPlugin) { %>
79import WorkboxWebpackPlugin from " workbox-webpack-plugin" ;<% } %>
810
911const __filename = fileURLToPath(import.meta.url);
1012const __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- <% } %>
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 { %>
16+ const stylesHandler = " style-loader" ;<% } %><% } %>
2117
2218/** @type { import(" webpack" ).Configuration} */
23- const config = {
19+ const config <% if (langType === "Typescript") { %> : Configuration <% } %> = {
2420 entry: " <%= entry %>" ,
2521 output: {
2622 path: path.resolve(__dirname, " dist" ),
@@ -31,10 +27,8 @@ const config = {
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 ],
@@ -108,13 +102,9 @@ const config = {
108102
109103export default () => {
110104 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- <% } %>
105+ config.mode = " production" ;<% if (extractPlugin === " Only for Production" ) { %>
106+ config.plugins?.push(new MiniCssExtractPlugin());<% } %><% if (workboxWebpackPlugin) { %>
107+ config.plugins?.push(new WorkboxWebpackPlugin.GenerateSW());<% } %>
118108 } else {
119109 config.mode = " development" ;
120110 }
0 commit comments