forked from generativefm/generative.fm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.prod.config.js
54 lines (48 loc) · 1.54 KB
/
webpack.prod.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
'use strict';
const OfflinePlugin = require('offline-plugin');
const fetchSampleSpec = require('@generative-music/samples.generative.fm/node-client');
const {
version,
} = require('@generative-music/samples.generative.fm/package.json');
const config = require('./webpack.config');
config.mode = 'production';
delete config.devtool;
const getConfig = fetchSampleSpec().then(spec => {
const { samples } = spec;
const sampleFilenames = Reflect.ownKeys(samples).reduce(
(filenames, instrumentName) => {
const instrumentSamplesByFormat = samples[instrumentName];
return filenames.concat(
Reflect.ownKeys(instrumentSamplesByFormat).reduce(
(instrumentSampleFilenames, format) => {
const formatSamples = instrumentSamplesByFormat[format];
if (Array.isArray(formatSamples)) {
return instrumentSampleFilenames.concat(formatSamples);
}
return instrumentSampleFilenames.concat(
Object.values(formatSamples)
);
},
[]
)
);
},
[`https://samples.generative.fm/index.${version}.json`]
);
config.plugins.push(
new OfflinePlugin({
appShell: '/',
externals: sampleFilenames.concat(['favicon.ico', 'manifest.json']),
autoUpdate: true,
ServiceWorker: {
events: true,
},
caches: {
main: [':rest:'],
optional: sampleFilenames,
},
})
);
return config;
});
module.exports = getConfig;