File size: 1,337 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
import commonjs from '@rollup/plugin-commonjs';
import terser from '@rollup/plugin-terser';
import typescript from 'rollup-plugin-typescript2';
import pkg from '../../package.json';
/**
*
* @returns {import("rollup").RollupOptions}
*/
export function createRollupConfig(options, callback) {
const name = options.name;
// A file with the extension ".mjs" will always be treated as ESM, even when pkg.type is "commonjs" (the default)
// https://nodejs.org/docs/latest/api/packages.html#packages_determining_module_system
const extName = options.format === 'esm' ? 'mjs' : 'js';
const outputName = 'dist/' + [name, options.format, extName].join('.');
const config = {
input: options.input,
output: {
file: outputName,
format: options.format,
name: 'ReactHookForm',
sourcemap: true,
globals: { react: 'React' },
exports: 'named',
},
external: Object.keys(pkg.peerDependencies),
plugins: [
typescript({
clean: true,
}),
options.format === 'umd' &&
commonjs({
include: /\/node_modules\//,
}),
options.format !== 'esm' &&
terser({
output: { comments: false },
compress: { drop_console: true },
}),
].filter(Boolean),
};
return callback ? callback(config) : config;
}
|