tvbox_config/nodejs/esbuild.js
liushiquan 36ab603d34 init
2024-06-01 22:41:46 +08:00

28 lines
652 B
JavaScript

import * as esbuild from 'esbuild';
import fs from 'fs';
import { createHash } from 'crypto';
esbuild.build({
entryPoints: ['src/index.js'],
outfile: 'dist/index.js',
bundle: true,
minify: true,
write: true,
format: 'cjs',
platform: 'node',
target: 'node18',
plugins: [genMd5()],
});
function genMd5() {
return {
name: 'gen-output-file-md5',
setup(build) {
build.onEnd(async (_) => {
const md5 = createHash('md5').update(fs.readFileSync('dist/index.js')).digest('hex');
fs.writeFileSync('dist/index.js.md5', md5);
});
},
};
}