squash all commits and fix service worker (file has to be at this specific path by convention):

Added pwa subscription storage for publishers
This commit is contained in:
Dobromir Popov
2024-05-07 10:28:54 +03:00
parent 7d1d529037
commit 03dcf5e755
18 changed files with 1053 additions and 288 deletions

View File

@ -1,11 +1,13 @@
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
//we're currently using next-pwa (which uses GeneraeSW automatically), so we don't need to use workbox-webpack-plugin
const { InjectManifest, GenerateSW } = require('workbox-webpack-plugin');
const withPWA = require('next-pwa')({
dest: 'public',
register: true, // ?
publicExcludes: ["!_error*.js"], //?
//disable: process.env.NODE_ENV === 'development',
skipWaiting: true,
// disable: process.env.NODE_ENV === 'development',
})
module.exports = withPWA({
@ -19,26 +21,56 @@ module.exports = withPWA({
compress: false,
pageExtensions: ['ts', 'tsx', 'md', 'mdx'], // Replace `jsx?` with `tsx?`
env: {
env: process.env.NODE_ENV,
env: process.env.APP_ENV,
server: process.env.NEXT_PUBLIC_PUBLIC_URL
},
webpack(config, { isServer }) {
// pwa: {
// dest: 'public',
// register: true,
// publicExcludes: ["!_error*.js"],
// disable: process.env.NODE_ENV === 'development',
// // sw: './worker/index.js', // Custom service worker file name
// },
config.optimization.minimize = true,
productionBrowserSourceMaps = true,
// plugins: [
// // new InjectManifest({
// // // These are some common options, and not all are required.
// // // Consult the docs for more info.
// // //exclude: [/.../, '...'],
// // maximumFileSizeToCacheInBytes: 1 * 1024 * 1024,
// // swSrc: './worker.js',
// // }),
// // new GenerateSW({
// // //disable all files
// // maximumFileSizeToCacheInBytes: 10 * 1024 * 1024,
// // // swSrc: './worker.js',
// // }),
// ],
webpack: (config, { isServer, buildId, dev }) => {
// Configure optimization and source maps
config.optimization.minimize = !dev;
//config.productionBrowserSourceMaps = true;
// Enable source maps based on non-production environments
if (!dev) {
config.devtool = 'source-map';
}
// Add custom fallbacks
config.resolve.fallback = { ...config.resolve.fallback, fs: false };
config.resolve.fallback = {
// InjectManifest configuration
if (!isServer) {
// config.plugins.push(new InjectManifest({
// // swSrc: './worker.js', // Path to source service worker file
// // swDest: '/worker.js', // Destination filename in the build output
// maximumFileSizeToCacheInBytes: 10 * 1024 * 1024, // Adjust as needed
// exclude: [/\.map$/, /_error.js$/, /favicon.ico$/] // Customize exclusion patterns
// })
// );
}
// if you miss it, all the other options in fallback, specified
// by next.js will be dropped.
...config.resolve.fallback,
fs: false, // the solution
};
// Only run the bundle analyzer for production builds and when the ANALYZE environment variable is set
// Bundle Analyzer Configuration
if (process.env.ANALYZE && !isServer) {
//const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
config.plugins.push(
new BundleAnalyzerPlugin({
analyzerMode: 'static',