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 7
/
Copy pathwebpack.config.js
114 lines (101 loc) · 2.79 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
const {CleanWebpackPlugin} = require('clean-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const ProgressBarPlugin = require('progress-bar-webpack-plugin');
const {DeckDeckGoInfoPlugin, DeckDeckGoRemoveNotesPlugin} = require('deckdeckgo-webpack-plugins');
const {GenerateSW} = require('workbox-webpack-plugin');
const webpack = require('webpack');
const path = require('path');
const config = {
entry: './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
}
};
const plugins = [
new CleanWebpackPlugin({
cleanStaleWebpackAssets: false
}),
new HtmlWebpackPlugin({
hash: true,
inject: true,
template: './src/index.html',
path: path.join(__dirname, '../dist/'),
filename: 'index.html',
minify: false
}),
new CopyWebpackPlugin({
patterns: [
{from: 'src/assets/', to: 'assets'},
{from: 'src/manifest.json', to: ''},
{from: 'src/robots.txt', to: ''},
{from: 'node_modules/ionicons/dist/ionicons/svg/', to: 'svg'}
]
}),
new ProgressBarPlugin()
];
module.exports = (env, argv) => {
if (argv.mode === 'development') {
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]
}
}
}
]
})
);
plugins.push(new DeckDeckGoInfoPlugin());
if (!argv.notes) {
plugins.push(new DeckDeckGoRemoveNotesPlugin());
}
}
plugins.push(
new webpack.DefinePlugin({
'process.env': {
SIGNALING_SERVER: JSON.stringify('https://api.deckdeckgo.com')
}
})
);
config.plugins = plugins;
return config;
};