Repository navigation
Expand file tree
/
Copy pathnext.config.js
More file actions
296 lines (273 loc) · 9.51 KB
/
Copy pathnext.config.js
File metadata and controls
296 lines (273 loc) · 9.51 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
import createNextIntlPlugin from 'next-intl/plugin';
import path from 'path';
import { fileURLToPath } from 'url';
import { execSync } from 'child_process';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const withNextIntl = createNextIntlPlugin('./src/i18n/request.ts');
function resolveAppVersion() {
if (process.env.APP_VERSION) return process.env.APP_VERSION;
if (process.env.NEXT_PUBLIC_APP_VERSION) return process.env.NEXT_PUBLIC_APP_VERSION;
try {
const gitHash = execSync('git rev-parse --short HEAD', { stdio: ['ignore', 'pipe', 'ignore'] })
.toString()
.trim();
const commitDate = execSync('git log -1 --format=%cd --date=format:%Y.%m.%d', { stdio: ['ignore', 'pipe', 'ignore'] })
.toString()
.trim();
if (gitHash && commitDate) {
return `v${commitDate}-${gitHash}`;
}
} catch {
// Git not available or not a git repository
}
return process.env.npm_package_version || '0.1.0';
}
/** @type {import('next').NextConfig} */
const nextConfig = {
// Enable static export for deployment flexibility
output: 'export',
// Support deployment under a subpath (e.g., /pdfcraft/)
// Use BASE_PATH or NEXT_PUBLIC_BASE_PATH environment variable
basePath: process.env.BASE_PATH || process.env.NEXT_PUBLIC_BASE_PATH || '',
assetPrefix: process.env.TAURI_ENV ? '/' : undefined,
env: {
NEXT_PUBLIC_APP_VERSION: resolveAppVersion(),
NEXT_PUBLIC_BUILD_DATE: new Date().toISOString(),
NEXT_PUBLIC_DISABLE_UPDATE_CHECK:
process.env.DISABLE_UPDATE_CHECK || process.env.NEXT_PUBLIC_DISABLE_UPDATE_CHECK || 'false',
},
// Webpack configuration for WASM modules
webpack: (config, { isServer, webpack }) => {
// Handle qpdf-wasm and other modules that use Node.js built-ins
if (!isServer) {
config.resolve.fallback = {
...config.resolve.fallback,
fs: false,
path: false,
crypto: false,
module: false,
url: false,
worker_threads: false,
canvas: false, // Required for pdfjs-dist-legacy
};
} else {
// Mark canvas as external for server-side builds
config.externals = config.externals || [];
config.externals.push({
canvas: 'commonjs canvas',
});
}
// Also add module and canvas to alias for some packages that use it
config.resolve.alias = {
...config.resolve.alias,
'module': false,
};
// Ignore problematic modules that are not needed in browser
config.plugins.push(
new webpack.IgnorePlugin({
resourceRegExp: /^module$/
}),
new webpack.IgnorePlugin({
resourceRegExp: /^canvas$/,
contextRegExp: /pdfjs-dist-legacy/
})
);
// Enable WebAssembly
config.experiments = {
...config.experiments,
asyncWebAssembly: true,
};
return config;
},
// Image optimization configuration
// Note: unoptimized is required for static export
images: {
unoptimized: true,
// Define allowed image formats
formats: ['image/avif', 'image/webp'],
// Define device sizes for responsive images
deviceSizes: [640, 750, 828, 1080, 1200, 1920, 2048, 3840],
// Define image sizes for srcset
imageSizes: [16, 32, 48, 64, 96, 128, 256, 384],
// Minimum cache TTL for optimized images (in seconds)
minimumCacheTTL: 60 * 60 * 24 * 30, // 30 days
},
turbopack: {
resolveAlias: {
canvas: './src/lib/mocks/canvas.js',
},
},
// Trailing slash for static hosting compatibility
trailingSlash: true,
// Strict mode for better development experience
reactStrictMode: true,
// TypeScript configuration
typescript: {
// Allow production builds even with type errors during development
ignoreBuildErrors: false,
},
// ESLint configuration
eslint: {
// Run ESLint during builds
ignoreDuringBuilds: false,
},
// Compiler options for performance
compiler: {
// Remove console.log in production
removeConsole: process.env.NODE_ENV === 'production' ? {
exclude: ['error', 'warn'],
} : false,
},
// Headers configuration for caching
// Note: These headers are applied when running with `next start`
// For static export, configure headers in your hosting platform
async headers() {
return [
{
// LibreOffice WASM .wasm.bin.gz — serve as application/wasm with gzip Content-Encoding
// Same approach as BentoPDF's nginx config so browser decompresses transparently
source: '/libreoffice-wasm/soffice.wasm.bin.gz',
headers: [
{ key: 'Content-Type', value: 'application/wasm' },
{ key: 'Content-Encoding', value: 'gzip' },
{ key: 'Cache-Control', value: 'public, max-age=31536000, immutable' },
{ key: 'Cross-Origin-Embedder-Policy', value: 'require-corp' },
{ key: 'Cross-Origin-Opener-Policy', value: 'same-origin' },
{ key: 'Cross-Origin-Resource-Policy', value: 'cross-origin' },
],
},
{
// LibreOffice WASM .data.bin.gz — serve as application/octet-stream with gzip Content-Encoding
source: '/libreoffice-wasm/soffice.data.bin.gz',
headers: [
{ key: 'Content-Type', value: 'application/octet-stream' },
{ key: 'Content-Encoding', value: 'gzip' },
{ key: 'Cache-Control', value: 'public, max-age=31536000, immutable' },
{ key: 'Cross-Origin-Embedder-Policy', value: 'require-corp' },
{ key: 'Cross-Origin-Opener-Policy', value: 'same-origin' },
{ key: 'Cross-Origin-Resource-Policy', value: 'cross-origin' },
],
},
{
// LibreOffice WASM .wasm.bin (decompressed) — serve as application/wasm
source: '/libreoffice-wasm/soffice.wasm.bin',
headers: [
{ key: 'Content-Type', value: 'application/wasm' },
{ key: 'Cache-Control', value: 'public, max-age=31536000, immutable' },
{ key: 'Cross-Origin-Embedder-Policy', value: 'require-corp' },
{ key: 'Cross-Origin-Opener-Policy', value: 'same-origin' },
{ key: 'Cross-Origin-Resource-Policy', value: 'cross-origin' },
],
},
{
// LibreOffice WASM .data.bin (decompressed) — serve as application/octet-stream
source: '/libreoffice-wasm/soffice.data.bin',
headers: [
{ key: 'Content-Type', value: 'application/octet-stream' },
{ key: 'Cache-Control', value: 'public, max-age=31536000, immutable' },
{ key: 'Cross-Origin-Embedder-Policy', value: 'require-corp' },
{ key: 'Cross-Origin-Opener-Policy', value: 'same-origin' },
{ key: 'Cross-Origin-Resource-Policy', value: 'cross-origin' },
],
},
{
// LibreOffice WASM Worker - needs COEP to spawn workers with SharedArrayBuffer access
source: '/libreoffice-wasm/browser.worker.global.js',
headers: [
{ key: 'Content-Type', value: 'application/javascript' },
{ key: 'Cache-Control', value: 'public, max-age=31536000, immutable' },
{ key: 'Cross-Origin-Embedder-Policy', value: 'require-corp' },
{ key: 'Cross-Origin-Opener-Policy', value: 'same-origin' },
{ key: 'Cross-Origin-Resource-Policy', value: 'cross-origin' },
],
},
{
// Static assets - long cache
source: '/:path*.(ico|jpg|jpeg|png|gif|svg|webp|avif|woff|woff2|ttf|eot)',
headers: [
{
key: 'Cache-Control',
value: 'public, max-age=31536000, immutable',
},
{
key: 'Cross-Origin-Opener-Policy',
value: 'same-origin',
},
{
key: 'Cross-Origin-Embedder-Policy',
value: 'require-corp',
},
{
key: 'Cross-Origin-Resource-Policy',
value: 'cross-origin',
},
],
},
{
// JavaScript and CSS - cache with revalidation
source: '/:path*.(js|css)',
headers: [
{
key: 'Cache-Control',
value: 'public, max-age=31536000, immutable',
},
],
},
{
// MJS files (ES modules) - correct MIME for module scripts
source: '/:path*.mjs',
headers: [
{
key: 'Content-Type',
value: 'application/javascript; charset=utf-8',
},
{
key: 'Cache-Control',
value: 'public, max-age=31536000, immutable',
},
],
},
{
// Global security & caching headers for all routes
source: '/:path*',
headers: [
{
key: 'Cache-Control',
value: 'public, max-age=0, must-revalidate',
},
{
key: 'X-Content-Type-Options',
value: 'nosniff',
},
{
key: 'X-Frame-Options',
value: 'SAMEORIGIN',
},
{
key: 'X-XSS-Protection',
value: '1; mode=block',
},
{
key: 'Referrer-Policy',
value: 'strict-origin-when-cross-origin',
},
// Required for SharedArrayBuffer (LibreOffice WASM)
{
key: 'Cross-Origin-Opener-Policy',
value: 'same-origin',
},
{
key: 'Cross-Origin-Embedder-Policy',
value: 'require-corp',
},
{
key: 'Cross-Origin-Resource-Policy',
value: 'cross-origin',
},
],
},
];
},
};
export default withNextIntl(nextConfig);