AFFiNE/apps/web/next.config.mjs

162 lines
4.1 KiB
JavaScript
Raw Normal View History

2023-03-02 05:13:45 +03:00
// @ts-check
import { createRequire } from 'node:module';
2023-02-19 11:40:39 +03:00
import path from 'node:path';
import { PerfseePlugin } from '@perfsee/webpack';
2023-02-19 11:40:39 +03:00
import debugLocal from 'next-debug-local';
import preset from './preset.config.mjs';
import { getCommitHash, getGitVersion } from './scripts/gitInfo.mjs';
2023-02-19 11:40:39 +03:00
const require = createRequire(import.meta.url);
console.info('Runtime Preset', preset);
const enableDebugLocal = path.isAbsolute(process.env.LOCAL_BLOCK_SUITE ?? '');
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',
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 = {
productionBrowserSourceMaps: true,
compiler: {
2023-03-04 10:36:20 +03:00
styledComponents: true,
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', {}],
// ['@swc-jotai/react-refresh', {}],
2023-03-08 11:29:50 +03:00
].filter(Boolean),
},
reactStrictMode: true,
2023-02-17 05:43:52 +03:00
transpilePackages: [
'@affine/component',
'@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
],
publicRuntimeConfig: {
PROJECT_NAME: process.env.npm_package_name ?? 'AFFiNE',
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 };
config.module.rules.push({
test: /\.md$/i,
loader: 'raw-loader',
});
config.resolve.alias['yjs'] = require.resolve('yjs');
2023-03-02 11:49:33 +03:00
if (!isServer && !dev) {
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];
}
}
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
);
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
const baseDir = process.env.LOCAL_BLOCK_SUITE ?? '/';
2023-02-19 11:40:39 +03:00
const withDebugLocal = debugLocal(
{
'@blocksuite/editor': path.resolve(baseDir, 'packages', 'editor'),
'@blocksuite/blocks/models': path.resolve(
baseDir,
'packages',
'blocks',
'src',
'models'
),
'@blocksuite/blocks/std': path.resolve(
baseDir,
'packages',
'blocks',
'src',
'std'
),
'@blocksuite/blocks/content-parser': path.resolve(
baseDir,
'packages',
'blocks',
'src',
'content-parser'
),
'@blocksuite/blocks': path.resolve(baseDir, 'packages', 'blocks'),
'@blocksuite/store': path.resolve(baseDir, 'packages', 'store'),
},
{
enable: enableDebugLocal,
}
);
2023-02-16 19:51:32 +03:00
const detectFirebaseConfig = () => {
if (!process.env.NEXT_PUBLIC_FIREBASE_API_KEY) {
console.warn('NEXT_PUBLIC_FIREBASE_API_KEY not found, please check it');
2023-02-16 19:51:32 +03:00
} else {
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);