-
Notifications
You must be signed in to change notification settings - Fork 1
/
rollup.config.mjs
131 lines (128 loc) · 2.7 KB
/
rollup.config.mjs
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
import { nodeResolve } from '@rollup/plugin-node-resolve';
import typescript from '@rollup/plugin-typescript';
import commonjs from '@rollup/plugin-commonjs';
import json from '@rollup/plugin-json';
import svg from 'rollup-plugin-svg-import';
import css from 'rollup-plugin-import-css';
import terser from '@rollup/plugin-terser';
function getBundleConfig(type) {
const globals = {
'photoswipe/lightbox': 'PhotoSwipeLightbox',
photoswipe: 'PhotoSwipe',
};
const external = [
'photoswipe/style.css',
'photoswipe/lightbox',
'photoswipe',
];
if (type === 'tests') {
globals.sinon = 'sinon';
external.push('sinon');
}
return {
input: `./${type}/index.ts`,
output: {
file: `./temp/${type}/bundle.js`,
format: 'iife',
sourcemap: true,
globals,
assetFileNames: 'bundle.css',
},
external,
watch: {
include: [
'src/**',
`${type}/**`,
],
},
plugins: [
nodeResolve(),
typescript(),
commonjs(),
json(),
svg({
stringify: true,
}),
css(),
],
};
}
function getBuildConfig(type) {
if (type === 'iife') {
return {
input: './src/index.ts',
output: {
file: './dist/lake.min.js',
format: 'iife',
name: 'Lake',
sourcemap: true,
plugins: [terser()],
assetFileNames: 'lake.css',
},
watch: {
include: [
'src/**',
],
},
plugins: [
nodeResolve(),
typescript(),
commonjs(),
json(),
svg({
stringify: true,
}),
css(),
],
};
}
return {
input: './src/index.ts',
output: {
file: './lib/lake.js',
format: 'es',
sourcemap: true,
assetFileNames: 'lake.css',
},
watch: {
include: [
'src/**',
],
},
plugins: [
typescript({
compilerOptions: {
rootDir: './src',
declaration: true,
declarationDir: './types',
},
}),
commonjs(),
json(),
svg({
stringify: true,
}),
css(),
],
};
}
export default (commandLineArgs) => {
const configList = [];
if (commandLineArgs.example === true) {
delete commandLineArgs.example;
configList.push(getBundleConfig('examples'));
}
if (commandLineArgs.test === true) {
delete commandLineArgs.test;
configList.push(getBundleConfig('tests'));
}
if (commandLineArgs.iife === true) {
delete commandLineArgs.iife;
configList.push(getBuildConfig('iife'));
}
if (commandLineArgs.es === true) {
delete commandLineArgs.es;
configList.push(getBuildConfig('es'));
}
return configList;
};