PromucFlow_constructor/app/client/craco.build.config.js
Diljit 4cb6ff03f9
chore: Prefetch module apis in service worker (#34003)
## Description
This PR has the following changes
- Modify the prefetch api cache strategy to handle multiple prefetch
requests.
- Convert the service worker files from js to ts
- Code splitting of CE and EE for service worker utils to handle EE
specific changes
- Jest test cases for the updated logic


Fixes #`Issue Number`  
_or_  
Fixes `Issue URL`
> [!WARNING]  
> _If no issue exists, please create an issue first, and check with the
maintainers if the issue is valid._

## Automation

/ok-to-test tags="@tag.All"

### 🔍 Cypress test results
<!-- This is an auto-generated comment: Cypress test results  -->
> [!TIP]
> 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/9511154598>
> Commit: 785197e27873e71ed457f785a73d4ea57f379213
> Cypress dashboard url: <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=9511154598&attempt=1"
target="_blank">Click here!</a>

<!-- end of auto-generated comment: Cypress test results  -->





















## Communication
Should the DevRel and Marketing teams inform users about this change?
- [ ] Yes
- [ ] No


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **New Features**
- Enhanced API request handling with new utility functions and caching
strategies for service worker operations.
- Updated service worker configuration to TypeScript for improved type
safety and maintainability.
- Added type definitions for `node-fetch` to support new service worker
functionalities.

- **Refactor**
- Consolidated `view` and `edit` endpoint URL construction in
`ConsolidatedPageLoadApi` for better code maintainability.

- **Chores**
- Updated dependencies in `package.json` for better development
experience and compatibility.
- Added tests for new service worker utility functions to ensure
reliability and correctness.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2024-06-14 16:30:23 +05:30

115 lines
3.6 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/* eslint-disable @typescript-eslint/no-var-requires */
const SentryWebpackPlugin = require("@sentry/webpack-plugin");
const { merge } = require("webpack-merge");
const common = require("./craco.common.config.js");
const WorkboxPlugin = require("workbox-webpack-plugin");
const CompressionPlugin = require("compression-webpack-plugin");
const { RetryChunkLoadPlugin } = require("webpack-retry-chunk-load-plugin");
const path = require("path");
const env = process.env.REACT_APP_ENVIRONMENT;
const isAirgap = process.env.REACT_APP_AIRGAP_ENABLED;
const plugins = [];
plugins.push(
new WorkboxPlugin.InjectManifest({
swSrc: "./src/serviceWorker.ts",
mode: "development",
swDest: "./pageService.js",
maximumFileSizeToCacheInBytes: 11 * 1024 * 1024,
exclude: [
// Dont cache source maps and PWA manifests.
// (These are the default values of the `exclude` option: https://developer.chrome.com/docs/workbox/reference/workbox-build/#type-WebpackPartial,
// so we need to specify them explicitly if were extending this array.)
/\.map$/,
/^manifest.*\.js$/,
// Dont cache the root html file
/index\.html/,
// Dont cache LICENSE.txt files emitted by CRA
// when a chunk includes some license comments
/LICENSE\.txt/,
// Dont cache static icons as there are hundreds of them, and caching them all
// one by one (as the service worker does it) keeps the network busy for a long time
// and delays the service worker installation
/\/*\.svg$/,
],
// Dont cache-bust JS and CSS chunks
dontCacheBustURLsMatching: /\.[0-9a-zA-Z]{8}\.chunk\.(js|css)$/,
}),
);
if (env === "PRODUCTION" || env === "STAGING") {
if (
process.env.SENTRY_AUTH_TOKEN != null &&
process.env.SENTRY_AUTH_TOKEN !== ""
) {
plugins.push(
new SentryWebpackPlugin({
include: "build",
ignore: ["node_modules", "webpack.config.js"],
release: process.env.REACT_APP_SENTRY_RELEASE,
deploy: {
env: process.env.REACT_APP_SENTRY_ENVIRONMENT,
},
}),
);
} else {
console.log(
"Sentry configuration missing in process environment. Sentry will be disabled.",
);
}
}
plugins.push(new CompressionPlugin());
plugins.push(
new CompressionPlugin({
algorithm: "brotliCompress",
filename: "[path][base].br",
test: /\.(js|css|html|svg)$/,
threshold: 10240,
minRatio: 0.8,
}),
);
plugins.push(
new RetryChunkLoadPlugin({
// optional value to set the amount of time in milliseconds before trying to load the chunk again. Default is 0
retryDelay: 3000,
// optional value to set the maximum number of retries to load the chunk. Default is 1
maxRetries: 2,
// optional code to be executed in the browser context if after all retries chunk is not loaded.
// if not set - nothing will happen and error will be returned to the chunk loader.
lastResortScript: "window.location.href='/404.html';",
}),
);
module.exports = merge(common, {
webpack: {
configure: {
plugins,
},
},
jest: {
configure: {
moduleNameMapper: {
// Jest module mapper which will detect our absolute imports.
"^@test(.*)$": "<rootDir>/test$1",
},
},
},
plugins: [
// Enable Airgap builds
{
plugin: {
overrideWebpackConfig: ({ context: { env, paths }, webpackConfig }) => {
if (env.REACT_APP_AIRGAP_ENABLED === "true" || isAirgap === "true") {
paths.appBuild = webpackConfig.output.path =
path.resolve("build_airgap");
}
return webpackConfig;
},
},
},
],
});