From 0417363009d04b163dd42093c3e5737e69e1dc18 Mon Sep 17 00:00:00 2001 From: DarkPhoenix2704 Date: Sun, 17 Nov 2024 03:39:56 +0000 Subject: [PATCH] chore: build to rspack and swc --- ...ack.cli.config.js => rspack.cli.config.js} | 33 ++++--- packages/nocodb/rspack.config.js | 91 +++++++++++++++++++ packages/nocodb/rspack.local.config.js | 90 ++++++++++++++++++ packages/nocodb/rspack.timely.config.js | 91 +++++++++++++++++++ packages/nocodb/webpack.config.js | 60 ------------ packages/nocodb/webpack.local.config.js | 59 ------------ packages/nocodb/webpack.timely.config.js | 57 ------------ 7 files changed, 291 insertions(+), 190 deletions(-) rename packages/nocodb/{webpack.cli.config.js => rspack.cli.config.js} (67%) create mode 100644 packages/nocodb/rspack.config.js create mode 100644 packages/nocodb/rspack.local.config.js create mode 100644 packages/nocodb/rspack.timely.config.js delete mode 100644 packages/nocodb/webpack.config.js delete mode 100644 packages/nocodb/webpack.local.config.js delete mode 100644 packages/nocodb/webpack.timely.config.js diff --git a/packages/nocodb/webpack.cli.config.js b/packages/nocodb/rspack.cli.config.js similarity index 67% rename from packages/nocodb/webpack.cli.config.js rename to packages/nocodb/rspack.cli.config.js index 704f57dffa..218d81288d 100644 --- a/packages/nocodb/webpack.cli.config.js +++ b/packages/nocodb/rspack.cli.config.js @@ -1,7 +1,5 @@ const path = require('path'); -const nodeExternals = require('webpack-node-externals'); -const webpack = require('webpack'); -const TerserPlugin = require('terser-webpack-plugin'); +const { rspack } = require('@rspack/core'); const { resolveTsAliases } = require('./build-utils/resolveTsAliases'); module.exports = { @@ -20,21 +18,26 @@ module.exports = { }, ], }, - optimization: { minimize: true, minimizer: [ - new TerserPlugin({ - extractComments: false, + new rspack.SwcJsMinimizerRspackPlugin({ + minimizerOptions: { + format: { + comments: false, + }, + }, }), ], nodeEnv: false, }, - externals: [ - nodeExternals({ - allowlist: ['nocodb-sdk'], - }), - ], + externals: { + 'nocodb-sdk': 'nocodb-sdk', + 'pg-query-stream': 'pg-query-stream', + 'better-sqlite3': 'better-sqlite3', + oracledb: 'oracledb', + 'pg-native': 'pg-native', + }, resolve: { extensions: ['.tsx', '.ts', '.js', '.json'], alias: resolveTsAliases(path.resolve('tsconfig.json')), @@ -51,10 +54,12 @@ module.exports = { __dirname: false, }, plugins: [ - new webpack.EnvironmentPlugin(['EE']), - new webpack.BannerPlugin({ + new rspack.EnvironmentPlugin({ + EE: true, + }), + new rspack.BannerPlugin({ banner: 'This is a generated file. Do not edit', - entryOnly:true + entryOnly: true, }), ], target: 'node', diff --git a/packages/nocodb/rspack.config.js b/packages/nocodb/rspack.config.js new file mode 100644 index 0000000000..2b23469e71 --- /dev/null +++ b/packages/nocodb/rspack.config.js @@ -0,0 +1,91 @@ +const path = require('path'); +const { rspack } = require('@rspack/core'); +const { resolveTsAliases } = require('./build-utils/resolveTsAliases'); + +module.exports = { + entry: './src/index.ts', + 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', + }, + }, + }, + ], + }, + + optimization: { + minimize: true, //Update this to true or false + minimizer: [ + new rspack.SwcJsMinimizerRspackPlugin({ + minimizerOptions: { + compress: { + keep_classnames: true, + }, + }, + }), + ], + nodeEnv: false, + }, + externals: { + '@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', + }, + resolve: { + extensions: ['.tsx', '.ts', '.js', '.json'], + alias: resolveTsAliases(path.resolve('tsconfig.json')), + }, + mode: 'production', + output: { + filename: 'bundle.js', + path: path.resolve(__dirname, 'dist'), + library: 'libs', + libraryTarget: 'umd', + globalObject: "typeof self !== 'undefined' ? self : this", + }, + node: { + __dirname: false, + }, + plugins: [ + new rspack.EnvironmentPlugin({ + EE: true, + }), + new rspack.CopyRspackPlugin({ + patterns: [{ from: 'src/public', to: 'public' }], + }), + ], + target: 'node', +}; diff --git a/packages/nocodb/rspack.local.config.js b/packages/nocodb/rspack.local.config.js new file mode 100644 index 0000000000..29a2dd7c08 --- /dev/null +++ b/packages/nocodb/rspack.local.config.js @@ -0,0 +1,90 @@ +const path = require('path'); +const { rspack } = require('@rspack/core'); +const { resolveTsAliases } = require('./build-utils/resolveTsAliases'); + +module.exports = { + entry: './src/run/local.ts', + // devtool: 'inline-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', + }, + }, + }, + ], + }, + + optimization: { + minimize: true, //Update this to true or false + minimizer: [ + new rspack.SwcJsMinimizerRspackPlugin({ + minimizerOptions: { + compress: { + keep_classnames: true, + }, + }, + }), + ], + nodeEnv: false, + }, + externals: { + '@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', + }, + resolve: { + extensions: ['.tsx', '.ts', '.js', '.json', '.node'], + alias: resolveTsAliases(path.resolve('tsconfig.json')), + }, + mode: 'production', + output: { + filename: 'main.js', + path: path.resolve(__dirname, 'docker'), + library: 'libs', + libraryTarget: 'umd', + globalObject: "typeof self !== 'undefined' ? self : this", + }, + node: { + __dirname: false, + }, + plugins: [ + new rspack.EnvironmentPlugin({ + EE: true, + }), + ], + + target: 'node', +}; diff --git a/packages/nocodb/rspack.timely.config.js b/packages/nocodb/rspack.timely.config.js new file mode 100644 index 0000000000..b053d07879 --- /dev/null +++ b/packages/nocodb/rspack.timely.config.js @@ -0,0 +1,91 @@ +const path = require('path'); +const { rspack } = require('@rspack/core'); +const { resolveTsAliases } = require('./build-utils/resolveTsAliases'); + +module.exports = { + entry: './src/run/timely.ts', + 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', + }, + }, + }, + ], + }, + + optimization: { + minimize: true, //Update this to true or false + minimizer: [ + new rspack.SwcJsMinimizerRspackPlugin({ + minimizerOptions: { + compress: { + keep_classnames: true, + }, + }, + }), + ], + nodeEnv: false, + }, + externals: { + '@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', + }, + resolve: { + extensions: ['.tsx', '.ts', '.js', '.json', '.node'], + alias: resolveTsAliases(path.resolve('./tsconfig.json')), + }, + mode: 'production', + output: { + filename: 'main.js', + path: path.resolve(__dirname, 'docker'), + library: 'libs', + libraryTarget: 'umd', + globalObject: "typeof self !== 'undefined' ? self : this", + }, + node: { + __dirname: false, + }, + plugins: [ + new rspack.EnvironmentPlugin({ + EE: true, + }), + new rspack.CopyRspackPlugin({ + patterns: [{ from: 'src/public', to: 'public' }], + }), + ], + target: 'node', +}; diff --git a/packages/nocodb/webpack.config.js b/packages/nocodb/webpack.config.js deleted file mode 100644 index 62a9ae5432..0000000000 --- a/packages/nocodb/webpack.config.js +++ /dev/null @@ -1,60 +0,0 @@ -const path = require('path'); -const nodeExternals = require('webpack-node-externals'); -const webpack = require('webpack'); -const CopyPlugin = require('copy-webpack-plugin'); -const TerserPlugin = require('terser-webpack-plugin'); -const { resolveTsAliases } = require('./build-utils/resolveTsAliases'); - -module.exports = { - entry: './src/index.ts', - module: { - rules: [ - { - test: /\.tsx?$/, - exclude: /node_modules/, - use: { - loader: 'ts-loader', - options: { - transpileOnly: true, - }, - }, - }, - ], - }, - - optimization: { - minimize: true, //Update this to true or false - minimizer: [ - new TerserPlugin({ - terserOptions: { - keep_classnames: true, - }, - }), - ], - nodeEnv: false, - }, - externals: [nodeExternals()], - resolve: { - extensions: ['.tsx', '.ts', '.js', '.json'], - alias: resolveTsAliases(path.resolve('tsconfig.json')), - }, - mode: 'production', - output: { - filename: 'bundle.js', - path: path.resolve(__dirname, 'dist'), - library: 'libs', - libraryTarget: 'umd', - globalObject: "typeof self !== 'undefined' ? self : this", - }, - node: { - __dirname: false, - }, - plugins: [ - new webpack.EnvironmentPlugin(['EE']), - new CopyPlugin({ - patterns: [{ from: 'src/public', to: 'public' }], - }), - ], - - target: 'node', -}; diff --git a/packages/nocodb/webpack.local.config.js b/packages/nocodb/webpack.local.config.js deleted file mode 100644 index 210dbcf789..0000000000 --- a/packages/nocodb/webpack.local.config.js +++ /dev/null @@ -1,59 +0,0 @@ -const path = require('path'); -const nodeExternals = require('webpack-node-externals'); -const webpack = require('webpack'); -const TerserPlugin = require('terser-webpack-plugin'); -const { resolveTsAliases } = require('./build-utils/resolveTsAliases'); - -module.exports = { - entry: './src/run/local.ts', - // devtool: 'inline-source-map', - module: { - rules: [ - { - test: /\.tsx?$/, - exclude: /node_modules/, - use: { - loader: 'ts-loader', - options: { - transpileOnly: true, - }, - }, - }, - ], - }, - - optimization: { - minimize: true, //Update this to true or false - minimizer: [ - new TerserPlugin({ - terserOptions: { - keep_classnames: true, - }, - }), - ], - nodeEnv: false, - }, - externals: [ - nodeExternals({ - allowlist: ['nocodb-sdk'], - }), - ], - resolve: { - extensions: ['.tsx', '.ts', '.js', '.json'], - alias: resolveTsAliases(path.resolve('tsconfig.json')), - }, - mode: 'production', - output: { - filename: 'main.js', - path: path.resolve(__dirname, 'docker'), - library: 'libs', - libraryTarget: 'umd', - globalObject: "typeof self !== 'undefined' ? self : this", - }, - node: { - __dirname: false, - }, - plugins: [new webpack.EnvironmentPlugin(['EE'])], - - target: 'node', -}; diff --git a/packages/nocodb/webpack.timely.config.js b/packages/nocodb/webpack.timely.config.js deleted file mode 100644 index 6878e3add7..0000000000 --- a/packages/nocodb/webpack.timely.config.js +++ /dev/null @@ -1,57 +0,0 @@ -const path = require('path'); -const nodeExternals = require('webpack-node-externals'); -const webpack = require('webpack'); -const CopyPlugin = require('copy-webpack-plugin'); -const TerserPlugin = require('terser-webpack-plugin'); -const { resolveTsAliases } = require('./build-utils/resolveTsAliases'); - -module.exports = { - entry: './src/run/timely.ts', - module: { - rules: [ - { - test: /\.tsx?$/, - exclude: /node_modules/, - use: { - loader: 'ts-loader', - options: { - transpileOnly: true, - }, - }, - }, - ], - }, - - optimization: { - minimize: true, //Update this to true or false - minimizer: [new TerserPlugin()], - nodeEnv: false, - }, - externals: [ - nodeExternals({ - allowlist: ['nocodb-sdk'], - }), - ], - resolve: { - extensions: ['.tsx', '.ts', '.js', '.json'], - alias: resolveTsAliases(path.resolve('./tsconfig.json')), - }, - mode: 'production', - output: { - filename: 'main.js', - path: path.resolve(__dirname, 'docker'), - library: 'libs', - libraryTarget: 'umd', - globalObject: "typeof self !== 'undefined' ? self : this", - }, - node: { - __dirname: false, - }, - plugins: [ - new webpack.EnvironmentPlugin(['EE']), - new CopyPlugin({ - patterns: [{ from: 'src/public', to: 'public' }], - }), - ], - target: 'node', -};