next.config.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import { I18NextHMRPlugin } from 'i18next-hmr/plugin';
  2. import { WebpackManifestPlugin } from 'webpack-manifest-plugin';
  3. import { i18n, localePath } from './src/next-i18next.config';
  4. import { listScopedPackages } from './src/utils/next.config.utils';
  5. // define transpiled packages for '@growi/*'
  6. const scopedPackages = listScopedPackages(['@growi']);
  7. const withTM = require('next-transpile-modules')(scopedPackages);
  8. // define additional entries
  9. const additionalWebpackEntries = {
  10. boot: './src/client/boot',
  11. };
  12. /** @type {import('next').NextConfig} */
  13. const nextConfig = {
  14. reactStrictMode: true,
  15. typescript: {
  16. tsconfigPath: 'tsconfig.build.client.json',
  17. },
  18. pageExtensions: ['page.tsx', 'page.ts', 'page.jsx', 'page.js'],
  19. i18n,
  20. /** @param config {import('next').NextConfig} */
  21. webpack(config, options) {
  22. // Avoid "Module not found: Can't resolve 'fs'"
  23. // See: https://stackoverflow.com/a/68511591
  24. if (!options.isServer) {
  25. config.resolve.fallback.fs = false;
  26. }
  27. // See: https://webpack.js.org/configuration/externals/
  28. // This provides a way of excluding dependencies from the output bundles
  29. config.externals.push('dtrace-provider');
  30. // configure additional entries
  31. const orgEntry = config.entry;
  32. config.entry = () => {
  33. return orgEntry().then((entry) => {
  34. return { ...entry, ...additionalWebpackEntries };
  35. });
  36. };
  37. config.plugins.push(
  38. new WebpackManifestPlugin({
  39. fileName: 'custom-manifest.json',
  40. }),
  41. );
  42. // setup i18next-hmr
  43. if (!options.isServer && options.dev) {
  44. config.plugins.push(new I18NextHMRPlugin({ localesDir: localePath }));
  45. }
  46. return config;
  47. },
  48. };
  49. module.exports = withTM(nextConfig);