-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.common.js
63 lines (61 loc) · 1.63 KB
/
webpack.common.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
const path = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const { pages } = require("./project.config");
const devMode = process.env.NODE_ENV !== "production";
const filename = devMode ? "[name].js" : "[name].[contenthash].js";
const cssFilename = devMode ? "[name].css" : "[name].[contenthash].css";
module.exports = {
entry: "./main.js",
output: {
path: path.resolve(__dirname, "dist"),
filename: filename,
clean: true,
assetModuleFilename: "assets/[hash][ext][query]",
},
plugins: [
...pages.map((page) => new HtmlWebpackPlugin(page)),
...(devMode ? [] : [new MiniCssExtractPlugin({ filename: cssFilename })]),
],
resolve: {
extensions: [".tsx", ".ts", ".js"],
},
module: {
rules: [
{
test: /\.tsx?$/,
use: "ts-loader",
include: path.resolve(__dirname, "src"),
exclude: /node_modules/,
},
{
test: /\.(sa|sc|c)ss$/i,
use: [
devMode ? "style-loader" : MiniCssExtractPlugin.loader,
"css-loader",
"postcss-loader",
"resolve-url-loader",
{
loader: "sass-loader",
options: {
sourceMap: true,
implementation: require("sass"),
},
},
],
},
{
test: /\.(png|svg|jpg|jpeg|gif|mp3|wav)$/i,
type: "asset/resource",
},
{
test: /\.(json)$/i,
type: "asset/source",
},
{
test: /\.(woff|woff2|eot|ttf|otf)$/i,
type: "asset/resource",
},
],
},
};