-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebpack.config.js
89 lines (78 loc) · 2.36 KB
/
webpack.config.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
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
// https://github.com/webdiscus/html-bundler-webpack-plugin
const path = require("path");
const HtmlBundlerPlugin = require("html-bundler-webpack-plugin");
module.exports = (env, argv) => {
const isDev = argv.mode === "development";
const config = {
mode: isDev ? "development" : "production",
devtool: isDev ? "inline-source-map" : "source-map",
stats: "minimal",
output: {
path: path.join(__dirname, "./dist_webpack"),
publicPath: "/static/",
},
resolve: {
alias: {},
extensions: [".js", ".jsx", ".ts", ".tsx"],
},
watchOptions: {
// Ignore changes in these folders when running `npm run dev`
ignored: [path.join(__dirname, "mesads/templates/django")],
},
plugins: [
new HtmlBundlerPlugin({
verbose: false, // output information about the process to console in development mode only
entry: path.join(__dirname, "mesads/templates/webpack"),
js: {
// output filename of extracted JS from source script loaded in HTML via `<script>` tag
filename: "assets/js/[name].[contenthash:8].js",
},
css: {
// output filename of extracted CSS from source style loaded in HTML via `<link>` tag
filename: "assets/css/[name].[contenthash:8].css",
},
}),
],
module: {
rules: [
{
test: /\.tsx?$/,
use: "ts-loader",
exclude: /node_modules/,
},
// styles
{
test: /\.(css|sass|scss)$/,
use: ["css-loader", "sass-loader"],
},
// images (load from `images` directory only)
{
test: /[\\/]images[\\/].+(png|jpe?g|svg|webp|ico)$/,
oneOf: [
// inline image using `?inline` query
{
resourceQuery: /inline/,
type: "asset/inline",
},
// auto inline by image size
{
type: "asset",
parser: {
dataUrlCondition: {
maxSize: 1024,
},
},
generator: {
filename: "assets/img/[name].[hash:8][ext]",
},
},
],
},
],
},
performance: {
hints: false, // don't show the size limit warning when a bundle is bigger than 250 KB
},
};
return config;
};