next.config.js 2.1 KB

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