fix @node-rs/jieba and window not found (#1313)

* dynamic import

* perf: entry

* fix: jieba package
This commit is contained in:
Archer
2024-04-28 10:27:34 +08:00
committed by GitHub
parent d407e87dd9
commit 59ece446a2
16 changed files with 560 additions and 139 deletions

View File

@@ -7,7 +7,7 @@ const nextConfig = {
output: 'standalone',
reactStrictMode: process.env.NODE_ENV === 'development' ? false : true,
compress: true,
webpack(config, { isServer }) {
webpack(config, { isServer, nextRuntime }) {
Object.assign(config.resolve.alias, {
'@mongodb-js/zstd': false,
'@aws-sdk/credential-providers': false,
@@ -26,6 +26,10 @@ const nextConfig = {
test: /\.svg$/i,
issuer: /\.[jt]sx?$/,
use: ['@svgr/webpack']
},
{
test: /\.node$/,
use: [{ loader: 'nextjs-node-loader' }]
}
]),
exprContextCritical: false,
@@ -33,11 +37,9 @@ const nextConfig = {
};
if (isServer) {
config.externals.push('isolated-vm');
config.externals.push('worker_threads');
config.externals.push('@node-rs/jieba');
if (config.name === 'server') {
if (nextRuntime === 'nodejs') {
// config.output.globalObject = 'self';
const oldEntry = config.entry;
@@ -76,7 +78,10 @@ const nextConfig = {
},
transpilePackages: ['@fastgpt/*'],
experimental: {
// 外部包独立打包
serverComponentsExternalPackages: ['mongoose', 'pg'],
// 指定导出包优化,按需引入包模块
optimizePackageImports: ['mongoose', 'pg'],
outputFileTracingRoot: path.join(__dirname, '../../')
}
};