-
Notifications
You must be signed in to change notification settings - Fork 6
/
webpack.rules.js
164 lines (153 loc) · 3.32 KB
/
webpack.rules.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
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/*
* Copyright (c) 2020, Max Klein
*
* This file is part of the tree-finder library, distributed under the terms of
* the BSD 3 Clause license. The full license can be found in the LICENSE file.
*/
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const path = require("path");
const TerserPlugin = require("terser-webpack-plugin");
const cssLoader = () => {return {
loader: "css-loader",
options: {
importLoaders: 1,
import: true,
modules: {
localIdentName: "[local]", //"[path][name]__[local]--[hash:base64:5]",
// compileType: "module",
// mode: "local",
// auto: true,
// exportGlobals: true,
// localIdentContext: path.resolve(__dirname, "src"),
// localIdentHashPrefix: "my-custom-hash",
// namedExport: true,
// exportLocalsConvention: "camelCase",
// exportOnlyLocals: false,
},
},
};}
// const postCssLoader = () => {return {
// loader: "postcss-loader",
// ...(process.env.NODE_ENV === "production") && {options: {
// postcssOptions: {
// minimize: true,
// plugins: [
// cssnano({
// preset: "lite"
// }),
// ],
// },
// }},
// };}
// load bitmap image rules
const bitmapRules = [
{
test: /\.(jpg|png|gif)$/,
use: "file-loader"
},
];
// load dependency source maps
const dependencySrcMapRules = [
{
test: /\.js$/,
use: "source-map-loader",
enforce: "pre",
exclude: /node_modules/,
},
{test: /\.js.map$/, use: "file-loader"},
];
// rules to cover all of pure/modules css/less
const stylingRules = [
{
test: /\.module\.css$/,
use: [
cssLoader(),
],
},
{
test: /(?<!\.module)\.css$/,
use: [
// "style-loader",
MiniCssExtractPlugin.loader,
cssLoader(),
],
},
{
test: /\.module\.less$/,
use: [
cssLoader(),
// "postcss-loader",
"less-loader",
],
},
{
test: /(?<!\.module)\.less$/,
use: [
// "style-loader",
MiniCssExtractPlugin.loader,
cssLoader(),
// "postcss-loader",
"less-loader",
],
},
];
// load svg via css url() rules
const svgUrlRules = [
{
test: /\.svg(\?v=\d+\.\d+\.\d+)?$/,
use: {
loader: "svg-url-loader",
options: {encoding: "none", limit: 10000},
},
},
];
const tsRules = [
{
test: /\.tsx?$/,
exclude: /node_modules/,
use: {
loader: "ts-loader",
options: {
transpileOnly: false, // Set to true if you are using fork-ts-checker-webpack-plugin
projectReferences: true
},
},
},
]
const getContext = (dir) => { return {
// context: path.resolve(dir),
};}
const getOptimization = () => { return {
minimizer: [
// "...",
new TerserPlugin({
// turn off license gen
terserOptions: {
format: {
comments: false,
},
},
// turn off license gen
extractComments: false,
}),
new CssMinimizerPlugin(),
],
};}
const getResolve = (dir) => { return {
modules: [
"node_modules",
path.resolve(dir),
],
extensions: [".tsx", ".ts", ".jsx", ".js", ".less", ".css"],
};}
module.exports = {
bitmapRules,
dependencySrcMapRules,
stylingRules,
svgUrlRules,
tsRules,
getContext,
getOptimization,
getResolve,
};