-
Notifications
You must be signed in to change notification settings - Fork 10
/
webpack.config.js
95 lines (94 loc) · 2.75 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
90
91
92
93
94
95
const LodashModuleReplacementPlugin = require("lodash-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const CssMinimizerPlugin = require("css-minimizer-webpack-plugin");
const path = require("path");
module.exports = (env, argv) => {
const config = {
entry: "./csm_web/frontend/src/index.tsx",
output: {
path: path.resolve(__dirname, "./csm_web/frontend/static/frontend/")
},
resolve: {
extensions: [".tsx", ".ts", ".js", ".json", ".css", ".scss", ".sass"]
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
include: path.resolve(__dirname, "./csm_web/frontend/src/"),
use: {
loader: "babel-loader"
}
},
{
test: /\.tsx?$/,
exclude: /node_modules/,
include: path.resolve(__dirname, "./csm_web/frontend/src/"),
use: {
loader: "babel-loader"
}
},
{
test: /\.svg$/,
include: [
path.resolve(__dirname, "./csm_web/frontend/static/frontend/"),
path.resolve(__dirname, "./csm_web/frontend/templates/frontend/")
],
use: [
{
loader: "@svgr/webpack",
// Always inline styles into svg attributes because <style> tags would violate our CSP
options: {
svgoConfig: {
plugins: [
{
name: "preset-default",
params: {
overrides: {
inlineStyles: { onlyMatchedOnce: false }
}
}
}
]
}
}
}
]
},
{
// scss, sass, css
test: /\.s[ac]ss$|\.css$/i,
include: [
path.resolve(__dirname, "./csm_web/frontend/src/css/"),
path.resolve(__dirname, "./csm_web/frontend/templates/frontend/")
],
sideEffects: true,
use: [
{
loader: MiniCssExtractPlugin.loader,
options: {
publicPath: "./csm_web/frontend/static/frontend/css/"
}
},
"css-loader",
"sass-loader"
]
}
]
},
optimization: {
minimizer: ["...", new CssMinimizerPlugin()]
},
watchOptions: {
poll: 1000,
ignored: /node_modules/
},
plugins: [new LodashModuleReplacementPlugin(), new MiniCssExtractPlugin()],
externals: { react: "React", "react-dom": "ReactDOM" }
};
if (argv.mode === "development") {
config.devtool = "eval-source-map";
}
return config;
};