Mirror: Rollup plugin to automatically check the exports of a library for cjs-module-lexer compatibility.
1import { builtinModules } from 'module';
2import { readFileSync } from 'fs';
3
4import cjsCheck from './src/index.mjs';
5
6const pkg = JSON.parse(readFileSync('./package.json', 'utf-8'));
7
8const output = format => {
9 const extension = format === 'esm' ? '.mjs' : '.js';
10 return {
11 chunkFileNames: '[hash]' + extension,
12 entryFileNames: '[name]' + extension,
13 dir: './dist',
14 exports: 'named',
15 sourcemap: true,
16 indent: false,
17 freeze: false,
18 strict: false,
19 format,
20 esModule: format !== 'esm',
21 externalLiveBindings: format !== 'esm',
22 generatedCode: {
23 preset: 'es5',
24 reservedNamesAsProps: false,
25 objectShorthand: false,
26 constBindings: false,
27 },
28 };
29};
30
31export default {
32 input: {
33 'rollup-plugin-cjs-check': './src/index.mjs',
34 },
35 external: [
36 ...builtinModules,
37 ...Object.keys(pkg.dependencies || {}),
38 ...Object.keys(pkg.peerDependencies || {}),
39 ],
40 onwarn() {},
41 plugins: [
42 cjsCheck(),
43 ],
44 treeshake: {
45 unknownGlobalSideEffects: false,
46 tryCatchDeoptimization: false,
47 moduleSideEffects: false,
48 },
49 output: [
50 output('esm'),
51 output('cjs')
52 ],
53};