-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnext.config.js
More file actions
81 lines (75 loc) · 2.99 KB
/
next.config.js
File metadata and controls
81 lines (75 loc) · 2.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
const webpack = require('webpack');
// Direct dependencies that must not be bundled (native modules / server-only)
const serverOnlyPackages = ['node-pty', 'better-sqlite3', 'dockerode'];
// Transitive native deps of dockerode that webpack fails to bundle.
// These are resolved at runtime through dockerode's dependency tree.
const transitiveBundleExcludes = ['ssh2', 'cpu-features'];
/** @type {import('next').NextConfig} */
const nextConfig = {
async rewrites() {
// REGISTRY_FIREWALL_URL が設定されている場合のみUIプロキシのrewriteを有効にする。
// 未設定時はrewriteを登録しないことで、タイムアウトせず即座に404を返す。
const registryFirewallUrl = process.env.REGISTRY_FIREWALL_URL;
if (!registryFirewallUrl) {
return [];
}
return [
{
source: '/api/registry-firewall/ui/:path*',
destination: `${registryFirewallUrl}/ui/:path*`,
},
];
},
// Server-side only packages (native modules that can't be bundled)
serverExternalPackages: serverOnlyPackages,
// Exclude frontend directory from build (used by Syncthing sync)
typescript: {
// Ignore build errors in excluded directories
ignoreBuildErrors: false,
},
// Exclude specific directories from being processed
pageExtensions: ['tsx', 'ts', 'jsx', 'js'],
// Transpile packages that have Turbopack compatibility issues
transpilePackages: ['react-diff-viewer-continued'],
// Turbopack設定(Next.js 16でデフォルト有効)
turbopack: {
// react-diff-viewer-continuedがWorkerで.tsファイルを参照しようとする問題を回避
resolveAlias: {
'./computeWorker.ts': './computeWorker.js',
},
resolveExtensions: ['.ts', '.tsx', '.js', '.jsx', '.json'],
},
webpack: (config, { isServer }) => {
// Ignore the frontend directory
config.watchOptions = {
...config.watchOptions,
ignored: ['**/frontend/**', '**/backend/**'],
};
// react-diff-viewer-continuedがWorkerで.tsファイルを参照しようとする問題を回避
// NormalModuleReplacementPluginで.ts参照を.jsに置き換える
config.plugins.push(
new webpack.NormalModuleReplacementPlugin(
/\.\/computeWorker\.ts$/,
'./computeWorker.js'
)
);
// サーバー側ビルドでネイティブモジュールを外部化
if (isServer) {
const allExternals = [...serverOnlyPackages, ...transitiveBundleExcludes];
const nativeExternals = Object.fromEntries(
allExternals.map(pkg => [pkg, `commonjs ${pkg}`])
);
if (typeof config.externals === 'function') {
config.externals = [config.externals, nativeExternals];
} else if (Array.isArray(config.externals)) {
config.externals.push(nativeExternals);
} else if (config.externals) {
config.externals = [config.externals, nativeExternals];
} else {
config.externals = [nativeExternals];
}
}
return config;
},
}
module.exports = nextConfig