fileserver/webpack.config.ts

67 lines
1.4 KiB
TypeScript

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());
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);
}
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',
devtool: 'inline-source-map',
resolve: {
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
}
};