-
Notifications
You must be signed in to change notification settings - Fork 2
/
webpack.config.js
127 lines (125 loc) · 3.4 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
const {Compilation, sources} = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const FaviconsWebpackPlugin = require('favicons-webpack-plugin');
const {GenerateSW} = require('workbox-webpack-plugin');
const RobotsTxtPlugin = require('robotstxt-webpack-plugin');
/** @typedef {import('webpack').Compiler} Compiler */
class AddMaskableIcons {
/**
* @param {Compiler} compiler
*/
apply(compiler) {
compiler.hooks.thisCompilation.tap(AddMaskableIcons.name, compilation => {
compilation.hooks.processAssets.tap(
{
name: AddMaskableIcons.name,
stage: Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE,
},
() => {
for (const file of Object.keys(compilation.assets)) {
if (!/manifest/.test(file)) continue;
const contents = compilation.getAsset(file);
const json = JSON.parse(contents.source.source());
const maskables = json.icons.map(i => ({...i, purpose: 'maskable'}));
json.icons.push(...maskables);
compilation.updateAsset(
file,
new sources.RawSource(JSON.stringify(json)),
)
}
}
)
});
}
}
/** @return {import('webpack').Configuration} */
module.exports = (env, argv) => {
const isDev = argv.mode === 'development';
return {
devtool: 'source-map',
entry: __dirname + '/src/index.tsx',
output: {
path: __dirname + '/dist',
filename: '[name].bundle.js',
publicPath: '',
clean: true,
},
resolve: {
extensions: ['.js', '.tsx', '.ts'],
},
module: {
rules: [
{
test: /\.ts[x]?$/,
loader: 'babel-loader',
exclude: /node_modules/
},
{
test: /\.css$/,
exclude: /node_modules/,
use: ['style-loader', 'css-loader'],
},
{
test: /\.s[ac]ss$/,
exclude: /node_modules/,
use: [
'style-loader',
{
loader: 'css-loader',
options: {
modules: {
localIdentName: isDev ?
'[local]__[hash:base64:5]' :
'[hash:base64]',
}
}
},
'sass-loader'
],
}
]
},
plugins: [
new RobotsTxtPlugin(),
new HtmlWebpackPlugin({
template: __dirname + '/src/index.html',
filename: 'index.html',
inject: 'head',
}),
new FaviconsWebpackPlugin({
logo: __dirname + '/src/logo.svg',
inject: true,
manifest: {
name: 'Card Trader',
short_name: 'Card Trader',
description: 'Interactive card trading app built with React.',
start_url: '/',
theme_color: '#2f2f2f',
background_color: '#1f1f1f',
},
favicons:{
manifestRelativePaths: true,
icons: {
android: {
background: '#1f1f1f',
},
appleIcon: {
background: '#1f1f1f',
},
appleStartup: false,
coast: false,
favicons: true,
firefox: false,
windows: false,
yandex: false,
}
}
}),
new GenerateSW(),
new AddMaskableIcons(),
],
devServer: {
historyApiFallback: true,
}
}
}