-
Notifications
You must be signed in to change notification settings - Fork 23
/
rollup.config.js
103 lines (96 loc) · 2.26 KB
/
rollup.config.js
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import fs from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import terser from '@rollup/plugin-terser';
import dts from 'rollup-plugin-dts';
import typescript from 'rollup-plugin-typescript2';
const resolve = (...args) =>
path.resolve(path.dirname(fileURLToPath(import.meta.url)), ...args);
const pkg = JSON.parse(fs.readFileSync(resolve('./package.json')));
const banner = `\
/*!
* ${pkg.name} - ${pkg.description}
*
* @version v${pkg.version}
* @link ${pkg.homepage}
* @license ${pkg.license}
* @copyright 2018-${new Date().getFullYear()} meteorlxy
*/
`;
let hasTSChecked = false;
export default [
{
input: 'index.ts',
output: 'vue-showdown.cjs.js',
format: 'cjs',
},
{
input: 'index.ts',
output: 'vue-showdown.esm.js',
format: 'es',
},
{
input: 'index.ts',
output: 'vue-showdown.esm.min.js',
format: 'es',
},
{
input: 'index.umd.ts',
output: 'vue-showdown.js',
format: 'umd',
globals: {
showdown: 'showdown',
vue: 'Vue',
},
},
{
input: 'index.umd.ts',
output: 'vue-showdown.min.js',
format: 'umd',
globals: {
showdown: 'showdown',
vue: 'Vue',
},
},
]
.map((opts) => {
const config = {
input: resolve('src', opts.input),
output: {
file: resolve('dist', opts.output),
format: opts.format,
name: 'VueShowdown',
globals: opts.globals,
banner,
exports: 'named',
},
external: ['showdown', 'vue'],
plugins: [
typescript({
check: !hasTSChecked,
tsconfig: resolve('tsconfig.base.json'),
tsconfigOverride: {
compilerOptions: {
declaration: !hasTSChecked,
declarationDir: hasTSChecked ? undefined : resolve('dist/types'),
},
include: [resolve('src/index.ts')],
},
useTsconfigDeclarationDir: !hasTSChecked,
}),
],
};
hasTSChecked = true;
if (/min\.js$/.test(opts.output)) {
config.plugins.push(terser());
}
return config;
})
.concat({
input: resolve('dist/types/index.d.ts'),
output: {
file: resolve('dist/vue-showdown.d.ts'),
format: 'es',
},
plugins: [dts()],
});