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 6650413d2b..3fc92ba3b6 100644 --- a/packages/nocodb/src/Noco.ts +++ b/packages/nocodb/src/Noco.ts @@ -96,6 +96,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, @@ -103,6 +105,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 {