This repository was archived by the owner on Jul 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrollup.config.js
More file actions
63 lines (52 loc) · 1.75 KB
/
rollup.config.js
File metadata and controls
63 lines (52 loc) · 1.75 KB
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
import commonjs from '@rollup/plugin-commonjs';
import {nodeResolve} from '@rollup/plugin-node-resolve';
import typescript from '@rollup/plugin-typescript';
import copier from 'rollup-plugin-copier';
import livereload from 'rollup-plugin-livereload';
import scss from 'rollup-plugin-scss';
import serve from 'rollup-plugin-serve';
import { terser } from 'rollup-plugin-terser';
import path from 'path';
import pkg from './package.json';
const isProd = process.env.PROD === 'true';
const camelize = (str) => str.replace('/', ' ').replace(/\W+(.)/g, (match, chr) => chr.toUpperCase());
const components = [
'login',
'embed'
];
const plugins = [
scss({ output: false }),
nodeResolve(),
typescript({ sourceMap: !isProd, inlineSources: !isProd }),
commonjs(),
];
const iife = {
input: 'src/index.ts',
output: { file: pkg.browser, format: 'iife', name: 'typeformElements' },
plugins,
};
const completeBuilds = [];
if (isProd) {
completeBuilds.push({
input: 'src/index.ts',
output: [
{ file: pkg.main, format: 'cjs' },
{ file: pkg.module, format: 'es' }
],
plugins
});
components.forEach((component) => {
completeBuilds.push({
input: 'src/' + component + '/index.ts',
output: { file: 'dist/' + component + '.js', format: 'iife', name: camelize('typeform/' + component) },
plugins: [ ...plugins, terser() ]
})
});
iife.plugins.push(terser());
} else {
iife.plugins.push(copier({ items: [{ src: 'src/index.html', dest: 'dist/index.html', createPath: true }] }));
iife.plugins.push(serve({ open: true, contentBase: 'dist' }));
iife.plugins.push(livereload({ watch: [path.resolve(__dirname, 'dist')], exts: ['html', 'js', 'scss', 'css'] }));
}
completeBuilds.push(iife);
export default completeBuilds;