fileserver/webpack.config.ts

68 lines
1.5 KiB
TypeScript

import { DefinePlugin } from 'webpack';
import * as nodeExternals from 'webpack-node-externals';
import * as copyPlugin from 'copy-webpack-plugin';
import TsconfigPathsPlugin from 'tsconfig-paths-webpack-plugin';
import { resolve } from 'path';
import * as pkg from './package.json';
function transform_package(input: Buffer): string {
const pkg = JSON.parse(input.toString());
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, null, '\t');
}
export default {
entry: './src/main.ts',
plugins: [
new DefinePlugin({
PROD: JSON.stringify(true)
}),
new copyPlugin({
patterns: [
{
from: resolve(__dirname, 'package.json'),
to: resolve(__dirname, 'dist', 'package.json'),
transform: transform_package
}
]
})
],
module: {
rules: [
{
test: /\.ts?$/,
use: 'ts-loader'
}
]
},
externalsPresets: { node: true },
mode: 'production',
resolve: {
plugins: [new TsconfigPathsPlugin()],
extensions: ['.ts', '.js']
},
output: {
filename: 'server.js',
path: resolve(__dirname, 'dist')
},
externals: [
nodeExternals({
allowlist: (dep) => !pkg.runtimeDependencies.includes(dep)
})
],
performance: {
maxEntrypointSize: 512 * 1024 * 1024,
maxAssetSize: 512 * 1024 * 1024
}
};