next-intlayer 1.0.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/README.md +199 -0
  2. package/dist/cjs/client/index.cjs +17 -23
  3. package/dist/cjs/client/index.cjs.map +1 -1
  4. package/dist/cjs/client/index.d.ts +3 -10
  5. package/dist/cjs/client/useLocale.cjs +13 -20
  6. package/dist/cjs/client/useLocale.cjs.map +1 -1
  7. package/dist/cjs/client/useLocale.d.ts +7 -7
  8. package/dist/cjs/generateStaticParams.cjs +8 -13
  9. package/dist/cjs/generateStaticParams.d.ts +2 -2
  10. package/dist/cjs/index.cjs +19 -25
  11. package/dist/cjs/index.cjs.map +1 -1
  12. package/dist/cjs/index.d.ts +8 -15
  13. package/dist/cjs/middleware/index.cjs +9 -21
  14. package/dist/cjs/middleware/index.d.ts +2 -2
  15. package/dist/cjs/middleware/intlayerMiddleware.cjs +28 -86
  16. package/dist/cjs/middleware/intlayerMiddleware.cjs.map +1 -1
  17. package/dist/cjs/middleware/intlayerMiddleware.d.ts +16 -1
  18. package/dist/cjs/middleware/localeDetector.cjs +20 -37
  19. package/dist/cjs/middleware/localeDetector.cjs.map +1 -1
  20. package/dist/cjs/middleware/localeDetector.d.ts +7 -2
  21. package/dist/cjs/server/index.cjs +17 -22
  22. package/dist/cjs/server/index.cjs.map +1 -1
  23. package/dist/cjs/server/index.d.ts +3 -10
  24. package/dist/cjs/server/withIntlayer.cjs +38 -53
  25. package/dist/cjs/server/withIntlayer.cjs.map +1 -1
  26. package/dist/cjs/server/withIntlayer.d.ts +13 -5
  27. package/dist/cjs/types/NextPage.cjs +4 -8
  28. package/dist/cjs/types/NextPage.d.ts +6 -6
  29. package/dist/cjs/types/index.cjs +4 -8
  30. package/dist/cjs/types/index.d.ts +4 -4
  31. package/dist/esm/client/index.d.mts +3 -10
  32. package/dist/esm/client/index.mjs +8 -8
  33. package/dist/esm/client/index.mjs.map +1 -1
  34. package/dist/esm/client/useLocale.d.mts +7 -7
  35. package/dist/esm/client/useLocale.mjs +12 -10
  36. package/dist/esm/client/useLocale.mjs.map +1 -1
  37. package/dist/esm/generateStaticParams.d.mts +2 -2
  38. package/dist/esm/generateStaticParams.mjs +4 -2
  39. package/dist/esm/index.d.mts +8 -15
  40. package/dist/esm/index.mjs +9 -9
  41. package/dist/esm/index.mjs.map +1 -1
  42. package/dist/esm/middleware/index.d.mts +2 -2
  43. package/dist/esm/middleware/index.mjs +2 -2
  44. package/dist/esm/middleware/intlayerMiddleware.d.mts +16 -1
  45. package/dist/esm/middleware/intlayerMiddleware.mjs +21 -66
  46. package/dist/esm/middleware/intlayerMiddleware.mjs.map +1 -1
  47. package/dist/esm/middleware/localeDetector.d.mts +7 -2
  48. package/dist/esm/middleware/localeDetector.mjs +5 -3
  49. package/dist/esm/middleware/localeDetector.mjs.map +1 -1
  50. package/dist/esm/server/index.d.mts +3 -10
  51. package/dist/esm/server/index.mjs +8 -8
  52. package/dist/esm/server/index.mjs.map +1 -1
  53. package/dist/esm/server/withIntlayer.d.mts +13 -5
  54. package/dist/esm/server/withIntlayer.mjs +34 -37
  55. package/dist/esm/server/withIntlayer.mjs.map +1 -1
  56. package/dist/esm/types/NextPage.d.mts +6 -6
  57. package/dist/esm/types/NextPage.mjs +1 -1
  58. package/dist/esm/types/index.d.mts +4 -4
  59. package/dist/esm/types/index.mjs +1 -1
  60. package/package.json +14 -12
  61. package/src/client/index.ts +2 -2
  62. package/src/client/useLocale.ts +6 -4
  63. package/src/index.ts +2 -2
  64. package/src/middleware/intlayerMiddleware.ts +15 -0
  65. package/src/middleware/localeDetector.ts +5 -0
  66. package/src/server/index.ts +2 -2
  67. package/src/server/withIntlayer.ts +33 -27
@@ -1,40 +1,37 @@
1
1
  import { resolve, relative, join } from "path";
2
2
  import { getConfiguration, formatEnvVariable } from "@intlayer/config";
3
- const intlayerConfig = getConfiguration({
4
- verbose: true,
5
- });
6
- const env = formatEnvVariable("NEXT_PUBLIC_INTLAYER_");
7
- const { mainDir, baseDir } = intlayerConfig.content;
8
- const mergeEnvVariable = (nextEnv = {}) => Object.assign({}, nextEnv, env);
9
- const mergeStats = (nextStats = {}) =>
10
- Object.assign({}, nextStats, {
11
- warnings: false,
3
+ import { IntLayerPlugin } from "@intlayer/webpack";
4
+ const withIntlayer = (_pluginOptions = {}) => (nextConfig = {}) => {
5
+ if (typeof nextConfig !== "object")
6
+ nextConfig = {};
7
+ const intlayerConfig = getConfiguration();
8
+ const env = formatEnvVariable("next");
9
+ const { mainDir, baseDir } = intlayerConfig.content;
10
+ return Object.assign({}, nextConfig, {
11
+ env: { ...nextConfig.env, ...env },
12
+ webpack: (config, { isServer, nextRuntime }) => {
13
+ const dictionariesPath = join(mainDir, "dictionaries.cjs");
14
+ const relativeDictionariesPath = relative(baseDir, dictionariesPath);
15
+ config.resolve.alias["@intlayer/dictionaries-entry"] = resolve(
16
+ relativeDictionariesPath
17
+ );
18
+ config.externals.push({
19
+ esbuild: "esbuild",
20
+ module: "module",
21
+ fs: "fs"
22
+ });
23
+ config.module.rules.push({
24
+ test: /\.node$/,
25
+ loader: "node-loader"
26
+ });
27
+ if (isServer && nextRuntime === "nodejs") {
28
+ config.plugins.push(new IntLayerPlugin());
29
+ }
30
+ return config;
31
+ }
12
32
  });
13
- const withIntlayer =
14
- (_pluginOptions = {}) =>
15
- (nextConfig = {}) => {
16
- if (typeof nextConfig !== "object") nextConfig = {};
17
- return Object.assign({}, nextConfig, {
18
- env: mergeEnvVariable(nextConfig.env),
19
- stats: mergeStats(nextConfig.stats),
20
- webpack: (config) => {
21
- const dictionariesPath = join(mainDir, "dictionaries.cjs");
22
- const relativeDictionariesPath = relative(baseDir, dictionariesPath);
23
- config.externals.push({
24
- esbuild: "esbuild",
25
- module: "module",
26
- fs: "fs",
27
- });
28
- config.resolve.alias["@intlayer/dictionaries-entry"] = resolve(
29
- relativeDictionariesPath
30
- );
31
- config.module.rules.push({
32
- test: /\.node$/,
33
- loader: "node-loader",
34
- });
35
- return config;
36
- },
37
- });
38
- };
39
- export { withIntlayer };
40
- //# sourceMappingURL=withIntlayer.mjs.map
33
+ };
34
+ export {
35
+ withIntlayer
36
+ };
37
+ //# sourceMappingURL=withIntlayer.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/server/withIntlayer.ts"],"sourcesContent":["import { resolve, relative, join } from 'path';\nimport { getConfiguration, formatEnvVariable } from '@intlayer/config';\nimport type { NextConfig } from 'next';\nimport type { NextJsWebpackConfig } from 'next/dist/server/config-shared';\n\ntype PluginOptions = {\n // TODO: add options\n};\n\nconst intlayerConfig = getConfiguration({\n verbose: true,\n});\n\n// Set all configuration values as environment variables\nconst env = formatEnvVariable('NEXT_PUBLIC_INTLAYER_');\nconst { mainDir, baseDir } = intlayerConfig.content;\n\nconst mergeEnvVariable = (\n nextEnv: Record<string, unknown> | undefined = {}\n): Record<string, string> => Object.assign({}, nextEnv, env);\n\nconst mergeStats = (\n nextStats: Record<string, unknown> | undefined = {}\n): Record<string, unknown> =>\n Object.assign({}, nextStats, {\n warnings: false,\n });\n\nexport const withIntlayer =\n (_pluginOptions: PluginOptions = {}) =>\n (nextConfig: Partial<NextConfig> = {}): Partial<NextConfig> => {\n if (typeof nextConfig !== 'object') nextConfig = {};\n\n return Object.assign({}, nextConfig, {\n env: mergeEnvVariable(nextConfig.env),\n\n stats: mergeStats(nextConfig.stats),\n\n webpack: (config: Parameters<NextJsWebpackConfig>['0']) => {\n const dictionariesPath = join(mainDir, 'dictionaries.cjs');\n const relativeDictionariesPath = relative(baseDir, dictionariesPath);\n\n config.externals.push({\n esbuild: 'esbuild',\n module: 'module',\n fs: 'fs',\n });\n\n config.resolve.alias['@intlayer/dictionaries-entry'] = resolve(\n relativeDictionariesPath\n );\n\n config.module.rules.push({\n test: /\\.node$/,\n loader: 'node-loader',\n });\n\n return config;\n },\n });\n };\n"],"mappings":"AAAA,SAAS,SAAS,UAAU,YAAY;AACxC,SAAS,kBAAkB,yBAAyB;AAQpD,MAAM,iBAAiB,iBAAiB;AAAA,EACtC,SAAS;AACX,CAAC;AAGD,MAAM,MAAM,kBAAkB,uBAAuB;AACrD,MAAM,EAAE,SAAS,QAAQ,IAAI,eAAe;AAE5C,MAAM,mBAAmB,CACvB,UAA+C,CAAC,MACrB,OAAO,OAAO,CAAC,GAAG,SAAS,GAAG;AAE3D,MAAM,aAAa,CACjB,YAAiD,CAAC,MAElD,OAAO,OAAO,CAAC,GAAG,WAAW;AAAA,EAC3B,UAAU;AACZ,CAAC;AAEI,MAAM,eACX,CAAC,iBAAgC,CAAC,MAClC,CAAC,aAAkC,CAAC,MAA2B;AAC7D,MAAI,OAAO,eAAe;AAAU,iBAAa,CAAC;AAElD,SAAO,OAAO,OAAO,CAAC,GAAG,YAAY;AAAA,IACnC,KAAK,iBAAiB,WAAW,GAAG;AAAA,IAEpC,OAAO,WAAW,WAAW,KAAK;AAAA,IAElC,SAAS,CAAC,WAAiD;AACzD,YAAM,mBAAmB,KAAK,SAAS,kBAAkB;AACzD,YAAM,2BAA2B,SAAS,SAAS,gBAAgB;AAEnE,aAAO,UAAU,KAAK;AAAA,QACpB,SAAS;AAAA,QACT,QAAQ;AAAA,QACR,IAAI;AAAA,MACN,CAAC;AAED,aAAO,QAAQ,MAAM,8BAA8B,IAAI;AAAA,QACrD;AAAA,MACF;AAEA,aAAO,OAAO,MAAM,KAAK;AAAA,QACvB,MAAM;AAAA,QACN,QAAQ;AAAA,MACV,CAAC;AAED,aAAO;AAAA,IACT;AAAA,EACF,CAAC;AACH;","names":[]}
1
+ {"version":3,"sources":["../../../src/server/withIntlayer.ts"],"sourcesContent":["import { resolve, relative, join } from 'path';\nimport { getConfiguration, formatEnvVariable } from '@intlayer/config';\nimport { IntLayerPlugin } from '@intlayer/webpack';\nimport type { NextConfig } from 'next';\nimport type { NextJsWebpackConfig } from 'next/dist/server/config-shared';\n\ntype PluginOptions = {\n // TODO: add options\n};\n\ntype WebpackParams = Parameters<NextJsWebpackConfig>;\n\n/**\n * A Next.js plugin that adds the intlayer configuration to the webpack configuration\n * and sets the environment variables\n *\n * Usage:\n *\n * // next.config.js\n * export default withIntlayer(nextConfig)\n *\n */\nexport const withIntlayer =\n (_pluginOptions: PluginOptions = {}) =>\n (nextConfig: Partial<NextConfig> = {}): Partial<NextConfig> => {\n if (typeof nextConfig !== 'object') nextConfig = {};\n\n const intlayerConfig = getConfiguration();\n\n // Set all configuration values as environment variables\n const env = formatEnvVariable('next');\n\n const { mainDir, baseDir } = intlayerConfig.content;\n\n return Object.assign({}, nextConfig, {\n env: { ...nextConfig.env, ...env },\n\n webpack: (\n config: WebpackParams['0'],\n { isServer, nextRuntime }: WebpackParams[1]\n ) => {\n const dictionariesPath = join(mainDir, 'dictionaries.cjs');\n const relativeDictionariesPath = relative(baseDir, dictionariesPath);\n\n config.resolve.alias['@intlayer/dictionaries-entry'] = resolve(\n relativeDictionariesPath\n );\n\n config.externals.push({\n esbuild: 'esbuild',\n module: 'module',\n fs: 'fs',\n });\n config.module.rules.push({\n test: /\\.node$/,\n loader: 'node-loader',\n });\n\n // Apply IntLayerPlugin only on the server-side\n if (isServer && nextRuntime === 'nodejs') {\n config.plugins.push(new IntLayerPlugin());\n }\n\n return config;\n },\n });\n };\n"],"mappings":"AAAA,SAAS,SAAS,UAAU,YAAY;AACxC,SAAS,kBAAkB,yBAAyB;AACpD,SAAS,sBAAsB;AAoBxB,MAAM,eACX,CAAC,iBAAgC,CAAC,MAClC,CAAC,aAAkC,CAAC,MAA2B;AAC7D,MAAI,OAAO,eAAe;AAAU,iBAAa,CAAC;AAElD,QAAM,iBAAiB,iBAAiB;AAGxC,QAAM,MAAM,kBAAkB,MAAM;AAEpC,QAAM,EAAE,SAAS,QAAQ,IAAI,eAAe;AAE5C,SAAO,OAAO,OAAO,CAAC,GAAG,YAAY;AAAA,IACnC,KAAK,EAAE,GAAG,WAAW,KAAK,GAAG,IAAI;AAAA,IAEjC,SAAS,CACP,QACA,EAAE,UAAU,YAAY,MACrB;AACH,YAAM,mBAAmB,KAAK,SAAS,kBAAkB;AACzD,YAAM,2BAA2B,SAAS,SAAS,gBAAgB;AAEnE,aAAO,QAAQ,MAAM,8BAA8B,IAAI;AAAA,QACrD;AAAA,MACF;AAEA,aAAO,UAAU,KAAK;AAAA,QACpB,SAAS;AAAA,QACT,QAAQ;AAAA,QACR,IAAI;AAAA,MACN,CAAC;AACD,aAAO,OAAO,MAAM,KAAK;AAAA,QACvB,MAAM;AAAA,QACN,QAAQ;AAAA,MACV,CAAC;AAGD,UAAI,YAAY,gBAAgB,UAAU;AACxC,eAAO,QAAQ,KAAK,IAAI,eAAe,CAAC;AAAA,MAC1C;AAEA,aAAO;AAAA,IACT;AAAA,EACF,CAAC;AACH;","names":[]}
@@ -1,11 +1,11 @@
1
- import { Locales } from "intlayer";
2
- import { NextPage } from "next";
3
- import { PropsWithChildren } from "react";
1
+ import { Locales } from 'intlayer';
2
+ import { NextPage } from 'next';
3
+ import { PropsWithChildren } from 'react';
4
4
 
5
5
  type LocalParams = {
6
- params: {
7
- locale: Locales;
8
- };
6
+ params: {
7
+ locale: Locales;
8
+ };
9
9
  };
10
10
  type NextPageIntlayer = NextPage<LocalParams>;
11
11
  type NextLayoutIntlayer = NextPage<PropsWithChildren<LocalParams>>;
@@ -1 +1 @@
1
- //# sourceMappingURL=NextPage.mjs.map
1
+ //# sourceMappingURL=NextPage.mjs.map
@@ -1,4 +1,4 @@
1
- export { LocalParams, NextPageIntlayer } from "./NextPage.mjs";
2
- import "intlayer";
3
- import "next";
4
- import "react";
1
+ export { LocalParams, NextPageIntlayer } from './NextPage.mjs';
2
+ import 'intlayer';
3
+ import 'next';
4
+ import 'react';
@@ -1 +1 @@
1
- //# sourceMappingURL=index.mjs.map
1
+ //# sourceMappingURL=index.mjs.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-intlayer",
3
- "version": "1.0.0",
3
+ "version": "1.2.0",
4
4
  "private": false,
5
5
  "description": "Webpack configuration for IntLayer using NextJS",
6
6
  "keywords": [
@@ -17,7 +17,7 @@
17
17
  "homepage": "https://github.com/aypineau/intlayer",
18
18
  "repository": {
19
19
  "type": "git",
20
- "url": "https://github.com/aypineau/intlayer"
20
+ "url": "git+https://github.com/aypineau/intlayer.git"
21
21
  },
22
22
  "license": "MIT",
23
23
  "author": {
@@ -66,22 +66,24 @@
66
66
  "negotiator": "^0.6.3",
67
67
  "next": "14.1.4",
68
68
  "webpack": "^5.91.0",
69
- "@intlayer/core": "^1.0.0",
70
- "@intlayer/config": "^1.0.0",
71
- "intlayer": "^1.0.0",
72
- "@intlayer/dictionaries-entry": "^1.0.0",
73
- "react-intlayer": "^1.0.0"
69
+ "@intlayer/chokidar": "^1.2.0",
70
+ "@intlayer/config": "^1.2.0",
71
+ "@intlayer/core": "^1.2.0",
72
+ "@intlayer/dictionaries-entry": "^1.2.0",
73
+ "@intlayer/webpack": "^1.2.0",
74
+ "intlayer": "^1.2.0",
75
+ "react-intlayer": "^1.2.0"
74
76
  },
75
77
  "devDependencies": {
76
78
  "@types/negotiator": "^0.6.3",
77
- "@types/node": "^20.11.30",
78
- "@types/react": "^18.2.78",
79
+ "@types/node": "^20.12.7",
80
+ "@types/react": "^18.2.79",
79
81
  "react": "^18.2.0",
80
82
  "rimraf": "5.0.5",
81
83
  "tsup": "^8.0.2",
82
- "typescript": "^5.4.3",
83
- "@utils/eslint-config": "^1.0.0",
84
- "@utils/ts-config": "^1.0.0"
84
+ "typescript": "^5.4.5",
85
+ "@utils/eslint-config": "^1.0.1",
86
+ "@utils/ts-config": "^1.0.1"
85
87
  },
86
88
  "peerDependencies": {
87
89
  "react": "^18.2.0"
@@ -1,7 +1,7 @@
1
1
  export {
2
2
  getTranslation,
3
- LocaleClientContextProvider,
4
- LocaleClientContext,
3
+ IntlayerClientProvider,
4
+ IntlayerClient,
5
5
  useIntlayer,
6
6
  useTraduction,
7
7
  useLocaleCookie,
@@ -1,5 +1,7 @@
1
- import { intlayerMiddlewareConfiguration } from '@intlayer/config/client';
2
- import type { Locales } from 'intlayer';
1
+ import {
2
+ type Locales,
3
+ intlayerMiddlewareConfiguration,
4
+ } from '@intlayer/config/client';
3
5
  import { usePathname, useRouter } from 'next/navigation.js';
4
6
  import { useLocale as useReactLocale, useLocaleCookie } from 'react-intlayer';
5
7
 
@@ -18,7 +20,7 @@ export const useLocale = () => {
18
20
  } = reactLocaleHook;
19
21
 
20
22
  const setLocale = (locale: Locales) => {
21
- if (currentLocale === locale) return;
23
+ if (currentLocale.toString() === locale.toString()) return;
22
24
 
23
25
  if (!availableLocales.includes(locale)) {
24
26
  console.error(`Locale ${locale} is not available`);
@@ -28,7 +30,7 @@ export const useLocale = () => {
28
30
  setLocaleCookie(locale);
29
31
 
30
32
  const pathWithoutLocale =
31
- !prefixDefault && currentLocale === defaultLocale
33
+ !prefixDefault && currentLocale.toString() === defaultLocale.toString()
32
34
  ? pathname
33
35
  : pathname.slice(`/${currentLocale}`.length) || '/';
34
36
 
package/src/index.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  export {
2
2
  getTranslation,
3
- LocaleClientContextProvider,
4
- LocaleClientContext,
3
+ IntlayerClientProvider,
4
+ IntlayerClient,
5
5
  useIntlayer,
6
6
  useTraduction,
7
7
  useLocaleCookie,
@@ -13,6 +13,21 @@ const {
13
13
  noPrefix,
14
14
  } = middleware;
15
15
 
16
+ /**
17
+ * Middleware that handles the internationalization layer
18
+ *
19
+ * Usage:
20
+ *
21
+ * // ./src/middleware.ts
22
+ *
23
+ * export { intlayerMiddleware as middleware } from '@intlayer/next/middleware';
24
+ *
25
+ * // applies this middleware only to files in the app directory
26
+ * export const config = {
27
+ * matcher: '/((?!api|static|.*\\..*|_next).*)',
28
+ * };
29
+ *
30
+ */
16
31
  export const intlayerMiddleware = (request: NextRequest): NextResponse => {
17
32
  const pathname = request.nextUrl.pathname;
18
33
  const cookieLocale = getCookieLocale(request);
@@ -6,6 +6,11 @@ import type { NextRequest } from 'next/server.js';
6
6
 
7
7
  const { locales, defaultLocale } = getConfiguration().internationalization;
8
8
 
9
+ /**
10
+ * Detects the locale from the request headers
11
+ *
12
+ * Headers are provided by the browser and can be used to determine the user's preferred language
13
+ */
9
14
  export const localeDetector = (request: NextRequest): Locales => {
10
15
  const negotiatorHeaders: Record<string, string> = {};
11
16
 
@@ -1,8 +1,8 @@
1
1
  export {
2
2
  getLocaleContent,
3
3
  useTraduction,
4
- LocaleServerContext,
5
- LocaleServerContextProvider,
4
+ IntlayerServer,
5
+ IntlayerServerProvider,
6
6
  locale,
7
7
  useIntlayer,
8
8
  } from 'react-intlayer/server';
@@ -1,5 +1,6 @@
1
1
  import { resolve, relative, join } from 'path';
2
2
  import { getConfiguration, formatEnvVariable } from '@intlayer/config';
3
+ import { IntLayerPlugin } from '@intlayer/webpack';
3
4
  import type { NextConfig } from 'next';
4
5
  import type { NextJsWebpackConfig } from 'next/dist/server/config-shared';
5
6
 
@@ -7,54 +8,59 @@ type PluginOptions = {
7
8
  // TODO: add options
8
9
  };
9
10
 
10
- const intlayerConfig = getConfiguration({
11
- verbose: true,
12
- });
13
-
14
- // Set all configuration values as environment variables
15
- const env = formatEnvVariable('NEXT_PUBLIC_INTLAYER_');
16
- const { mainDir, baseDir } = intlayerConfig.content;
17
-
18
- const mergeEnvVariable = (
19
- nextEnv: Record<string, unknown> | undefined = {}
20
- ): Record<string, string> => Object.assign({}, nextEnv, env);
21
-
22
- const mergeStats = (
23
- nextStats: Record<string, unknown> | undefined = {}
24
- ): Record<string, unknown> =>
25
- Object.assign({}, nextStats, {
26
- warnings: false,
27
- });
11
+ type WebpackParams = Parameters<NextJsWebpackConfig>;
28
12
 
13
+ /**
14
+ * A Next.js plugin that adds the intlayer configuration to the webpack configuration
15
+ * and sets the environment variables
16
+ *
17
+ * Usage:
18
+ *
19
+ * // next.config.js
20
+ * export default withIntlayer(nextConfig)
21
+ *
22
+ */
29
23
  export const withIntlayer =
30
24
  (_pluginOptions: PluginOptions = {}) =>
31
25
  (nextConfig: Partial<NextConfig> = {}): Partial<NextConfig> => {
32
26
  if (typeof nextConfig !== 'object') nextConfig = {};
33
27
 
34
- return Object.assign({}, nextConfig, {
35
- env: mergeEnvVariable(nextConfig.env),
28
+ const intlayerConfig = getConfiguration();
29
+
30
+ // Set all configuration values as environment variables
31
+ const env = formatEnvVariable('next');
36
32
 
37
- stats: mergeStats(nextConfig.stats),
33
+ const { mainDir, baseDir } = intlayerConfig.content;
38
34
 
39
- webpack: (config: Parameters<NextJsWebpackConfig>['0']) => {
35
+ return Object.assign({}, nextConfig, {
36
+ env: { ...nextConfig.env, ...env },
37
+
38
+ webpack: (
39
+ config: WebpackParams['0'],
40
+ { isServer, nextRuntime }: WebpackParams[1]
41
+ ) => {
40
42
  const dictionariesPath = join(mainDir, 'dictionaries.cjs');
41
43
  const relativeDictionariesPath = relative(baseDir, dictionariesPath);
42
44
 
45
+ config.resolve.alias['@intlayer/dictionaries-entry'] = resolve(
46
+ relativeDictionariesPath
47
+ );
48
+
43
49
  config.externals.push({
44
50
  esbuild: 'esbuild',
45
51
  module: 'module',
46
52
  fs: 'fs',
47
53
  });
48
-
49
- config.resolve.alias['@intlayer/dictionaries-entry'] = resolve(
50
- relativeDictionariesPath
51
- );
52
-
53
54
  config.module.rules.push({
54
55
  test: /\.node$/,
55
56
  loader: 'node-loader',
56
57
  });
57
58
 
59
+ // Apply IntLayerPlugin only on the server-side
60
+ if (isServer && nextRuntime === 'nodejs') {
61
+ config.plugins.push(new IntLayerPlugin());
62
+ }
63
+
58
64
  return config;
59
65
  },
60
66
  });