This repository has been archived by the owner on Apr 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathwebpack.config.js
118 lines (109 loc) · 3 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
const path = require('path');
const webpack = require('webpack');
const CopyPlugin = require('copy-webpack-plugin');
const {version} = require('./package.json');
const minimize = true;
module.exports = {
mode: 'production',
performance: {
maxEntrypointSize: 1e10,
maxAssetSize: 1e10,
},
optimization: {
minimize: minimize,
},
module: {
rules: [
{
test: /\.(png|jpg|gif)$/i,
use: [
{
loader: 'url-loader',
},
],
type: 'javascript/auto',
},
{
test: /\.css$/i,
use: [
{
loader: 'style-loader',
options: {
insert: function insertAtTop(element) {
let parent = window.gmStyles;
if (parent == null) {
window.gmStyles = document.createElement('div');
parent = window.gmStyles;
};
// eslint-disable-next-line no-underscore-dangle
const lastInsertedElement =
window._lastElementInsertedByStyleLoader;
if (!lastInsertedElement) {
parent.insertBefore(element, parent.firstChild);
} else if (lastInsertedElement.nextSibling) {
parent.insertBefore(element, lastInsertedElement.nextSibling);
} else {
parent.appendChild(element);
}
// eslint-disable-next-line no-underscore-dangle
window._lastElementInsertedByStyleLoader = element;
},
},
},
'css-loader',
],
},
{
test: /\.(xml|html)$/i,
use: 'raw-loader',
},
{
test: /\.(woff|woff2|eot|ttf|otf)$/i,
type: 'asset/inline',
},
{
test: /\.(raw\.js)$/i,
use: minimize ? [
{
loader: path.resolve('./minify-loader.js'),
},
] : undefined,
type: 'asset/source',
},
],
},
plugins: [
new webpack.optimize.LimitChunkCountPlugin({
maxChunks: 1,
}),
new CopyPlugin({
patterns: [
{from: 'src/icons', to: 'icons'},
{from: 'src/rules.json', to: 'rules.json'},
{
from: 'src/manifest.json',
to: 'manifest.json',
transform: (content) => {
const jsonContent = JSON.parse(content);
jsonContent.version = version.replace(/-.+/, '');
return JSON.stringify(jsonContent, null, 2);
},
},
],
}),
],
entry: {
'js/injector': './src/inject/injector.js',
'js/gmLoader': './src/inject/gmLoader.js',
'background': './src/background.js',
'css/style': './src/gmWindow/style.css',
'js/loadInjector': './src/inject/loadInjector.js',
'js/runInjectors': './src/inject/runInjectors.js',
},
output: {
hashFunction: 'xxhash64',
chunkFormat: 'array-push',
filename: '[name].js',
path: path.resolve(__dirname, 'dist'),
},
};