forked from obedm503/showdown-katex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
84 lines (77 loc) · 1.86 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
import babel from 'rollup-plugin-babel';
import commonjs from 'rollup-plugin-commonjs';
import inject from 'rollup-plugin-inject';
import license from 'rollup-plugin-license';
import resolve from 'rollup-plugin-node-resolve';
import replace from 'rollup-plugin-replace';
import { terser } from 'rollup-plugin-terser';
/** @type {import('rollup').RollupOptions} */
const config = {
input: './src/showdown-katex.js',
output: {
name: 'showdownKatex',
sourcemap: true,
file: './dist/showdown-katex.js',
format: 'umd',
},
external: [],
plugins: [
replace({ 'process.env.TARGET': `"${process.env.TARGET}"` }),
babel({
exclude: 'node_modules/**', // only transpile our source code
}),
],
};
if (process.env.TARGET !== 'cjs') {
// web environment
config.external.push('showdown');
config.output.globals = {
showdown: 'showdown',
};
config.plugins.push(
resolve(),
commonjs(),
// inject because the auto render extension decided to assume `katex` is
// available as a global
inject({
katex: 'katex',
}),
);
}
if (process.env.TARGET === 'cjs') {
// node environment
config.output.file = './lib/showdown-katex.js';
config.output.format = 'cjs';
config.external.push(
'showdown',
'jsdom',
'katex',
'katex/dist/contrib/auto-render',
);
}
if (process.env.MIN === 'true') {
config.output.file = './dist/showdown-katex.min.js';
config.plugins.push(
terser({
output: {
comments: /^!|@preserve|@license|@cc_on/gi,
},
compress: {
pure_getters: true,
unsafe: true,
unsafe_comps: true,
},
}),
);
}
config.plugins.push(
license({
banner: `/**!
* @author obedm503
* @git https://github.com/obedm503/showdown-katex.git
* @examples https://obedm503.github.io/showdown-katex/
* @license MIT
*/`,
}),
);
export default config;