forked from nyaruka/temba-components
-
Notifications
You must be signed in to change notification settings - Fork 1
/
rollup.config.js
73 lines (66 loc) · 2 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
import merge from 'deepmerge';
import { createSpaConfig } from '@open-wc/building-rollup';
import packageJson from './package.json';
import commonjs from '@rollup/plugin-commonjs';
import copy from 'rollup-plugin-copy';
const baseConfig = createSpaConfig({
// if you need to support older browsers, such as IE11, set the legacyBuild
// option to generate an additional build just for this browser
// legacyBuild: true,
outputDir: 'dist',
developmentMode: process.env.ROLLUP_WATCH === 'true',
injectServiceWorker: false,
html: {
files: [
'./templates/components-head.html',
'./templates/components-body.html',
],
flatten: false,
transform: [
// inject app version
(html, args) => {
if (args.htmlFileName === 'templates/components-body.html') {
html = html.replace(
'</body>',
`<script>window.TEMBA_COMPONENTS_VERSION = "${packageJson.version}";</script></body>`
);
html = html.replace(/(.*<body>)/is, '');
html = html.replace(/(<\/body>.*)/is, '');
}
if (args.htmlFileName === 'templates/components-head.html') {
html = html.replace(/(.*<head>)/is, '');
html = html.replace(/(<\/head>.*)/is, '');
html = html.replace('as="script"', '');
html = html.replace(
'<link rel="preload"',
'<link rel="modulepreload"'
);
}
return html.replace(
'="../',
'="{{STATIC_URL}}@nyaruka/temba-components/dist/'
);
},
],
},
});
const rollupConfig = merge(baseConfig, {
plugins: [
commonjs({
include: 'node_modules/**',
}),
copy({
targets: [
{ src: 'static/icons/symbol-defs.svg', dest: 'dist/static/icons/' },
{ src: 'static/img', dest: 'dist/static/' },
{
src: 'dist/*.js',
dest: 'dist/',
rename: () => 'index.js',
},
],
hook: 'writeBundle',
}),
],
});
export default rollupConfig;