memories/webpack.js

95 lines
3.0 KiB
JavaScript
Raw Normal View History

2022-08-14 20:54:18 +00:00
const webpackConfig = require('@nextcloud/webpack-vue-config')
2022-10-17 02:52:44 +00:00
const WorkboxPlugin = require('workbox-webpack-plugin')
2022-09-13 01:33:24 +00:00
const path = require('path')
2022-10-17 02:52:44 +00:00
const buildMode = process.env.NODE_ENV
const isDev = buildMode === 'development'
2022-09-13 01:33:24 +00:00
webpackConfig.module.rules.push({
test: /\.ts?$/,
loader: 'ts-loader',
exclude: /node_modules/,
options: {
appendTsSuffixTo: [/\.vue$/],
},
});
webpackConfig.resolve.extensions.push('.ts');
webpackConfig.resolve.alias = {
'vue$': 'vue/dist/vue.esm.js',
}
webpackConfig.entry.main = path.resolve(path.join('src', 'main'));
2022-08-14 20:54:18 +00:00
2022-10-15 19:21:53 +00:00
webpackConfig.watchOptions = {
ignored: /node_modules/,
aggregateTimeout: 300,
};
2022-10-17 02:52:44 +00:00
if (!isDev) {
2022-11-22 08:12:06 +00:00
const imageCacheOpts = (expiryDays) => ({
handler: 'CacheFirst',
options: {
cacheName: 'images',
expiration: {
maxAgeSeconds: 3600 * 24 * expiryDays, // days
maxEntries: 20000, // 20k images
},
},
});
2022-10-17 02:52:44 +00:00
webpackConfig.plugins.push(
new WorkboxPlugin.GenerateSW({
swDest: 'memories-service-worker.js',
clientsClaim: true,
skipWaiting: true,
exclude: [new RegExp('.*')], // don't do precaching
inlineWorkboxRuntime: true,
sourcemap: false,
// Define runtime caching rules.
runtimeCaching: [{
2022-11-29 22:28:10 +00:00
// Do not cache transcoded video files
urlPattern: /^.*\/apps\/memories\/api\/video\/transcode\/.*/,
2022-11-22 08:12:06 +00:00
handler: 'NetworkOnly',
}, {
// Do not cache raw editing files
urlPattern: /^.*\/apps\/memories\/api\/image\/jpeg\/.*/,
handler: 'NetworkOnly',
}, {
// Do not cache webdav
urlPattern: /^.*\/remote.php\/.*/,
handler: 'NetworkOnly',
}, {
// Do not cache downloads
urlPattern: /^.*\/apps\/files\/ajax\/download.php?.*/,
handler: 'NetworkOnly',
}, {
2022-12-03 05:04:31 +00:00
// Preview file request
urlPattern: /^.*\/apps\/memories\/api\/image\/preview\/.*/,
2022-11-22 08:12:06 +00:00
...imageCacheOpts(7),
2022-11-29 22:28:10 +00:00
}, {
// Live photo videos
urlPattern: /^.*\/apps\/memories\/api\/video\/livephoto\/.*/,
...imageCacheOpts(7),
2022-11-22 08:12:06 +00:00
}, {
// Face previews from Memories
urlPattern: /^.*\/apps\/memories\/api\/faces\/preview\/.*/,
...imageCacheOpts(1),
2022-10-17 02:52:44 +00:00
}, {
// Match page requests
urlPattern: /^.*\/.*$/,
handler: 'NetworkFirst',
options: {
cacheName: 'pages',
expiration: {
maxAgeSeconds: 3600 * 24 * 7, // one week
maxEntries: 2000, // assets
},
},
}],
})
);
}
2022-08-14 20:54:18 +00:00
module.exports = webpackConfig