@akanjs/config 0.0.4 → 0.0.6
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.
- package/package.json +1 -1
- package/src/capacitor.base.config.d.ts +2 -0
- package/src/capacitor.base.config.js +72 -0
- package/src/capacitor.base.config.ts +39 -0
- package/src/jest.config.base.js +5 -4
- package/src/jest.config.base.ts +5 -4
- package/src/next.base.d.ts +12 -0
- package/src/next.base.js +100 -81
- package/src/next.base.ts +137 -0
- package/src/webpack.backend.base.js +3 -2
package/package.json
CHANGED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
var capacitor_base_config_exports = {};
|
|
29
|
+
__export(capacitor_base_config_exports, {
|
|
30
|
+
withBase: () => withBase
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(capacitor_base_config_exports);
|
|
33
|
+
var import_os = __toESM(require("os"));
|
|
34
|
+
const getLocalIP = () => {
|
|
35
|
+
const interfaces = import_os.default.networkInterfaces();
|
|
36
|
+
for (const interfaceName in interfaces) {
|
|
37
|
+
const iface = interfaces[interfaceName];
|
|
38
|
+
if (!iface)
|
|
39
|
+
continue;
|
|
40
|
+
for (const alias of iface) {
|
|
41
|
+
if (alias.family === "IPv4" && !alias.internal)
|
|
42
|
+
return alias.address;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return "127.0.0.1";
|
|
46
|
+
};
|
|
47
|
+
const withBase = (applyConfig) => {
|
|
48
|
+
const projectName = process.env.NX_TASK_TARGET_PROJECT;
|
|
49
|
+
if (!projectName)
|
|
50
|
+
throw new Error("projectName is not defined, please run with nx command");
|
|
51
|
+
const ip = getLocalIP();
|
|
52
|
+
const baseConfig = {
|
|
53
|
+
appId: `com.${projectName}.app`,
|
|
54
|
+
appName: projectName,
|
|
55
|
+
webDir: `../../dist/apps/${projectName}/csr/`,
|
|
56
|
+
bundledWebRuntime: false,
|
|
57
|
+
server: process.env.APP_OPERATION_MODE !== "release" ? {
|
|
58
|
+
androidScheme: "http",
|
|
59
|
+
url: `http://${ip}:4201`,
|
|
60
|
+
cleartext: true,
|
|
61
|
+
allowNavigation: [`http://${ip}:8080/*`]
|
|
62
|
+
} : void 0,
|
|
63
|
+
plugins: {
|
|
64
|
+
CapacitorCookies: { enabled: true }
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
return applyConfig(baseConfig);
|
|
68
|
+
};
|
|
69
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
70
|
+
0 && (module.exports = {
|
|
71
|
+
withBase
|
|
72
|
+
});
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { CapacitorConfig } from "@capacitor/cli";
|
|
2
|
+
import os from "os";
|
|
3
|
+
|
|
4
|
+
const getLocalIP = () => {
|
|
5
|
+
const interfaces = os.networkInterfaces();
|
|
6
|
+
for (const interfaceName in interfaces) {
|
|
7
|
+
const iface = interfaces[interfaceName];
|
|
8
|
+
if (!iface) continue;
|
|
9
|
+
for (const alias of iface) {
|
|
10
|
+
if (alias.family === "IPv4" && !alias.internal) return alias.address;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
return "127.0.0.1"; // fallback to localhost if no suitable IP found
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export const withBase = (applyConfig: (config: CapacitorConfig) => CapacitorConfig) => {
|
|
17
|
+
const projectName = process.env.NX_TASK_TARGET_PROJECT;
|
|
18
|
+
if (!projectName) throw new Error("projectName is not defined, please run with nx command");
|
|
19
|
+
const ip = getLocalIP();
|
|
20
|
+
const baseConfig: CapacitorConfig = {
|
|
21
|
+
appId: `com.${projectName}.app`,
|
|
22
|
+
appName: projectName,
|
|
23
|
+
webDir: `../../dist/apps/${projectName}/csr/`,
|
|
24
|
+
bundledWebRuntime: false,
|
|
25
|
+
server:
|
|
26
|
+
process.env.APP_OPERATION_MODE !== "release"
|
|
27
|
+
? {
|
|
28
|
+
androidScheme: "http",
|
|
29
|
+
url: `http://${ip}:4201`,
|
|
30
|
+
cleartext: true,
|
|
31
|
+
allowNavigation: [`http://${ip}:8080/*`],
|
|
32
|
+
}
|
|
33
|
+
: undefined,
|
|
34
|
+
plugins: {
|
|
35
|
+
CapacitorCookies: { enabled: true },
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
return applyConfig(baseConfig);
|
|
39
|
+
};
|
package/src/jest.config.base.js
CHANGED
|
@@ -27,12 +27,13 @@ const withBase = (name) => {
|
|
|
27
27
|
process.env.NEXT_PUBLIC_OPERATION_MODE = "local";
|
|
28
28
|
process.env.NEXT_PUBLIC_APP_NAME = name;
|
|
29
29
|
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
|
|
30
|
+
const akanjsPrefix = process.env.USE_AKANJS_PKGS === "true" ? "../../pkgs/" : "";
|
|
30
31
|
return {
|
|
31
32
|
displayName: name,
|
|
32
|
-
preset:
|
|
33
|
-
globalSetup:
|
|
34
|
-
setupFilesAfterEnv: [
|
|
35
|
-
globalTeardown:
|
|
33
|
+
preset: `${akanjsPrefix}@akanjs/config/src/jest.preset.js`,
|
|
34
|
+
globalSetup: `${akanjsPrefix}@akanjs/config/src/jest.globalSetup.ts`,
|
|
35
|
+
setupFilesAfterEnv: [`${akanjsPrefix}@akanjs/config/src/jest.setupFilesAfterEnv.ts`],
|
|
36
|
+
globalTeardown: `${akanjsPrefix}@akanjs/config/src/jest.globalTeardown.ts`,
|
|
36
37
|
testMatch: ["**/?(*.)+(test).ts?(x)"],
|
|
37
38
|
testPathIgnorePatterns: ["/node_modules/", "/app/"],
|
|
38
39
|
maxWorkers: 1,
|
package/src/jest.config.base.ts
CHANGED
|
@@ -7,12 +7,13 @@ export const withBase = (name: string): Config.InitialOptions => {
|
|
|
7
7
|
process.env.NEXT_PUBLIC_OPERATION_MODE = "local";
|
|
8
8
|
process.env.NEXT_PUBLIC_APP_NAME = name;
|
|
9
9
|
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
|
|
10
|
+
const akanjsPrefix = process.env.USE_AKANJS_PKGS === "true" ? "../../pkgs/" : "";
|
|
10
11
|
return {
|
|
11
12
|
displayName: name,
|
|
12
|
-
preset:
|
|
13
|
-
globalSetup:
|
|
14
|
-
setupFilesAfterEnv: [
|
|
15
|
-
globalTeardown:
|
|
13
|
+
preset: `${akanjsPrefix}@akanjs/config/src/jest.preset.js`,
|
|
14
|
+
globalSetup: `${akanjsPrefix}@akanjs/config/src/jest.globalSetup.ts`,
|
|
15
|
+
setupFilesAfterEnv: [`${akanjsPrefix}@akanjs/config/src/jest.setupFilesAfterEnv.ts`],
|
|
16
|
+
globalTeardown: `${akanjsPrefix}@akanjs/config/src/jest.globalTeardown.ts`,
|
|
16
17
|
testMatch: ["**/?(*.)+(test).ts?(x)"],
|
|
17
18
|
testPathIgnorePatterns: ["/node_modules/", "/app/"],
|
|
18
19
|
maxWorkers: 1,
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { NextConfig } from "next";
|
|
2
|
+
/**
|
|
3
|
+
* @type { (config: import('@nx/next/plugins/with-nx').WithNxOptions) => import('@nx/next/plugins/with-nx').WithNxOptions }
|
|
4
|
+
**/
|
|
5
|
+
export declare const withBase: (appName: string, config: NextConfig, routes?: {
|
|
6
|
+
basePath?: string;
|
|
7
|
+
domains: {
|
|
8
|
+
main?: string[];
|
|
9
|
+
develop?: string[];
|
|
10
|
+
debug?: string[];
|
|
11
|
+
};
|
|
12
|
+
}[]) => import("@nx/next/src/utils/config").NextConfigFn;
|
package/src/next.base.js
CHANGED
|
@@ -1,35 +1,61 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
var next_base_exports = {};
|
|
29
|
+
__export(next_base_exports, {
|
|
30
|
+
withBase: () => withBase
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(next_base_exports);
|
|
33
|
+
var import_bundle_analyzer = __toESM(require("@next/bundle-analyzer"));
|
|
34
|
+
var import_next = require("@nx/next");
|
|
35
|
+
var import_next_pwa = __toESM(require("next-pwa"));
|
|
36
|
+
var import_cache = __toESM(require("next-pwa/cache"));
|
|
37
|
+
const commandType = process.env.NX_TASK_TARGET_TARGET?.includes("serve") ? "serve" : process.env.NX_TASK_TARGET_TARGET?.includes("build") ? "build" : "deploy";
|
|
38
|
+
const withPWA = (0, import_next_pwa.default)({
|
|
10
39
|
dest: "public",
|
|
11
40
|
register: true,
|
|
12
41
|
skipWaiting: true,
|
|
13
|
-
|
|
42
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
43
|
+
runtimeCaching: import_cache.default
|
|
14
44
|
// disable: commandType === "serve",
|
|
15
45
|
});
|
|
16
46
|
const devDomain = process.env.NEXT_PUBLIC_SERVE_DOMAIN ?? "akanjs.com";
|
|
17
47
|
const libs = ["game", "mint", "platform", "social", "shared", "util"];
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* @type { (config: import('@nx/next/plugins/with-nx').WithNxOptions) => import('@nx/next/plugins/with-nx').WithNxOptions }
|
|
21
|
-
**/
|
|
22
48
|
const withBase = (appName, config, routes = []) => {
|
|
23
|
-
return composePlugins(
|
|
24
|
-
withNx,
|
|
25
|
-
|
|
49
|
+
return (0, import_next.composePlugins)(
|
|
50
|
+
import_next.withNx,
|
|
51
|
+
(0, import_bundle_analyzer.default)({ enabled: process.env.ANALYZE === "true" }),
|
|
26
52
|
withPWA
|
|
27
53
|
// ...(commandType !== "serve" ? [withPWA] : [])
|
|
28
54
|
)({
|
|
29
55
|
...config,
|
|
30
56
|
env: {
|
|
31
57
|
...config.env,
|
|
32
|
-
basePaths: routes.map(({ basePath }) => basePath).join(",")
|
|
58
|
+
basePaths: routes.map(({ basePath }) => basePath).join(",")
|
|
33
59
|
},
|
|
34
60
|
transpilePackages: ["swiper", "ssr-window", "dom7"],
|
|
35
61
|
reactStrictMode: commandType === "serve" ? false : true,
|
|
@@ -37,7 +63,7 @@ const withBase = (appName, config, routes = []) => {
|
|
|
37
63
|
modularizeImports: {
|
|
38
64
|
"react-icons/?(((\\w*)?/?)*)": {
|
|
39
65
|
transform: "@react-icons/all-files/{{ matches.[1] }}/{{member}}",
|
|
40
|
-
skipDefaultConversion: true
|
|
66
|
+
skipDefaultConversion: true
|
|
41
67
|
},
|
|
42
68
|
lodash: { transform: "lodash/{{member}}", preventFullImport: true },
|
|
43
69
|
...Object.fromEntries(
|
|
@@ -47,81 +73,74 @@ const withBase = (appName, config, routes = []) => {
|
|
|
47
73
|
[`@${lib}/ui`, { transform: `@${lib}/ui/{{member}}`, skipDefaultConversion: true }],
|
|
48
74
|
[`@${lib}/next`, { transform: `@${lib}/next/{{member}}`, skipDefaultConversion: true }],
|
|
49
75
|
[`@${lib}/common`, { transform: `@${lib}/common/{{member}}`, skipDefaultConversion: true }],
|
|
50
|
-
[`@${lib}/client`, { transform: `@${lib}/lib/{{ camelCase member }}`, skipDefaultConversion: true }]
|
|
76
|
+
[`@${lib}/client`, { transform: `@${lib}/lib/{{ camelCase member }}`, skipDefaultConversion: true }]
|
|
51
77
|
],
|
|
52
78
|
[
|
|
53
79
|
["@contract", { transform: `@contract/src/{{member}}`, skipDefaultConversion: true }],
|
|
54
80
|
[`@akanjs/next`, { transform: `@akanjs/next/{{member}}`, skipDefaultConversion: true }],
|
|
55
|
-
[`@akanjs/common`, { transform: `@akanjs/common/{{member}}`, skipDefaultConversion: true }]
|
|
81
|
+
[`@akanjs/common`, { transform: `@akanjs/common/{{member}}`, skipDefaultConversion: true }]
|
|
56
82
|
]
|
|
57
83
|
)
|
|
58
84
|
),
|
|
59
|
-
...
|
|
85
|
+
...config.modularizeImports ?? {}
|
|
60
86
|
},
|
|
61
87
|
images: {
|
|
62
88
|
formats: ["image/avif", "image/webp"],
|
|
63
|
-
...
|
|
89
|
+
...config.images ?? {},
|
|
64
90
|
remotePatterns: [
|
|
65
|
-
...
|
|
66
|
-
...routes
|
|
67
|
-
.map(({
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
{ protocol: "https", hostname: `**.${devDomain}` },
|
|
74
|
-
],
|
|
75
|
-
},
|
|
76
|
-
webpack: (config) => {
|
|
77
|
-
// react-pdf error fix
|
|
78
|
-
config.resolve.alias.canvas = false;
|
|
79
|
-
config.resolve.alias.encoding = false;
|
|
80
|
-
return config;
|
|
91
|
+
...config.images?.remotePatterns ?? [],
|
|
92
|
+
...routes.map(({ domains }) => [
|
|
93
|
+
...domains.main?.map((domain) => ({ protocol: "https", hostname: `**.${domain}` })) ?? [],
|
|
94
|
+
...domains.develop?.map((domain) => ({ protocol: "https", hostname: `**.${domain}` })) ?? [],
|
|
95
|
+
...domains.debug?.map((domain) => ({ protocol: "https", hostname: `**.${domain}` })) ?? []
|
|
96
|
+
]).flat(),
|
|
97
|
+
{ protocol: "https", hostname: `**.${devDomain}` }
|
|
98
|
+
]
|
|
81
99
|
},
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
{ basePath, domain: `${basePath}-develop.${devDomain}` },
|
|
87
|
-
{ basePath, domain: `${basePath}-main.${devDomain}` },
|
|
88
|
-
...(domains?.main?.map((domain) => ({ basePath, domain })) ?? []),
|
|
89
|
-
...(domains?.develop?.map((domain) => ({ basePath, domain })) ?? []),
|
|
90
|
-
...(domains?.debug?.map((domain) => ({ basePath, domain })) ?? []),
|
|
91
|
-
])
|
|
92
|
-
.flat()
|
|
93
|
-
.map(({ basePath, domain }) => ({
|
|
94
|
-
source: `/:locale/${basePath}/:path*`,
|
|
95
|
-
has: [{ type: "host", value: domain }],
|
|
96
|
-
permanent: true,
|
|
97
|
-
destination: "/:locale/:path*",
|
|
98
|
-
}));
|
|
100
|
+
webpack: (config2) => {
|
|
101
|
+
config2.resolve.alias.canvas = false;
|
|
102
|
+
config2.resolve.alias.encoding = false;
|
|
103
|
+
return config2;
|
|
99
104
|
},
|
|
100
|
-
|
|
101
|
-
return routes
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
has: [{ type: "host", value: domain }],
|
|
115
|
-
destination: `/:locale/${basePath}`,
|
|
116
|
-
},
|
|
117
|
-
{
|
|
118
|
-
source: `/:locale/:path((?!${basePath}$)(?!admin(?:/|$)).*)`,
|
|
119
|
-
has: [{ type: "host", value: domain }],
|
|
120
|
-
destination: `/:locale/${basePath}/:path*`,
|
|
121
|
-
},
|
|
122
|
-
])
|
|
123
|
-
.flat();
|
|
105
|
+
redirects() {
|
|
106
|
+
return routes.map(({ basePath, domains }) => [
|
|
107
|
+
{ basePath, domain: `${basePath}-debug.${devDomain}` },
|
|
108
|
+
{ basePath, domain: `${basePath}-develop.${devDomain}` },
|
|
109
|
+
{ basePath, domain: `${basePath}-main.${devDomain}` },
|
|
110
|
+
...domains.main?.map((domain) => ({ basePath, domain })) ?? [],
|
|
111
|
+
...domains.develop?.map((domain) => ({ basePath, domain })) ?? [],
|
|
112
|
+
...domains.debug?.map((domain) => ({ basePath, domain })) ?? []
|
|
113
|
+
]).flat().map(({ basePath, domain }) => ({
|
|
114
|
+
source: `/:locale/${basePath}/:path*`,
|
|
115
|
+
has: [{ type: "host", value: domain }],
|
|
116
|
+
permanent: true,
|
|
117
|
+
destination: "/:locale/:path*"
|
|
118
|
+
}));
|
|
124
119
|
},
|
|
120
|
+
rewrites() {
|
|
121
|
+
return routes.map(({ basePath, domains }) => [
|
|
122
|
+
{ basePath, domain: `${basePath}-debug.${devDomain}` },
|
|
123
|
+
{ basePath, domain: `${basePath}-develop.${devDomain}` },
|
|
124
|
+
{ basePath, domain: `${basePath}-main.${devDomain}` },
|
|
125
|
+
...domains.main?.map((domain) => ({ basePath, domain })) ?? [],
|
|
126
|
+
...domains.develop?.map((domain) => ({ basePath, domain })) ?? [],
|
|
127
|
+
...domains.debug?.map((domain) => ({ basePath, domain })) ?? []
|
|
128
|
+
]).flat().map(({ basePath, domain }) => [
|
|
129
|
+
{
|
|
130
|
+
source: "/:locale",
|
|
131
|
+
has: [{ type: "host", value: domain }],
|
|
132
|
+
destination: `/:locale/${basePath}`
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
source: `/:locale/:path((?!${basePath}$)(?!admin(?:/|$)).*)`,
|
|
136
|
+
has: [{ type: "host", value: domain }],
|
|
137
|
+
destination: `/:locale/${basePath}/:path*`
|
|
138
|
+
}
|
|
139
|
+
]).flat();
|
|
140
|
+
}
|
|
125
141
|
});
|
|
126
142
|
};
|
|
127
|
-
|
|
143
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
144
|
+
0 && (module.exports = {
|
|
145
|
+
withBase
|
|
146
|
+
});
|
package/src/next.base.ts
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
|
2
|
+
import withAnalyze from "@next/bundle-analyzer";
|
|
3
|
+
import { composePlugins, withNx } from "@nx/next";
|
|
4
|
+
import type { NextPlugin } from "@nx/next/src/utils/config";
|
|
5
|
+
import type { NextConfig } from "next";
|
|
6
|
+
import pwa from "next-pwa";
|
|
7
|
+
import runtimeCaching from "next-pwa/cache";
|
|
8
|
+
|
|
9
|
+
const commandType = process.env.NX_TASK_TARGET_TARGET?.includes("serve")
|
|
10
|
+
? "serve"
|
|
11
|
+
: process.env.NX_TASK_TARGET_TARGET?.includes("build")
|
|
12
|
+
? "build"
|
|
13
|
+
: "deploy";
|
|
14
|
+
|
|
15
|
+
const withPWA = pwa({
|
|
16
|
+
dest: "public",
|
|
17
|
+
register: true,
|
|
18
|
+
skipWaiting: true,
|
|
19
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
20
|
+
runtimeCaching,
|
|
21
|
+
// disable: commandType === "serve",
|
|
22
|
+
});
|
|
23
|
+
const devDomain = process.env.NEXT_PUBLIC_SERVE_DOMAIN ?? "akanjs.com";
|
|
24
|
+
const libs = ["game", "mint", "platform", "social", "shared", "util"];
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* @type { (config: import('@nx/next/plugins/with-nx').WithNxOptions) => import('@nx/next/plugins/with-nx').WithNxOptions }
|
|
28
|
+
**/
|
|
29
|
+
export const withBase = (
|
|
30
|
+
appName: string,
|
|
31
|
+
config: NextConfig,
|
|
32
|
+
routes: { basePath?: string; domains: { main?: string[]; develop?: string[]; debug?: string[] } }[] = []
|
|
33
|
+
) => {
|
|
34
|
+
return composePlugins(
|
|
35
|
+
withNx,
|
|
36
|
+
withAnalyze({ enabled: process.env.ANALYZE === "true" }) as unknown as NextPlugin,
|
|
37
|
+
withPWA as unknown as NextPlugin
|
|
38
|
+
// ...(commandType !== "serve" ? [withPWA] : [])
|
|
39
|
+
)({
|
|
40
|
+
...config,
|
|
41
|
+
env: {
|
|
42
|
+
...config.env,
|
|
43
|
+
basePaths: routes.map(({ basePath }) => basePath).join(","),
|
|
44
|
+
},
|
|
45
|
+
transpilePackages: ["swiper", "ssr-window", "dom7"],
|
|
46
|
+
reactStrictMode: commandType === "serve" ? false : true,
|
|
47
|
+
nx: { svgr: false },
|
|
48
|
+
modularizeImports: {
|
|
49
|
+
"react-icons/?(((\\w*)?/?)*)": {
|
|
50
|
+
transform: "@react-icons/all-files/{{ matches.[1] }}/{{member}}",
|
|
51
|
+
skipDefaultConversion: true,
|
|
52
|
+
},
|
|
53
|
+
lodash: { transform: "lodash/{{member}}", preventFullImport: true },
|
|
54
|
+
...Object.fromEntries(
|
|
55
|
+
[appName, ...libs].reduce(
|
|
56
|
+
(acc, lib) => [
|
|
57
|
+
...acc,
|
|
58
|
+
[`@${lib}/ui`, { transform: `@${lib}/ui/{{member}}`, skipDefaultConversion: true }],
|
|
59
|
+
[`@${lib}/next`, { transform: `@${lib}/next/{{member}}`, skipDefaultConversion: true }],
|
|
60
|
+
[`@${lib}/common`, { transform: `@${lib}/common/{{member}}`, skipDefaultConversion: true }],
|
|
61
|
+
[`@${lib}/client`, { transform: `@${lib}/lib/{{ camelCase member }}`, skipDefaultConversion: true }],
|
|
62
|
+
],
|
|
63
|
+
[
|
|
64
|
+
["@contract", { transform: `@contract/src/{{member}}`, skipDefaultConversion: true }],
|
|
65
|
+
[`@akanjs/next`, { transform: `@akanjs/next/{{member}}`, skipDefaultConversion: true }],
|
|
66
|
+
[`@akanjs/common`, { transform: `@akanjs/common/{{member}}`, skipDefaultConversion: true }],
|
|
67
|
+
]
|
|
68
|
+
)
|
|
69
|
+
),
|
|
70
|
+
...(config.modularizeImports ?? {}),
|
|
71
|
+
},
|
|
72
|
+
images: {
|
|
73
|
+
formats: ["image/avif", "image/webp"],
|
|
74
|
+
...(config.images ?? {}),
|
|
75
|
+
remotePatterns: [
|
|
76
|
+
...(config.images?.remotePatterns ?? []),
|
|
77
|
+
...routes
|
|
78
|
+
.map(({ domains }) => [
|
|
79
|
+
...(domains.main?.map((domain) => ({ protocol: "https", hostname: `**.${domain}` })) ?? []),
|
|
80
|
+
...(domains.develop?.map((domain) => ({ protocol: "https", hostname: `**.${domain}` })) ?? []),
|
|
81
|
+
...(domains.debug?.map((domain) => ({ protocol: "https", hostname: `**.${domain}` })) ?? []),
|
|
82
|
+
])
|
|
83
|
+
.flat(),
|
|
84
|
+
{ protocol: "https", hostname: `**.${devDomain}` },
|
|
85
|
+
],
|
|
86
|
+
},
|
|
87
|
+
webpack: (config: NextConfig) => {
|
|
88
|
+
// react-pdf error fix
|
|
89
|
+
config.resolve.alias.canvas = false;
|
|
90
|
+
config.resolve.alias.encoding = false;
|
|
91
|
+
return config;
|
|
92
|
+
},
|
|
93
|
+
redirects() {
|
|
94
|
+
return routes
|
|
95
|
+
.map(({ basePath, domains }) => [
|
|
96
|
+
{ basePath, domain: `${basePath}-debug.${devDomain}` },
|
|
97
|
+
{ basePath, domain: `${basePath}-develop.${devDomain}` },
|
|
98
|
+
{ basePath, domain: `${basePath}-main.${devDomain}` },
|
|
99
|
+
...(domains.main?.map((domain) => ({ basePath, domain })) ?? []),
|
|
100
|
+
...(domains.develop?.map((domain) => ({ basePath, domain })) ?? []),
|
|
101
|
+
...(domains.debug?.map((domain) => ({ basePath, domain })) ?? []),
|
|
102
|
+
])
|
|
103
|
+
.flat()
|
|
104
|
+
.map(({ basePath, domain }) => ({
|
|
105
|
+
source: `/:locale/${basePath}/:path*`,
|
|
106
|
+
has: [{ type: "host", value: domain }],
|
|
107
|
+
permanent: true,
|
|
108
|
+
destination: "/:locale/:path*",
|
|
109
|
+
}));
|
|
110
|
+
},
|
|
111
|
+
rewrites() {
|
|
112
|
+
return routes
|
|
113
|
+
.map(({ basePath, domains }) => [
|
|
114
|
+
{ basePath, domain: `${basePath}-debug.${devDomain}` },
|
|
115
|
+
{ basePath, domain: `${basePath}-develop.${devDomain}` },
|
|
116
|
+
{ basePath, domain: `${basePath}-main.${devDomain}` },
|
|
117
|
+
...(domains.main?.map((domain) => ({ basePath, domain })) ?? []),
|
|
118
|
+
...(domains.develop?.map((domain) => ({ basePath, domain })) ?? []),
|
|
119
|
+
...(domains.debug?.map((domain) => ({ basePath, domain })) ?? []),
|
|
120
|
+
])
|
|
121
|
+
.flat()
|
|
122
|
+
.map(({ basePath, domain }) => [
|
|
123
|
+
{
|
|
124
|
+
source: "/:locale",
|
|
125
|
+
has: [{ type: "host", value: domain }],
|
|
126
|
+
destination: `/:locale/${basePath}`,
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
source: `/:locale/:path((?!${basePath}$)(?!admin(?:/|$)).*)`,
|
|
130
|
+
has: [{ type: "host", value: domain }],
|
|
131
|
+
destination: `/:locale/${basePath}/:path*`,
|
|
132
|
+
},
|
|
133
|
+
])
|
|
134
|
+
.flat();
|
|
135
|
+
},
|
|
136
|
+
} as unknown as NextConfig);
|
|
137
|
+
};
|
|
@@ -25,11 +25,12 @@ module.exports = composePlugins(withNx(), (config) => {
|
|
|
25
25
|
config.plugins.push(new GeneratePackageJsonPlugin(basePackage));
|
|
26
26
|
|
|
27
27
|
if (process.env.NX_TASK_TARGET_TARGET !== "serve-backend") return config;
|
|
28
|
+
const cwd = process.cwd();
|
|
28
29
|
Object.assign(config, {
|
|
29
|
-
entry: [path.join(
|
|
30
|
+
entry: [path.join(cwd, "node_modules/webpack/hot/poll?100"), `./main.ts`],
|
|
30
31
|
mode: "development",
|
|
31
32
|
output: {
|
|
32
|
-
path: path.join(
|
|
33
|
+
path: path.join(cwd, `dist/apps/${appName}/backend`),
|
|
33
34
|
filename: "main.js",
|
|
34
35
|
},
|
|
35
36
|
});
|