ente/web/packages/next/next.config.base.js
Manav Rathi 9eab93cfdf
Suppress webpack's critical dependency warnings for libheif
Supressing it for now since it obscures other important information in the console.

Upstream issue, which currently doesn't have a workaround:
https://github.com/catdad-experiments/libheif-js/issues/23

Full error message:

     ⚠ ../../node_modules/libheif-js/libheif-wasm/libheif-bundle.js
    Critical dependency: require function is used in a way in which dependencies cannot be statically extracted

    Import trace for requested module:
    ../../node_modules/libheif-js/libheif-wasm/libheif-bundle.js
    ../../node_modules/libheif-js/wasm-bundle.js
    ../../node_modules/heic-decode/index.js
    ../../node_modules/heic-convert/index.js
    ./src/worker/convert.worker.ts
    ./src/utils/comlink/ComlinkConvertWorker.ts
    ./src/services/heic-convert/service.ts
    ...

Refs:
- https://stackoverflow.com/questions/38392697/webpack-umd-critical-dependency-cannot-be-statically-extracted
2024-04-15 13:47:46 +05:30

82 lines
2.7 KiB
JavaScript

// @ts-check
/**
* @file Configure the Next.js build
*
* This file gets used by the Next.js build phase, and is not included in the
* browser build. It will not be parsed by Webpack, Babel or TypeScript, so
* don't use features that will not be available in our target node version.
*
* https://nextjs.org/docs/pages/api-reference/next-config-js
*/
const cp = require("child_process");
const os = require("os");
/**
* Return the current commit ID if we're running inside a git repository.
*/
const gitSHA = () => {
// Allow the command to fail. gitSHA will be an empty string in such cases.
// This allows us to run the build even when we're outside of a git context.
//
// The /dev/null redirection is needed so that we don't print error messages
// if someone is trying to run outside of a git context. Since the way to
// redirect output and ignore failure is different on Windows, the command
// needs to be OS specific.
const command =
os.platform() == "win32"
? "git rev-parse --short HEAD 2> NUL || cd ."
: "git rev-parse --short HEAD 2>/dev/null || true";
const result = cp
.execSync(command, {
cwd: __dirname,
encoding: "utf8",
})
.trimEnd();
// Convert empty strings (e.g. when the `|| true` part of the above execSync
// comes into play) to undefined.
return result ? result : undefined;
};
/**
* Configuration for the Next.js build
*
* @type {import("next").NextConfig}
*/
const nextConfig = {
// Generate a static export when we run `next build`.
output: "export",
compiler: {
emotion: true,
},
// Use Next.js to transpile our internal packages before bundling them.
transpilePackages: ["@/next", "@/utils"],
// Add environment variables to the JavaScript bundle. They will be
// available as `process.env.VAR_NAME` to our code.
env: {
GIT_SHA: gitSHA(),
},
// Customize the webpack configuration used by Next.js
webpack: (config, { isServer }) => {
// https://dev.to/marcinwosinek/how-to-add-resolve-fallback-to-webpack-5-in-nextjs-10-i6j
if (!isServer) {
config.resolve.fallback.fs = false;
}
// Suppress the warning "Critical dependency: require function is used
// in a way in which dependencies cannot be statically extracted" when
// import heic-convert.
//
// Upstream issue, which currently doesn't have a workaround.
// https://github.com/catdad-experiments/libheif-js/issues/23
config.ignoreWarnings = [{ module: /libheif-js/ }];
return config;
},
};
module.exports = nextConfig;