-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathrollup.config.js
57 lines (50 loc) · 1.27 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
/* eslint-env node */
import fs from 'fs';
import path from 'path';
import babel from 'rollup-plugin-babel';
import { terser } from 'rollup-plugin-terser';
import { sizeSnapshot } from 'rollup-plugin-size-snapshot';
const { version, license, name } = require('./package.json');
const licenseData = fs.readFileSync(path.join(process.cwd(), 'LICENSE.md'), {
encoding: 'utf-8',
});
const bannerPlugin = {
banner: `/**
* @license ${name} ${version}
* ${licenseData.split('\n', 1)}
* License: ${license}
*/`,
};
const optimizeReplace = {
name: 'optimizeReplace',
transform: code =>
code
.replace(/(var|const) TYPE_[^\n]+/g, '')
.replace(/TYPE_TEXT/g, '0')
.replace(/TYPE_VARIABLE/g, '1')
.replace(/TYPE_EXPRESSION/g, '2')
.replace(/export var /g, 'var '), // Only needed in esm
};
const exportFormat = format => ({
input: 'src/frenchkiss.js',
output: {
name,
file: `dist/${format}/frenchkiss.js`,
format,
},
plugins: [
bannerPlugin,
babel(),
optimizeReplace,
terser({
toplevel: true,
compress: {
unsafe: true,
},
output: { comments: /@license/ }
}),
sizeSnapshot(),
].filter(v => v),
external: ['src/compiler.js'],
});
export default ['umd', 'cjs', 'esm'].map(exportFormat);