2023-03-02 05:13:45 +03:00
|
|
|
// @ts-check
|
2023-03-02 21:01:09 +03:00
|
|
|
import { createRequire } from 'node:module';
|
2023-02-19 11:40:39 +03:00
|
|
|
import path from 'node:path';
|
2023-03-02 21:01:09 +03:00
|
|
|
|
|
|
|
import { PerfseePlugin } from '@perfsee/webpack';
|
2023-02-19 11:40:39 +03:00
|
|
|
import debugLocal from 'next-debug-local';
|
2023-03-02 21:01:09 +03:00
|
|
|
|
2023-03-01 10:40:01 +03:00
|
|
|
import preset from './preset.config.mjs';
|
|
|
|
import { getCommitHash, getGitVersion } from './scripts/gitInfo.mjs';
|
2023-02-19 11:40:39 +03:00
|
|
|
|
2023-03-01 10:40:01 +03:00
|
|
|
const require = createRequire(import.meta.url);
|
|
|
|
|
|
|
|
console.info('Runtime Preset', preset);
|
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 ?? '');
|
|
|
|
|
2023-03-22 09:09:30 +03:00
|
|
|
if (enableDebugLocal) {
|
|
|
|
console.info('Debugging local blocksuite');
|
|
|
|
}
|
|
|
|
|
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,
|
2023-03-01 10:40:01 +03:00
|
|
|
compiler: {
|
2023-03-04 10:36:20 +03:00
|
|
|
styledComponents: true,
|
2023-03-01 10:40:01 +03:00
|
|
|
removeConsole: {
|
|
|
|
exclude: ['error', 'log', 'warn', 'info'],
|
|
|
|
},
|
|
|
|
emotion: {
|
|
|
|
sourceMap: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
images: {
|
|
|
|
unoptimized: true,
|
|
|
|
},
|
|
|
|
experimental: {
|
|
|
|
swcPlugins: [
|
2023-03-08 11:29:50 +03:00
|
|
|
process.env.COVERAGE === 'true' && ['swc-plugin-coverage-instrument', {}],
|
2023-03-20 10:05:02 +03:00
|
|
|
// ['@swc-jotai/debug-label', {}],
|
2023-03-01 10:40:01 +03:00
|
|
|
// ['@swc-jotai/react-refresh', {}],
|
2023-03-08 11:29:50 +03:00
|
|
|
].filter(Boolean),
|
2022-12-30 16:40:15 +03:00
|
|
|
},
|
2023-03-01 10:40:01 +03:00
|
|
|
reactStrictMode: true,
|
2023-02-17 05:43:52 +03:00
|
|
|
transpilePackages: [
|
|
|
|
'@affine/component',
|
2023-03-01 10:40:01 +03:00
|
|
|
'@affine/i18n',
|
2023-03-02 05:13:45 +03:00
|
|
|
'@affine/debug',
|
2023-03-02 04:26:55 +03:00
|
|
|
'@affine/env',
|
2023-03-11 08:15:19 +03:00
|
|
|
'@affine/templates',
|
2023-02-17 05:43:52 +03:00
|
|
|
],
|
2023-03-01 10:40:01 +03:00
|
|
|
publicRuntimeConfig: {
|
2023-03-24 01:15:40 +03:00
|
|
|
PROJECT_NAME: process.env.npm_package_name ?? 'AFFiNE',
|
2023-03-01 10:40:01 +03:00
|
|
|
BUILD_DATE: new Date().toISOString(),
|
|
|
|
gitVersion: getGitVersion(),
|
|
|
|
hash: getCommitHash(),
|
|
|
|
serverAPI:
|
|
|
|
profileTarget[process.env.NODE_API_SERVER || 'dev'] ?? profileTarget.dev,
|
|
|
|
editorVersion: require('./package.json').dependencies['@blocksuite/editor'],
|
|
|
|
...preset,
|
|
|
|
},
|
2023-03-02 11:49:33 +03:00
|
|
|
webpack: (config, { dev, isServer }) => {
|
2022-12-30 14:42:01 +03:00
|
|
|
config.experiments = { ...config.experiments, topLevelAwait: true };
|
2022-12-30 16:40:15 +03:00
|
|
|
config.module.rules.push({
|
|
|
|
test: /\.md$/i,
|
|
|
|
loader: 'raw-loader',
|
|
|
|
});
|
2023-03-02 22:50:23 +03:00
|
|
|
config.resolve.alias['yjs'] = require.resolve('yjs');
|
2022-12-30 16:40:15 +03:00
|
|
|
|
2023-03-28 07:05:49 +03:00
|
|
|
if (!isServer && !dev && process.env.PERFSEE_TOKEN) {
|
2023-03-02 11:49:33 +03:00
|
|
|
config.devtool = 'hidden-nosources-source-map';
|
|
|
|
const perfsee = new PerfseePlugin({
|
|
|
|
project: 'affine-toeverything',
|
|
|
|
});
|
|
|
|
if (Array.isArray(config.plugins)) {
|
|
|
|
config.plugins.push(perfsee);
|
|
|
|
} else {
|
|
|
|
config.plugins = [perfsee];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-30 16:40:15 +03:00
|
|
|
return config;
|
|
|
|
},
|
|
|
|
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-03-01 10:40:01 +03:00
|
|
|
console.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
|
|
|
},
|
2023-02-14 09:51:05 +03:00
|
|
|
basePath: process.env.NEXT_BASE_PATH,
|
2023-03-03 05:00:56 +03:00
|
|
|
pageExtensions: [...(preset.enableDebugPage ? ['tsx', 'dev.tsx'] : ['tsx'])],
|
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 ?? '/';
|
2023-02-19 11:40:39 +03:00
|
|
|
const withDebugLocal = debugLocal(
|
2022-12-30 16:40:15 +03:00
|
|
|
{
|
|
|
|
'@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'
|
|
|
|
),
|
2023-03-22 08:17:57 +03:00
|
|
|
'@blocksuite/blocks/content-parser': path.resolve(
|
|
|
|
baseDir,
|
|
|
|
'packages',
|
|
|
|
'blocks',
|
|
|
|
'src',
|
|
|
|
'content-parser'
|
|
|
|
),
|
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-02-16 19:51:32 +03:00
|
|
|
const detectFirebaseConfig = () => {
|
|
|
|
if (!process.env.NEXT_PUBLIC_FIREBASE_API_KEY) {
|
2023-03-01 10:40:01 +03:00
|
|
|
console.warn('NEXT_PUBLIC_FIREBASE_API_KEY not found, please check it');
|
2023-02-16 19:51:32 +03:00
|
|
|
} else {
|
2023-03-01 10:40:01 +03:00
|
|
|
console.info('NEXT_PUBLIC_FIREBASE_API_KEY found');
|
2023-02-16 19:51:32 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
detectFirebaseConfig();
|
2023-01-03 06:43:59 +03:00
|
|
|
|
2023-02-19 11:40:39 +03:00
|
|
|
export default withDebugLocal(nextConfig);
|