For those interested in how I tackled this issue, my solution involved utilizing webpack with the following configuration:
import webpack from 'webpack';
import path from 'path';
import nodeExternals from 'webpack-node-externals';
const config: webpack.Configuration = {
mode: "production",
entry: "./src/server.ts",
target: "node",
output: {
path: path.resolve(__dirname, 'dist'),
filename: "main.js"
},
resolve: {
extensions: [".ts", ".js"],
},
devtool: "source-map",
module: {
rules: [
{
test: /\.ts$/,
exclude: /node_modules/,
use: {
loader: "ts-loader",
options: {
transpileOnly: true
}
}
}
],
},
externals: nodeExternals()
}
export default config;
Additionally, on the Continuous Integration server, I executed the following commands:
npm install
webpack
npm ci
One key aspect of this approach is the utilization of npm ci
(introduced in npm v6), which eliminates devDependencies from node_modules
. Subsequently, I included both the node_modules
directory and transpiled js
files in the deployment package.