-
-
Notifications
You must be signed in to change notification settings - Fork 36
/
webpack.config.js
114 lines (111 loc) · 3.61 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
const path = require('path');
const CopyPlugin = require('copy-webpack-plugin');
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const RemoveEmptyScriptsPlugin = require('webpack-remove-empty-scripts');
const TerserPlugin = require("terser-webpack-plugin");
const CircularDependencyPlugin = require('circular-dependency-plugin');
const MangleCssClassPlugin = require('mangle-css-class-webpack-plugin');
const fs = require('fs');
/**
* Generates all the entry points needed.
* @returns {{index: string, "styles/calendar": string}}
*/
function getEntries() {
//Default required entry points
const list = {
"index": {import: './src/index.ts'},
"styles/calendar": './src/styles/index.scss'
};
//Get all the additional theme files as entry points
fs.readdirSync('./src/styles/themes/').forEach((file) => {
if(file.endsWith('.scss') && !file.startsWith('_')){
list[`styles/themes/${file.replace('.scss', '')}`] = `./src/styles/themes/${file}`;
}
});
return list;
}
module.exports = {
mode: "production",
entry: getEntries(),
optimization: {
removeEmptyChunks: true,
minimize: true,
minimizer: [new TerserPlugin({
extractComments: false, // To avoid separate file with licenses.
terserOptions: {
ecma: '2020',
mangle: true,
sourceMap: false,
module: true,
keep_classnames: /^(NoteSheet|MainApp)$/,
keep_fnames: false,
toplevel: true,
},
})]
},
plugins: [
new CircularDependencyPlugin({
exclude: /__mocks__|docs|dist|node_modules|\.test\.ts/,
include: /src/,
failOnError: true,
}),
new CopyPlugin({
patterns: [
{ context: './src/', from : '**/*.json', to : './' },
{ context: './src/', from : '**/*.(hbs|html)', to : '[path][name].html' },
{ context: './', from : 'README.md', to : './' },
{ context: './', from : 'LICENSE', to : './' },
{ context: './src/assets', from: '**/*.png', to: './assets/'}
]
}),
new MangleCssClassPlugin({
classNameRegExp: 'fsc-[a-z\-][a-zA-Z0-9_\-]*',
reserveClassName: ['fa', 'fas', 'far'],
ignorePrefix: ['fsc-']
}),
new RemoveEmptyScriptsPlugin(),
new MiniCssExtractPlugin({
filename: "[name].css"
})
],
module: {
rules: [
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/,
},
{
test: /\.s[ac]ss$/i,
use: [
MiniCssExtractPlugin.loader,
// Translates CSS into CommonJS
{
loader: 'css-loader',
options: {
url: { filter: (url, resourcePath) => {return !(url.indexOf('/ui/') > -1);}}
}
},
// Compiles Sass to CSS
'sass-loader'
],
},
{
test: /\.svg$/,
type: 'asset/source'
},
]
},
resolve: {
extensions: ['.tsx', '.ts', '.js'],
},
performance: {
maxEntrypointSize: 512000,
maxAssetSize: 512000
},
output: {
path: path.resolve(__dirname, 'dist'),
filename: '[name].js',
clean: true
},
};