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
177 lines (166 loc) · 4.73 KB
/
rollup.config.js
File metadata and controls
177 lines (166 loc) · 4.73 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
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
import babel from 'rollup-plugin-babel';
import cleanup from 'rollup-plugin-cleanup';
import commonjs from '@rollup/plugin-commonjs';
import copy from 'rollup-plugin-copy';
import html from '@rollup/plugin-html';
import replace from '@rollup/plugin-replace';
import resolve from '@rollup/plugin-node-resolve';
/**
* Maps a key value object to HTML attributes.
*
* @param {object} attributes
*/
const makeHtmlAttributes = (attributes) => {
if (!attributes) {
return '';
}
const keys = Object.keys(attributes);
return keys.reduce(
(result, key) => (result += ` ${key}="${attributes[key]}"`),
''
);
};
/**
* Generates an index.html file that pulls in and initializes our bundle.
*
* @param {object} options
*/
const indexHtmlTemplate = async ({ attributes, files, publicPath, title }) => {
const description = 'A WebGL morph target progressive web application demo.';
const scripts = (files.js || [])
.map(({ fileName }) => {
const attrs = makeHtmlAttributes(attributes.script);
return `<script src="${publicPath}${fileName}" ${attrs}></script>`;
})
.join('\n');
const links = (files.css || [])
.map(({ fileName }) => {
const attrs = makeHtmlAttributes(attributes.link);
return `<link href="${publicPath}${fileName}" rel="stylesheet" ${attrs}>`;
})
.join('\n');
// FIXME: Temporary cdn url to three.js should be replaced. This exists since
// we're migrating from an old version that doesn't support modules yet.
const indexHtml = `
<!DOCTYPE html>
<html ${makeHtmlAttributes(attributes.html)}>
<head>
<meta charset="utf-8">
<meta name="description" content="${description}" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>${title}</title>
<style>
body {
margin: 0;
padding: 0;
font-family: Montserrat,sans-serif;
-webkit-font-smoothing: antialiased;
-moz-font-smoothing: antialiased;
-o-font-smoothing: antialiased;
}
ginger-app {
height: 100vh;
}
@supports (-webkit-appearance:none) {
ginger-app {
height: calc(100vh - 56px);
}
}
</style>
<link href="https://fonts.googleapis.com/css2?family=Montserrat:wght@400;500;600;700&display=swap" rel="stylesheet">
<link href="/static/images/icon.png" rel="shortcut icon" type="image/x-icon">
${links}
${scripts}
<script>
if ('serviceWorker' in navigator) {
window.addEventListener('load', () => {
navigator.serviceWorker.register('/service-worker.js');
});
}
</script>
</head>
<body>
<ginger-app></ginger-app>
</body>
</html>
`;
return indexHtml.replace(/\s+/g, ' ').trim();
};
export default [
{
input: './index.js',
output: {
file: './dist/bundle.rollup.js',
format: 'iife',
name: 'ginger',
},
plugins: [
resolve({
browser: true,
jsnext: true,
extensions: ['.js', '.json'],
}),
commonjs(),
replace({ 'process.env.NODE_ENV': JSON.stringify('production') }),
babel({
extensions: ['.js'],
presets: [],
// Three.js is ignored as babel takes millennia to process it, probably
// being caused by a bug.
ignore: ['node_modules/three'],
env: {
production: {
presets: ['@babel/preset-env', 'minify'],
},
},
}),
cleanup({ comments: 'none' }),
html({
title: 'Ginger',
publicPath: '/',
attributes: {
html: { lang: 'en' },
link: null,
script: { type: 'module' },
},
template: indexHtmlTemplate,
}),
copy({
targets: [
{ src: 'static', dest: 'dist' },
{ src: 'manifest.json', dest: 'dist' },
],
}),
],
},
{
input: './service-worker.js',
output: {
file: './dist/service-worker.js',
format: 'iife',
name: 'sw',
},
plugins: [
resolve({
browser: true,
jsnext: true,
extensions: ['.js', '.json'],
}),
commonjs(),
replace({ 'process.env.NODE_ENV': JSON.stringify('production') }),
babel({
extensions: ['.js'],
presets: [],
// Three.js is ignored as babel takes millennia to process it, probably
// being caused by a bug.
ignore: ['node_modules/three'],
env: {
production: {
presets: ['@babel/preset-env', 'minify'],
},
},
}),
cleanup({ comments: 'none' }),
],
},
];