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 13
/
Copy pathwebpack.config.js
137 lines (120 loc) · 3.39 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
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: 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']
},
{
test: /\.(png|woff|woff2|eot|ttf|svg)$/,
loader: 'url-loader',
options: {
limit: 100000
}
}
]
},
devServer: {
open: true,
port: 3000
}
};
const plugins = [
new CleanWebpackPlugin({
cleanStaleWebpackAssets: false
}),
new HtmlWebpackPlugin({
hash: true,
inject: true,
minify: false,
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: ''},
{from: 'node_modules/ionicons/dist/ionicons/svg/', to: 'svg'}
]
}),
new ProgressBarPlugin()
];
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]
}
}
}
]
})
);
plugins.push(new DeckDeckGoInfoPlugin());
if (!argv.notes) {
plugins.push(new DeckDeckGoRemoveNotesPlugin());
}
}
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;
}
processEnv['process.env']['KEEP_HISTORY'] = argv.mode === 'development' || argv.mode === 'local';
plugins.push(new webpack.DefinePlugin(processEnv));
return config;
};