forked from Cookie-AutoDelete/Cookie-AutoDelete
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
121 lines (118 loc) · 3.77 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
115
116
117
118
119
120
121
const BundleAnalyzerPlugin =
require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const CopyPlugin = require('copy-webpack-plugin');
const webpack = require('webpack');
module.exports = {
mode: 'production',
entry: {
background: `${__dirname}/src/background.ts`,
popup: `${__dirname}/src/ui/popup/index.tsx`,
setting: `${__dirname}/src/ui/settings/index.tsx`,
},
externals: {
'redux-webext': 'ReduxWebExt',
},
output: {
path: `${__dirname}/extension/bundles`,
filename: `[name].bundle.js`,
},
module: {
rules: [
{
test: /\.tsx?$/,
exclude: /node_modules/,
use: [
{
loader: 'ts-loader',
// options: {
// // this will disable any type checking
// transpileOnly: true,
// },
},
],
},
{ enforce: 'pre', test: /\.js$/, loader: 'source-map-loader' },
],
},
plugins: [
new webpack.BannerPlugin(`
Copyright (c) 2017-2022 Kenny Do and CAD Team (https://github.com/Cookie-AutoDelete/Cookie-AutoDelete/graphs/contributors)
Licensed under MIT (https://github.com/Cookie-AutoDelete/Cookie-AutoDelete/blob/3.X.X-Branch/LICENSE)
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
`),
// new BundleAnalyzerPlugin({
// analyzerMode: 'static',
// }),
new CopyPlugin({
patterns: [
{
force: true,
from: 'bootstrap/dist/css/bootstrap.min.css*',
to: '../../extension/global_files/[name][ext]',
context: `${__dirname}/node_modules`,
},
{
force: true,
from: 'bootstrap/dist/js/bootstrap.bundle.min.js*',
to: '../../extension/global_files/[name][ext]',
context: `${__dirname}/node_modules`,
},
{
force: true,
from: 'jquery/dist/jquery.slim.min*',
to: '../../extension/global_files/[name][ext]',
context: `${__dirname}/node_modules`,
},
{
force: true,
from: 'webextension-polyfill/dist/browser-polyfill.min.js*',
to: '../../extension/global_files/[name][ext]',
context: `${__dirname}/node_modules`,
},
],
}),
],
resolve: {
extensions: ['.mjs', '.tsx', '.ts', '.js', '.json', '.png'],
},
optimization: {
splitChunks: {
automaticNameDelimiter: '-',
cacheGroups: {
ui: {
test: /[\\/]node_modules[\\/](react|react-dom|@fortawesome)[\\/]|[\\/]src[\\/]ui[\\/]/,
priority: -10,
},
common: {
chunks: 'initial',
// cacheGroupKey here is `common` as key of cacheGroup
name: (module, chunks, cacheGroupKey) => {
return [cacheGroupKey, chunks.map((c) => c.runtime).join('-')].join(
'-',
);
},
// Alternate version of above results, only if output.filename stays as [name].bundle.js
// filename: (pathData) => {
// return `common-${
// pathData.runtime.size > 1
// ? Array.from(pathData.runtime).join('-')
// : pathData.runtime
// }.bundle.js`;
// },
priority: -15,
},
default: {
minChunks: 2,
priority: -20,
reuseExistingChunk: true,
},
},
},
},
};