-
Notifications
You must be signed in to change notification settings - Fork 20
/
webpack.config.js
148 lines (136 loc) · 5.49 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
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
const path = require('path');
const glob = require('glob');
const CopyPlugin = require('copy-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const webpack = require('webpack');
const resolve = require('path').resolve;
const CHROME_KEY =
'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAmf6qYyrFypvvB0klM/hHhIdGO0bAnUT6ZK4fLqGl8/l5OWze2leeQkC/Nf0HOTQ50d2sdgXFuQDfHsMF+HQ5pUVIUT/25MzEXZWGwqi+JAxEX9Q/yGFFN53nI4m7mGNzCQ0TDUS3IrJsFfQBMEdv/fAwnhEitF/Ko9qn8/KYDzZqIjujwXKKeqlx+UXIvkgblI44RT9evwiqp+/WjZZ/YQzLa9tFhdz0Ct3Qvhn/03YrLAXa+yxXKpLAjQJ9DpYJoa++bJwluffinxKQUX0tm5dzFRSRKFCG92hKHnQHcQFUnBlDKF4LS0KQhgelyiTxN4GmKX7I1xQS/B1TByLL2wIDAQAB';
function getPathEntries(path) {
return glob.sync(path).reduce((acc, e) => {
if (!e.includes('node_modules')) {
// Remove extension
acc[e.replace(/\.[^/.]+$/, '')] = e;
}
return acc;
}, {});
}
function convertToFirefoxManifest(manifest) {
const cp = Object.assign({}, manifest);
cp.background = {
page: 'src/background_ff.html',
};
cp.browser_specific_settings = {
gecko: {
id: '{194d0dc6-7ada-41c6-88b8-95d7636fe43c}',
strict_min_version: '109.0',
},
};
// Allow getting the extension version from CSFloat page in Firefox
cp.content_scripts.push({
matches: ['*://*.csfloat.com/*'],
js: ['src/lib/page_scripts/csfloat.js'],
});
cp.host_permissions.push('*://*.csfloat.com/*');
return cp;
}
module.exports = (env) => {
const mode = env.mode || 'development';
return {
mode: 'none',
entry: Object.assign(
getPathEntries('./src/lib/page_scripts/*.ts'),
getPathEntries('./src/lib/types/*.d.ts'),
getPathEntries('./src/background.ts'),
getPathEntries('./src/**/*.js')
),
output: {
path: path.join(__dirname, 'dist'),
filename: '[name].js',
},
resolve: {
extensions: ['.ts', '.js', '.html'],
},
module: {
rules: [
{
test: /\.ts$/,
loader: 'ts-loader',
exclude: /node_modules|\.d\.ts$/,
},
{
test: /\.d\.ts$/,
loader: 'ignore-loader',
},
{
test: new RegExp(`.(css)$`),
loader: 'file-loader',
options: {
name: '[name].[ext]',
},
exclude: /node_modules/,
},
{
test: /environment\.ts$/,
loader: 'file-replace-loader',
options: {
condition: mode === 'development',
replacement: resolve('./src/environment.dev.ts'),
},
},
],
},
plugins: [
new MiniCssExtractPlugin(),
new webpack.SourceMapDevToolPlugin({}),
new CopyPlugin({
patterns: [
{from: 'icons', to: 'icons', context: '.'},
{from: 'src/global.css', to: 'src/', context: '.'},
{from: 'src/background_ff.html', to: 'src/', context: '.'},
{from: 'src/steamcommunity_ruleset.json', to: 'src/', context: '.'},
{from: 'src', to: 'raw/', context: '.'},
{from: 'README.md', to: '', context: '.'},
{
from: 'manifest.json',
to: 'manifest.json',
transform(raw) {
let processed = JSON.parse(raw.toString());
if (mode === 'development' && env.browser === 'chrome') {
processed.key = CHROME_KEY;
}
if (mode === 'development') {
// Add permissions only used for connecting to localhost dev env
processed.host_permissions.push('http://localhost:8080/*');
const versionResource = processed.web_accessible_resources.find((e) =>
e.resources[0].includes('version.txt')
);
versionResource.matches.push('http://localhost:4200/*');
processed.externally_connectable.matches.push('http://localhost/*');
processed.externally_connectable.matches.push('http://localhost:4200/*');
}
if (env.browser === 'firefox') {
processed = convertToFirefoxManifest(processed);
}
return JSON.stringify(processed, null, 2);
},
},
{
from: 'manifest.json',
to: 'src/version.txt',
transform(raw) {
let processed = JSON.parse(raw.toString());
return processed.version;
},
},
],
}),
],
stats: {
errorDetails: true,
},
optimization: {
usedExports: true,
},
};
};