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

38 lines
1.0 KiB
JavaScript

import * as rollup from 'rollup';
import json from '@rollup/plugin-json';
import commonjs from '@rollup/plugin-commonjs';
import fs from 'fs';
import { createHash } from 'crypto';
rollup
.rollup({
input: ['./src/index.config.js'],
plugins: [commonjs(), json()],
onwarn: function (message) {
console.log(message.toString());
},
})
.then((build) => {
build
.write({
dir: './dist',
format: 'cjs',
entryFileNames: '[name].js',
strict: false,
plugins: [genMd5()],
})
.then((output) => {
console.log(output.output.map((o) => o.fileName));
});
});
function genMd5() {
return {
name: 'gen-output-file-md5',
writeBundle() {
const md5 = createHash('md5').update(fs.readFileSync('./dist/index.config.js')).digest('hex');
fs.writeFileSync('./dist/index.config.js.md5', md5);
},
};
}