This repository has been archived by the owner on Feb 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
webpack.config.js
136 lines (121 loc) · 3.87 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
const {CleanWebpackPlugin} = require('clean-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const {GenerateSW} = require('workbox-webpack-plugin');
const webpack = require('webpack');
const path = require('path');
const config = {
entry: path.resolve(__dirname, 'src', 'index.js'),
output: {
filename: '[name].[chunkhash].js',
path: path.resolve(__dirname, 'dist')
},
module: {
rules: [
{
test: /\.css$/,
use: [
'style-loader',
'css-loader'
]
}
]
},
devServer: {
open: true,
port: 3000,
publicPath: '{{DECKDECKGO_BASE_HREF}}',
openPage: 'http://localhost:3000{{DECKDECKGO_BASE_HREF}}'
}
};
const plugins = [
new CleanWebpackPlugin({
cleanStaleWebpackAssets: false
}),
new HtmlWebpackPlugin({
hash: true,
inject: true,
template: path.resolve(__dirname, 'src', 'index.html'),
path: path.join(__dirname, '../dist/'),
filename: 'index.html'
}),
new CopyWebpackPlugin({
patterns: [
{from: 'src/assets/', to: 'assets'},
{from: 'src/manifest.json', to: ''},
{from: 'src/robots.txt', to: ''}
]
})
];
module.exports = (env, argv) => {
if (argv.mode === 'development' || argv.mode === 'local') {
config.devtool = 'source-map';
}
if (argv.mode === 'production') {
plugins.push(new GenerateSW({
ignoreURLParametersMatching: [/./],
runtimeCaching: [{
urlPattern: new RegExp(/^(?!.*(?:unsplash|giphy|tenor|firebasestorage))(?=.*(?:png|jpg|jpeg|svg|webp|gif)).*/),
handler: 'CacheFirst',
options: {
cacheName: 'images',
expiration: {
maxEntries: 60,
maxAgeSeconds: 30 * 24 * 60 * 60 // 30 days
},
}
},{
urlPattern: new RegExp(/^(?=.*(?:unsplash|giphy|tenor|firebasestorage))(?=.*(?:png|jpg|jpeg|svg|webp|gif)).*/),
handler: 'StaleWhileRevalidate',
options: {
cacheName: 'cors-images',
expiration: {
maxEntries: 60,
maxAgeSeconds: 30 * 24 * 60 * 60 // 30 days
},
cacheableResponse: {
statuses: [0, 200]
}
}
},{
urlPattern: new RegExp(/^https:\/\/fonts\.googleapis\.com/),
handler: 'StaleWhileRevalidate',
options: {
cacheName: 'google-fonts-stylesheets'
}
},{
urlPattern: new RegExp(/^https:\/\/fonts\.gstatic\.com/),
handler: 'CacheFirst',
options: {
cacheName: 'google-fonts-stylesheets',
expiration: {
maxEntries: 310,
maxAgeSeconds: 60 * 60 * 24 * 365 // 365 days
},
}
}]
}));
}
config.plugins = plugins;
let processEnv;
if (env && env.local) {
processEnv = {
'process.env': {
SIGNALING_SERVER: JSON.stringify('http://localhost:3002')
}
};
} else {
processEnv = {
'process.env': {
SIGNALING_SERVER: JSON.stringify('https://api.deckdeckgo.com')
}
};
}
if (env && env.noRemote) {
processEnv['process.env']['NO_REMOTE'] = true;
}
plugins.push(
new webpack.DefinePlugin(processEnv)
);
return config;
};