-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.common.js
More file actions
128 lines (125 loc) · 3.43 KB
/
webpack.common.js
File metadata and controls
128 lines (125 loc) · 3.43 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import path, { dirname } from 'path';
import { CleanWebpackPlugin } from 'clean-webpack-plugin';
import Dotenv from 'dotenv-webpack';
import HtmlWebPackPlugin from'html-webpack-plugin';
import FaviconsWebpackPlugin from 'favicons-webpack-plugin';
import MiniCssExtractPlugin from 'mini-css-extract-plugin';
import { fileURLToPath } from 'url';
import { glob } from 'glob';
import getMinifiedClassName from './getMinifiedClassName.js';
const __dirname = dirname(fileURLToPath(import.meta.url));
const config = (mode) => ({
mode: mode,
entry: './src/index.tsx',
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'bundle.js',
publicPath: '/',
},
resolve: {
extensions: [".tsx", ".ts", ".js"],
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: ["babel-loader"],
},
{
test: /\.(ts|tsx)$/,
exclude: /node_modules/,
use: ["babel-loader", "ts-loader"],
},
{
test: /\.html$/,
use: [
{
loader: 'html-loader',
},
],
},
{
test: /\.(sass|scss)$/,
use: [
MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: {
modules: {
mode: 'local',
namedExport: false,
auto: true,
...((mode === 'production') ? {
getLocalIdent: (context, localIdentName, localName) => (
getMinifiedClassName(localName, context.resourcePath)
),
}: {
localIdentName: '[name]__[local]--[hash:base64:5]',
}),
exportLocalsConvention: 'dashes',
}
}
},
{
loader: 'postcss-loader',
options: {
postcssOptions: {
plugins: [
[
'@fullhuman/postcss-purgecss',
{
content: [
`${path.join(__dirname, "src")}/index.html`,
...glob.sync(`${path.join(__dirname, "src")}/**/*.tsx`, { nodir: true }),
],
variables: true,
safelist: {
deep: [/custom-/],
},
},
]
],
}
}
},
{
loader: 'sass-loader',
options: {
sourceMap: true,
},
},
],
},
{
test: /\.svg$/i,
type: 'asset',
resourceQuery: { not: [/react/] }, // exclude react component if *.svg?react
},
{
test: /\.svg$/i,
issuer: /\.[jt]sx?$/,
resourceQuery: /react/, // *.svg?react
use: ['@svgr/webpack'],
},
{
test: /\.(png|jpg|gif|ico)$/i,
type: 'asset/resource',
},
],
},
plugins: [
new CleanWebpackPlugin(),
new Dotenv({ prefix: 'import.meta.env.', systemvars: true }),
new HtmlWebPackPlugin({
template: './src/index.html',
filename: './index.html',
}),
new FaviconsWebpackPlugin({ logo: './public/favicon.svg', mode: 'webapp', devMode: 'light'}),
new MiniCssExtractPlugin({
filename: '[name].css',
chunkFilename: '[id].css',
}),
],
});
export default config;