Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/kind-ducks-sniff.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"create-webpack-app": feat
---

Covert templates to ECMA modules syntax.
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
{
"version": "1.0.0",

"description": "My webpack project",

"name": "webpack-project",
"type": "module",
"scripts": {
"build": "webpack --mode=production --config-node-env=production",
"build:dev": "webpack --mode=development",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
module.exports = {
import autoprefixer from "autoprefixer";

export default {
// Add you postcss configuration here
// Learn more about it at https://github.com/webpack-contrib/postcss-loader#config-files
plugins: [["autoprefixer"]],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,34 +1,37 @@
// Generated using webpack-cli https://github.com/webpack/webpack-cli

const path = require('path');<% if (htmlWebpackPlugin) { %>
const HtmlWebpackPlugin = require('html-webpack-plugin');<% } %><% if (extractPlugin !== 'No') { %>
const MiniCssExtractPlugin = require('mini-css-extract-plugin');<% } %><% if (workboxWebpackPlugin) { %>
const WorkboxWebpackPlugin = require('workbox-webpack-plugin');<% } %>
import path from "node:path";
import { fileURLToPath } from "node:url";<% if (htmlWebpackPlugin) { %>
import HtmlWebpackPlugin from "html-webpack-plugin";<% } %><% if (extractPlugin !== "No") { %>
import MiniCssExtractPlugin from "mini-css-extract-plugin";<% } %><% if (workboxWebpackPlugin) { %>
import WorkboxWebpackPlugin from "workbox-webpack-plugin";<% } %>

const isProduction = process.env.NODE_ENV === 'production';
<% if (cssType !== 'none') { %>
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const isProduction = process.env.NODE_ENV === "production";
<% if (cssType !== "none") { %>
<% if (extractPlugin === "Yes") { %>
const stylesHandler = MiniCssExtractPlugin.loader;
<% } else if (extractPlugin === "Only for Production") { %>
const stylesHandler = isProduction ? MiniCssExtractPlugin.loader : 'style-loader';
const stylesHandler = isProduction ? MiniCssExtractPlugin.loader : "style-loader";
<% } else { %>
const stylesHandler = 'style-loader';
const stylesHandler = "style-loader";
<% } %>
<% } %>

/** @type {import("webpack").Configuration} */
const config = {
entry: '<%= entryPoint %>',
entry: "<%= entryPoint %>",
output: {
path: path.resolve(__dirname, 'dist'),
path: path.resolve(__dirname, "dist"),
},<% if (devServer) { %>
devServer: {
open: true,
host: 'localhost',
host: "localhost",
},<% } %>
plugins: [<% if (htmlWebpackPlugin) { %>
new HtmlWebpackPlugin({
template: 'index.html',
template: "index.html",
}),
<% } %><% if (extractPlugin === "Yes") { %>
new MiniCssExtractPlugin(),
Expand All @@ -40,63 +43,63 @@ const config = {
rules: [<% if (langType == "ES6") { %>
{
test: /\.(js|jsx)$/i,
loader: 'babel-loader',
loader: "babel-loader",
},<% } %><% if (langType == "Typescript") { %>
{
test: /\.(ts|tsx)$/i,
loader: 'ts-loader',
exclude: ['/node_modules/'],
loader: "ts-loader",
exclude: ["/node_modules/"],
},<% } %><% if (isCSS && !isPostCSS) { %>
{
test: /\.css$/i,
use: [stylesHandler,'css-loader'],
},<% } %><% if (cssType == 'SASS') { %>
use: [stylesHandler,"css-loader"],
},<% } %><% if (cssType == "SASS") { %>
{
test: /\.s[ac]ss$/i,
use: [stylesHandler, 'css-loader', <% if (isPostCSS) { %>'postcss-loader', <% } %>'sass-loader'],
},<% } %><% if (cssType == 'LESS') { %>
use: [stylesHandler, "css-loader", <% if (isPostCSS) { %>"postcss-loader", <% } %>"sass-loader"],
},<% } %><% if (cssType == "LESS") { %>
{
test: /\.less$/i,
use: [stylesHandler, 'css-loader', <% if (isPostCSS) { %>'postcss-loader', <% } %>'less-loader'],
},<% } %><% if (cssType == 'Stylus') { %>
use: [stylesHandler, "css-loader", <% if (isPostCSS) { %>"postcss-loader", <% } %>"less-loader"],
},<% } %><% if (cssType == "Stylus") { %>
{
test: /\.styl$/i,
use: [stylesHandler, 'css-loader', <% if (isPostCSS) { %>'postcss-loader', <% } %>'stylus-loader'],
use: [stylesHandler, "css-loader", <% if (isPostCSS) { %>"postcss-loader", <% } %>"stylus-loader"],
},<% } %><% if (isPostCSS && isCSS) { %>
{
test: /\.css$/i,
use: [stylesHandler, 'css-loader', 'postcss-loader'],
use: [stylesHandler, "css-loader", "postcss-loader"],
},<% } %>
{
test: /\.(eot|svg|ttf|woff|woff2|png|jpg|gif)$/i,
type: 'asset',
type: "asset",
},
%><% if (htmlWebpackPlugin) { %>
{
test: /\.html$/i,
use: ['html-loader'],
use: ["html-loader"],
},<% } %>

// Add your rules for custom modules here
// Learn more about loaders from https://webpack.js.org/loaders/
],
},<% if (langType == "Typescript") {%>
resolve: {
extensions: ['.tsx', '.ts', '.jsx', '.js', '...'],
extensions: [".tsx", ".ts", ".jsx", ".js", "..."],
},<% } %>
};

module.exports = () => {
export default () => {
if (isProduction) {
config.mode = 'production';
config.mode = "production";
<% if (extractPlugin === "Only for Production") { %>
config.plugins.push(new MiniCssExtractPlugin());
<% } %>
<% if (workboxWebpackPlugin) { %>
config.plugins.push(new WorkboxWebpackPlugin.GenerateSW());
<% } %>
} else {
config.mode = 'development';
config.mode = "development";
}
return config;
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"version": "1.0.0",
"description": "My webpack project",
"name": "my-webpack-project",
"type": "module",
"scripts": {
"build": "webpack --mode=production --config-node-env=production",
"build:dev": "webpack --mode=development",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,34 +1,37 @@
// Generated using webpack-cli https://github.com/webpack/webpack-cli

const path = require('path');<% if (htmlWebpackPlugin) { %>
const HtmlWebpackPlugin = require('html-webpack-plugin');<% } %><% if (extractPlugin !== 'No') { %>
const MiniCssExtractPlugin = require('mini-css-extract-plugin');<% } %><% if (workboxWebpackPlugin) { %>
const WorkboxWebpackPlugin = require('workbox-webpack-plugin');<% } %>
import path from "node:path";
import { fileURLToPath } from "node:url";<% if (htmlWebpackPlugin) { %>
import HtmlWebpackPlugin from "html-webpack-plugin";<% } %><% if (extractPlugin !== "No") { %>
import MiniCssExtractPlugin from "mini-css-extract-plugin";<% } %><% if (workboxWebpackPlugin) { %>
import WorkboxWebpackPlugin from "workbox-webpack-plugin";<% } %>

const isProduction = process.env.NODE_ENV === 'production';
<% if (cssType !== 'none') { %>
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const isProduction = process.env.NODE_ENV === "production";
<% if (cssType !== "none") { %>
<% if (extractPlugin === "Yes") { %>
const stylesHandler = MiniCssExtractPlugin.loader;
<% } else if (extractPlugin === "Only for Production") { %>
const stylesHandler = isProduction ? MiniCssExtractPlugin.loader : 'style-loader';
const stylesHandler = isProduction ? MiniCssExtractPlugin.loader : "style-loader";
<% } else { %>
const stylesHandler = 'style-loader';
const stylesHandler = "style-loader";
<% } %>
<% } %>

/** @type {import("webpack").Configuration} */
const config = {
entry: '<%= entry %>',
entry: "<%= entry %>",
output: {
path: path.resolve(__dirname, 'dist'),
path: path.resolve(__dirname, "dist"),
},<% if (devServer) { %>
devServer: {
open: true,
host: 'localhost',
host: "localhost",
},<% } %>
plugins: [<% if (htmlWebpackPlugin) { %>
new HtmlWebpackPlugin({
template: 'index.html',
template: "index.html",
}),
<% } %><% if (extractPlugin === "Yes") { %>
new MiniCssExtractPlugin(),
Expand All @@ -50,32 +53,32 @@ const config = {
},<% } %><% if (langType == "Typescript") { %>
{
test: /\.(ts|tsx)$/i,
loader: 'ts-loader',
exclude: ['/node_modules/'],
loader: "ts-loader",
exclude: ["/node_modules/"],
},<% } %><% if (isCSS && !isPostCSS) { %>
{
test: /\.css$/i,
use: [stylesHandler,'css-loader'],
},<% } %><% if (cssType == 'SASS') { %>
use: [stylesHandler,"css-loader"],
},<% } %><% if (cssType == "SASS") { %>
{
test: /\.s[ac]ss$/i,
use: [stylesHandler, 'css-loader', <% if (isPostCSS) { %>'postcss-loader', <% } %>'sass-loader'],
},<% } %><% if (cssType == 'LESS') { %>
use: [stylesHandler, "css-loader", <% if (isPostCSS) { %>"postcss-loader", <% } %>"sass-loader"],
},<% } %><% if (cssType == "LESS") { %>
{
test: /\.less$/i,
use: [stylesHandler, 'css-loader', <% if (isPostCSS) { %>'postcss-loader', <% } %>'less-loader'],
},<% } %><% if (cssType == 'Stylus') { %>
use: [stylesHandler, "css-loader", <% if (isPostCSS) { %>"postcss-loader", <% } %>"less-loader"],
},<% } %><% if (cssType == "Stylus") { %>
{
test: /\.styl$/i,
use: [stylesHandler, 'css-loader', <% if (isPostCSS) { %>'postcss-loader', <% } %>'stylus-loader'],
use: [stylesHandler, "css-loader", <% if (isPostCSS) { %>"postcss-loader", <% } %>"stylus-loader"],
},<% } %><% if (isPostCSS && isCSS) { %>
{
test: /\.css$/i,
use: [stylesHandler, 'css-loader', 'postcss-loader'],
use: [stylesHandler, "css-loader", "postcss-loader"],
},<% } %>
{
test: /\.(eot|svg|ttf|woff|woff2|png|jpg|gif)$/i,
type: 'asset',
type: "asset",
},

// Add your rules for custom modules here
Expand All @@ -86,21 +89,21 @@ const config = {
alias: {
"@": path.resolve(__dirname, "./src/"),
},
extensions: ['.jsx', '.js'<% if (langType === 'Typescript') { %>, '.tsx', '.ts'<% } %>],
extensions: [".jsx", ".js"<% if (langType === "Typescript") { %>, ".tsx", ".ts"<% } %>],
},
};

module.exports = () => {
export default () => {
if (isProduction) {
config.mode = 'production';
config.mode = "production";
<% if (extractPlugin === "Only for Production") { %>
config.plugins.push(new MiniCssExtractPlugin());
<% } %>
<% if (workboxWebpackPlugin) { %>
config.plugins.push(new WorkboxWebpackPlugin.GenerateSW());
<% } %>
} else {
config.mode = 'development';
config.mode = "development";
}
return config;
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"version": "1.0.0",
"description": "My webpack project",
"name": "my-webpack-project",
"type": "module",
"scripts": {
"build": "webpack --mode=production --config-node-env=production",
"build:dev": "webpack --mode=development",
Expand Down
Loading
Loading