Repository navigation
Expand file tree
/
Copy pathrollup.config.js
More file actions
56 lines (53 loc) · 1.5 KB
/
Copy pathrollup.config.js
File metadata and controls
56 lines (53 loc) · 1.5 KB
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
48
49
50
51
52
53
54
55
56
import { babel } from '@rollup/plugin-babel';
import dts from 'rollup-plugin-dts';
const pkg = require('./package.json');
const external = Object.keys(pkg.dependencies).concat(Object.keys(pkg.peerDependencies));
/**
* Returns the build configuration of the module or of a secondary module e.g. controllers
* @param {string} input The entry point e.g. src/index.js
* @param {string} outDir The output directory e.g. dist
* @param {Array<string>=} extraExternal Additional external modules
*/
function createConfig(input, outDir, extraExternal = []) {
return [
{
input: `${input}.js`,
output: {
file: `${outDir}/index.cjs.js`,
format: 'cjs',
sourcemap: true
},
external: external.concat(extraExternal),
plugins: [babel({
babelHelpers: 'bundled'
})]
},
{
input: `${input}.js`,
output: {
file: `${outDir}/index.esm.js`,
format: 'esm',
sourcemap: true
},
external: external.concat(extraExternal),
plugins: [babel({
babelHelpers: 'bundled'
})]
},
{
input: `${input}.d.ts`,
output: [{ file: `${outDir}/index.d.ts`, format: 'es' }],
external: external.concat(extraExternal),
plugins: [dts({
compilerOptions: {
removeComments: true
}
})],
}
];
}
const config = [
...createConfig('src/index', 'dist'),
...createConfig('controllers/src/index', 'controllers/dist', [ '@themost/express' ])
];
export default config;