Made webpack distribution have als little dependencies als possible

Closes #14
This commit is contained in:
Mutzi 2022-08-25 12:11:21 +02:00
parent 8e1cd73f39
commit fbaedc7049
3 changed files with 29 additions and 8 deletions

View File

@ -45,6 +45,15 @@
"thirty-two": "^1.0.2",
"typeorm": "^0.3.7"
},
"runtimeDependencies": [
"@nestjs/common",
"@nestjs/core",
"@nestjs/platform-fastify",
"@nestjs/serve-static",
"argon2",
"sqlite3",
"typeorm"
],
"devDependencies": {
"@nestjs/cli": "^9.0.0",
"@nestjs/schematics": "^9.0.1",

View File

@ -11,7 +11,8 @@
"outDir": "./dist",
"baseUrl": "./",
"incremental": true,
"skipLibCheck": true
"skipLibCheck": true,
"resolveJsonModule": true
},
"exclude": ["node_modules", "dist", "test", "**/*spec.ts", "frontend"]
}

View File

@ -2,14 +2,21 @@ import { DefinePlugin } from 'webpack';
import * as nodeExternals from 'webpack-node-externals';
import * as copyPlugin from 'copy-webpack-plugin';
import { resolve } from 'path';
import * as pkg from './package.json';
function transform_package(input: Buffer): string {
const pkg = JSON.parse(input.toString());
delete pkg['devDependencies'];
delete pkg['jest'];
pkg['scripts'] = {
start: 'node server.js'
};
pkg['dependencies'] = Object.fromEntries(
Object.entries<string>(pkg['dependencies']).filter((dep) =>
pkg['runtimeDependencies'].includes(dep[0])
)
);
delete pkg['runtimeDependencies'];
delete pkg['devDependencies'];
delete pkg['jest'];
return JSON.stringify(pkg);
}
@ -25,10 +32,6 @@ export default {
from: resolve(__dirname, 'package.json'),
to: resolve(__dirname, 'dist', 'package.json'),
transform: transform_package
},
{
from: resolve(__dirname, 'yarn.lock'),
to: resolve(__dirname, 'dist', 'yarn.lock')
}
]
})
@ -51,5 +54,13 @@ export default {
filename: 'server.js',
path: resolve(__dirname, 'dist')
},
externals: [nodeExternals()]
externals: [
nodeExternals({
allowlist: (dep) => !pkg.runtimeDependencies.includes(dep)
})
],
performance: {
maxEntrypointSize: 512 * 1024 * 1024,
maxAssetSize: 512 * 1024 * 1024
}
};