From 6a8fd63f7ea9f4e03bcadd11cce392376343fd7c Mon Sep 17 00:00:00 2001 From: DarkPhoenix2704 Date: Sun, 17 Nov 2024 03:39:56 +0000 Subject: [PATCH] wip: rspack --- packages/nocodb/rspack.dev.base.config.js | 96 +++++++++++++++++++++++ packages/nocodb/src/Noco.ts | 7 ++ 2 files changed, 103 insertions(+) create mode 100644 packages/nocodb/rspack.dev.base.config.js diff --git a/packages/nocodb/rspack.dev.base.config.js b/packages/nocodb/rspack.dev.base.config.js new file mode 100644 index 0000000000..fa62f284b0 --- /dev/null +++ b/packages/nocodb/rspack.dev.base.config.js @@ -0,0 +1,96 @@ +const { join } = require('path'); +const { rspack } = require('@rspack/core'); +const NodeExternals = require('webpack-node-externals'); +const { RunScriptWebpackPlugin } = require('run-script-webpack-plugin'); + +const baseDevConfig = { + mode: 'development', + target: 'node', + devtool: 'eval-source-map', + module: { + rules: [ + { + test: /\.node$/, + loader: 'node-loader', + options: { + name: '[path][name].[ext]', + }, + }, + { + test: /\.tsx?$/, + exclude: /node_modules/, + loader: 'builtin:swc-loader', + options: { + jsc: { + parser: { + syntax: 'typescript', + tsx: true, + decorators: true, + dynamicImport: true, + }, + transform: { + legacyDecorator: true, + decoratorMetadata: true, + }, + target: 'es2017', + }, + module: { + type: 'commonjs', + }, + }, + }, + ], + }, + externals: [ + NodeExternals({ + allowlist: ['webpack/hot/poll?1000'], + }), + { + '@nestjs/microservices': '@nestjs/microservices', + '@nestjs/microservices/microservices-module': + '@nestjs/microservices/microservices-module', + sharp: 'commonjs sharp', + 'nocodb-sdk': 'nocodb-sdk', + 'pg-query-stream': 'pg-query-stream', + 'better-sqlite3': 'better-sqlite3', + oracledb: 'oracledb', + 'pg-native': 'pg-native', + '@nestjs/graphql': '@nestjs/graphql', + pg: 'commonjs pg', + knex: 'commonjs knex', + }, + ], + resolve: { + extensions: ['.tsx', '.ts', '.js', '.json', '.node'], + }, + optimization: { + minimize: false, + nodeEnv: false, + }, + plugins: [ + new rspack.EnvironmentPlugin({ + EE: true, + NODE_ENV: 'development', + }), + new RunScriptWebpackPlugin({ + name: 'main.js', + autoRestart: true, + }), + ], + output: { + path: join(__dirname, 'dist'), + filename: 'main.js', + library: { + type: 'commonjs2', + }, + clean: true, + }, + devServer: { + devMiddleware: { + writeToDisk: true, + }, + port: 9001, + }, +}; + +module.exports = baseDevConfig; diff --git a/packages/nocodb/src/Noco.ts b/packages/nocodb/src/Noco.ts index ce58ea5c36..85dab58296 100644 --- a/packages/nocodb/src/Noco.ts +++ b/packages/nocodb/src/Noco.ts @@ -97,6 +97,8 @@ export default class Noco { return (this.ee = false); } + declare module: any; + static async init(param: any, httpServer: http.Server, server: Express) { const nestApp = await NestFactory.create(AppModule, { bufferLogs: true, @@ -104,6 +106,11 @@ export default class Noco { this.initCustomLogger(nestApp); nestApp.flushLogs(); + if (module.hot) { + module.hot.accept(); + module.hot.dispose(() => nestApp.close()); + } + try { this.sharp = (await import('sharp')).default; } catch {