58 lines
2.1 KiB
JavaScript
58 lines
2.1 KiB
JavaScript
const webpack = require('webpack');
|
|
const WorkBoxPlugin = require('workbox-webpack-plugin');
|
|
|
|
// Fail the build loudly when an API base is missing, instead of emitting a
|
|
// bundle in which every request URL is the string "undefined/orders/..." —
|
|
// a relative path that silently resolves against whatever host the console is
|
|
// served from. That produced a deploy where the API base appeared to be the
|
|
// front-end's own origin. Only enforced for production builds; `npm start`
|
|
// is left alone.
|
|
const REQUIRED_PROD_ENV = ['REACT_APP_URL', 'REACT_APP_URL2', 'REACT_APP_URL3'];
|
|
|
|
function assertRequiredEnv() {
|
|
if (process.env.NODE_ENV !== 'production') return;
|
|
const missing = REQUIRED_PROD_ENV.filter((k) => !process.env[k]);
|
|
if (!missing.length) return;
|
|
throw new Error(
|
|
`\n\nBuild aborted — missing required environment variable(s): ${missing.join(', ')}.\n` +
|
|
'Define them in .env (loaded by every build) or build via `npm run build:staging` / `build:dev`,\n' +
|
|
'which load .env.staging / .env.development through env-cmd.\n'
|
|
);
|
|
}
|
|
|
|
module.exports = function override(config) {
|
|
assertRequiredEnv();
|
|
|
|
config.resolve.fallback = {
|
|
process: require.resolve('process/browser'),
|
|
// zlib: require.resolve('browserify-zlib'),
|
|
stream: require.resolve('stream-browserify'),
|
|
crypto: require.resolve('crypto-browserify'),
|
|
util: require.resolve('util'),
|
|
buffer: require.resolve('buffer')
|
|
// asset: require.resolve('assert')
|
|
};
|
|
|
|
// https://stackoverflow.com/questions/69135310/workaround-for-cache-size-limit-in-create-react-app-pwa-service-worker
|
|
config.plugins.forEach((plugin) => {
|
|
if (plugin instanceof WorkBoxPlugin.InjectManifest) {
|
|
plugin.config.maximumFileSizeToCacheInBytes = 50 * 1024 * 1024;
|
|
}
|
|
});
|
|
|
|
// Disable ESLint plugin in Webpack so lint warnings never block compilation
|
|
config.plugins = config.plugins.filter(
|
|
(plugin) => plugin.constructor && plugin.constructor.name !== 'ESLintWebpackPlugin'
|
|
);
|
|
|
|
config.plugins = [
|
|
...config.plugins,
|
|
new webpack.ProvidePlugin({
|
|
process: 'process/browser.js',
|
|
Buffer: ['buffer', 'Buffer']
|
|
})
|
|
];
|
|
|
|
return config;
|
|
};
|