/
rollup.config.ts
65 lines (62 loc) · 1.97 KB
/
rollup.config.ts
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
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import replace from '@rollup/plugin-replace';
import postcss from 'rollup-plugin-postcss';
import filesize from 'rollup-plugin-filesize';
import serve from 'rollup-plugin-serve';
import livereload from 'rollup-plugin-livereload';
import typescript from 'rollup-plugin-typescript2';
import {terser} from 'rollup-plugin-terser';
const getVersion = require('./scripts/version');
const pkg = require('./package.json');
async function getConfig() {
const version = await getVersion();
const config = {
input: `src/index.ts`,
output: [
{file: pkg.main, name: 'CookieConsent', format: 'umd'},
{file: pkg.module, format: 'es', indent: false},
],
// Indicate here external modules you don't wanna include in your bundle (i.e.: 'lodash')
external: [],
watch: {
include: 'src/**',
},
plugins: [
postcss({
minimize: true,
// extract: path.resolve('dist/cookie-consent.css'),
}),
replace({
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
__VERSION__: JSON.stringify(version),
}),
// Compile TypeScript files
typescript({useTsconfigDeclarationDir: true}),
// Allow bundling cjs modules (unlike webpack, rollup doesn't understand cjs)
commonjs(),
// Allow node_modules resolution, so you can use 'external' to control
// which external modules to include in the bundle
// https://github.com/rollup/rollup-plugin-node-resolve#usage
resolve(),
terser({
include: [/^.+\.min\.js$/, '*umd*'],
}),
filesize(),
],
};
if (process.env.NODE_ENV === 'development') {
config.plugins = [
...config.plugins,
serve({
open: true,
openPage: '/examples/index.html',
contentBase: '',
port: 2046,
}),
livereload({verbose: false}),
];
}
return config;
}
export default getConfig();