2022-12-30 16:40:15 +03:00
|
|
|
/* eslint @typescript-eslint/no-var-requires: "off" */
|
2022-11-03 13:50:27 +03:00
|
|
|
const { getGitVersion, getCommitHash } = require('./scripts/gitInfo');
|
2022-12-30 16:40:15 +03:00
|
|
|
const { dependencies } = require('./package.json');
|
|
|
|
const path = require('node:path');
|
|
|
|
const printer = require('./scripts/printer').printer;
|
2022-10-17 20:31:40 +03:00
|
|
|
|
2023-01-01 19:57:08 +03:00
|
|
|
const enableDebugLocal = path.isAbsolute(process.env.LOCAL_BLOCK_SUITE ?? '');
|
|
|
|
const EDITOR_VERSION = enableDebugLocal
|
|
|
|
? 'local-version'
|
|
|
|
: dependencies['@blocksuite/editor'];
|
|
|
|
|
2023-01-07 12:01:10 +03:00
|
|
|
const profileTarget = {
|
|
|
|
ac: '100.85.73.88:12001',
|
2023-02-09 10:24:25 +03:00
|
|
|
dev: '100.84.105.99:11001',
|
|
|
|
test: '100.84.105.99:11001',
|
2023-01-14 05:07:59 +03:00
|
|
|
stage: '',
|
|
|
|
pro: 'http://pathfinder.affine.pro',
|
2023-01-07 12:01:10 +03:00
|
|
|
local: '127.0.0.1:3000',
|
|
|
|
};
|
|
|
|
|
|
|
|
const getRedirectConfig = profile => {
|
|
|
|
const target = profileTarget[profile || 'dev'] || profileTarget['dev'];
|
|
|
|
|
|
|
|
return [
|
|
|
|
[
|
|
|
|
{ source: '/api/:path*', destination: `http://${target}/api/:path*` },
|
|
|
|
{
|
|
|
|
source: '/collaboration/:path*',
|
|
|
|
destination: `http://${target}/collaboration/:path*`,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
target,
|
2023-02-10 15:41:01 +03:00
|
|
|
profile || 'dev',
|
2023-01-07 12:01:10 +03:00
|
|
|
];
|
|
|
|
};
|
|
|
|
|
2022-09-22 10:39:53 +03:00
|
|
|
/** @type {import('next').NextConfig} */
|
2022-11-03 09:53:44 +03:00
|
|
|
const nextConfig = {
|
2022-10-14 14:29:36 +03:00
|
|
|
productionBrowserSourceMaps: true,
|
2022-12-30 16:40:15 +03:00
|
|
|
reactStrictMode: false,
|
2022-10-14 14:29:36 +03:00
|
|
|
swcMinify: false,
|
2022-11-03 13:50:27 +03:00
|
|
|
publicRuntimeConfig: {
|
|
|
|
NODE_ENV: process.env.NODE_ENV,
|
|
|
|
PROJECT_NAME: process.env.npm_package_name,
|
|
|
|
BUILD_DATE: new Date().toISOString(),
|
|
|
|
CI: process.env.CI || null,
|
|
|
|
VERSION: getGitVersion(),
|
|
|
|
COMMIT_HASH: getCommitHash(),
|
2023-01-01 19:57:08 +03:00
|
|
|
EDITOR_VERSION,
|
2022-12-30 16:40:15 +03:00
|
|
|
},
|
2023-02-14 06:18:43 +03:00
|
|
|
transpilePackages: ['@affine/component', '@affine/i18n'],
|
2022-12-30 16:40:15 +03:00
|
|
|
webpack: config => {
|
2022-12-30 14:42:01 +03:00
|
|
|
config.experiments = { ...config.experiments, topLevelAwait: true };
|
2022-12-30 16:40:15 +03:00
|
|
|
config.resolve.alias['yjs'] = require.resolve('yjs');
|
|
|
|
config.module.rules.push({
|
|
|
|
test: /\.md$/i,
|
|
|
|
loader: 'raw-loader',
|
|
|
|
});
|
|
|
|
|
|
|
|
return config;
|
|
|
|
},
|
|
|
|
images: {
|
|
|
|
unoptimized: true,
|
|
|
|
},
|
|
|
|
rewrites: async () => {
|
2023-02-10 15:41:01 +03:00
|
|
|
const [profile, target, desc] = getRedirectConfig(
|
|
|
|
process.env.NODE_API_SERVER
|
2023-01-07 12:01:10 +03:00
|
|
|
);
|
2023-02-10 15:41:01 +03:00
|
|
|
printer.info(`API request proxy to [${desc} Server]: ` + target);
|
2023-01-07 12:01:10 +03:00
|
|
|
return profile;
|
2022-11-03 13:50:27 +03:00
|
|
|
},
|
2022-12-19 11:40:07 +03:00
|
|
|
basePath: process.env.BASE_PATH,
|
2023-02-08 23:53:30 +03:00
|
|
|
experimental: {
|
|
|
|
forceSwcTransforms: true,
|
|
|
|
},
|
2022-11-03 09:53:44 +03:00
|
|
|
};
|
2022-09-22 10:39:53 +03:00
|
|
|
|
2022-12-30 16:40:15 +03:00
|
|
|
const baseDir = process.env.LOCAL_BLOCK_SUITE ?? '/';
|
|
|
|
const withDebugLocal = require('next-debug-local')(
|
|
|
|
{
|
|
|
|
'@blocksuite/editor': path.resolve(baseDir, 'packages', 'editor'),
|
2023-01-01 19:57:08 +03:00
|
|
|
'@blocksuite/blocks/models': path.resolve(
|
|
|
|
baseDir,
|
|
|
|
'packages',
|
|
|
|
'blocks',
|
|
|
|
'src',
|
|
|
|
'models'
|
|
|
|
),
|
|
|
|
'@blocksuite/blocks/std': path.resolve(
|
|
|
|
baseDir,
|
|
|
|
'packages',
|
|
|
|
'blocks',
|
|
|
|
'src',
|
|
|
|
'std'
|
|
|
|
),
|
2022-12-30 16:40:15 +03:00
|
|
|
'@blocksuite/blocks': path.resolve(baseDir, 'packages', 'blocks'),
|
|
|
|
'@blocksuite/store': path.resolve(baseDir, 'packages', 'store'),
|
|
|
|
},
|
|
|
|
{
|
2023-01-01 19:57:08 +03:00
|
|
|
enable: enableDebugLocal,
|
2022-12-30 16:40:15 +03:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2023-01-03 06:43:59 +03:00
|
|
|
const withPWA = require('next-pwa')({
|
|
|
|
dest: 'public',
|
2023-02-01 18:43:54 +03:00
|
|
|
scope: '/_next',
|
2023-01-03 06:43:59 +03:00
|
|
|
disable: process.env.NODE_ENV !== 'production',
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = withDebugLocal(withPWA(nextConfig));
|