-
Notifications
You must be signed in to change notification settings - Fork 1
/
rollup.config.js
210 lines (197 loc) · 7.11 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
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
import svelte from 'rollup-plugin-svelte';
import commonjs from '@rollup/plugin-commonjs';
import resolve from '@rollup/plugin-node-resolve';
import livereload from 'rollup-plugin-livereload';
import { terser } from 'rollup-plugin-terser';
import css from 'rollup-plugin-css-only';
import json from '@rollup/plugin-json';
import copy from 'rollup-plugin-copy';
import replace from '@rollup/plugin-replace';
const {markdown} = require('svelte-preprocess-markdown');
const workbox = require('rollup-plugin-workbox-inject');
import {version} from './package.json';
import watchAssets from 'rollup-plugin-watch-assets';
import html from '@open-wc/rollup-plugin-html';
import {DATASET} from './src/stores';
const Mustache = require('mustache');
import md2json from 'md-2-json';
import fs from 'fs';
const production = !process.env.ROLLUP_WATCH;
const debugWorkbox = !!process.env.DEBUG_WORKBOX;
const disableLiveReload = !!process.env.DISABLE_LIVERELOAD || debugWorkbox;
const relPath = (url) => url.replace('./', './public/'); // public path for a local url
//For adding/remove year, change DATASET is src/stores.js
const U = {
'APP_VERSION': version,
'process.env.NODE_ENV': (production) ? JSON.stringify('production') : JSON.stringify('development'),
'CONF_PDFJS_WORKER_JS': 'https://cdnjs.cloudflare.com/ajax/libs/pdf.js/2.4.456/pdf.worker.min.js',
'CONF_PDFJS_JS': 'https://cdnjs.cloudflare.com/ajax/libs/pdf.js/2.4.456/pdf.min.js',
'CONF_JSPDF_JS': 'https://cdnjs.cloudflare.com/ajax/libs/jspdf/2.2.0/jspdf.umd.min.js',
'CONF_JSPDF_TABLE_JS': 'https://cdnjs.cloudflare.com/ajax/libs/jspdf-autotable/3.5.13/jspdf.plugin.autotable.min.js',
'CONF_JSPDF_FONT_TTF': './fonts/HelveticaUTF8.ttf',
'CONF_BUNDLE_JS': './js/bundle.js',
'CONF_BUNDLE_CSS': './css/bundle.css',
'CONF_ABRILFATFACE_WOFF2': '../fonts/abril-fatface-v12-latin-ext_latin-regular.woff2', /* relative to public/css/bundle.css */
'CONF_ABRILFATFACE_WOFF': '../fonts/abril-fatface-v12-latin-ext_latin-regular.woff',
'CONF_DATASET_URLS': Array.from(new Set(DATASET.map(o => o.url))).join(';'),
'CONF_FM_EXAMPLE_IMG': './img/fm_exemple3.jpg',
'CONF_S_EXAMPLE_IMG': './img/s_exemple3.jpg',
// 'CONF_FM_EXAMPLE_WEBP': './img/fm_exemple2.jpg'.replace('.jpg', '.webp'),
// 'CONF_S_EXAMPLE_WEBP': './img/s_exemple2.jpg'.replace('.jpg', '.webp')
};
function serve() {
let server;
function toExit() {
if (server) server.kill(0);
}
return {
writeBundle() {
if (server) return;
const command = (process.env.SERVE === 'start2') ? 'start2' : 'start';
server = require('child_process').spawn('npm', ['run', command, '--', '--dev'], {
stdio: ['ignore', 'inherit', 'inherit'],
shell: true
});
process.on('SIGTERM', toExit);
process.on('exit', toExit);
}
};
}
export default [{
input: 'src/main.js',
output: {
sourcemap: true,
format: 'iife',
name: 'app',
dir: 'public',
entryFileNames: U.CONF_BUNDLE_JS.replace('./', '')
},
plugins: [
watchAssets({ assets: ['./src/index.html'] }),
replace({'values': {...U}, 'preventAssignment': true}),
svelte({
compilerOptions: {
// enable run-time checks when not in production
dev: !production
},
extensions: ['.svelte','.md'],
preprocess: [
markdown()
]
}),
// we'll extract any component CSS out into
// a separate file - better for performance
//scss({ output: relPath(U.CONF_BUNDLE_CSS) }), // scss needs public/ prefix
css({ output: U.CONF_BUNDLE_CSS.replace('./', '') }),
// If you have external dependencies installed from
// npm, you'll most likely need these plugins. In
// some cases you'll need additional configuration -
// consult the documentation for details:
// https://github.com/rollup/plugins/tree/master/packages/commonjs
resolve({
browser: true,
dedupe: ['svelte']
}),
commonjs(),
json(),
copy({
targets: [{ src: 'assets/**/*', dest: 'public' }],
flatten: false,
copyOnce: true,
verbose: true
}),
copy({
targets: [
{
src: './data/airports.json',
dest: './public/data'
},
{
src: './data/data*.json',
dest: './public/data'
},
{
src: './data/*.?sv',
dest: './public/data'
},
{
src: './src/reset.html',
dest: './public'
}//,
// {
// src: './src/index.html',
// dest: './public',
// transform: (contents) => Mustache.render(contents.toString(), U)
// }
],
copyOnce: true,
verbose: true
}),
{
name: 'generate-changelog-json',
writeBundle() {
const changelog = fs.readFileSync('./CHANGELOG.md', 'utf8');
fs.writeFileSync(
'./public/CHANGELOG.json',
JSON.stringify(md2json.parse(changelog))
);
},
},
// In dev mode, call `npm run start` once
// the bundle has been generated
!production && serve(),
// Watch the `public` directory and refresh the
// browser on changes when not in production
!production && !disableLiveReload && livereload({watch: 'public', port:35728, https: (process.env.SERVE === 'start2') ? {
key: fs.readFileSync('localhost-key.pem'),
cert: fs.readFileSync('localhost-cert.pem')
} : null}),
// If we're building for production (npm run build
// instead of npm run dev), minify
production && terser()
],
watch: {
clearScreen: false
}
},
{
input: 'src/index.html',
output: { dir: 'public'},
plugins: [html({
minify: false,
transform: [
htmlString => Mustache.render(htmlString, U)
],
})],
},
{
input: 'src/sw.js',
output: {
sourcemap: true,
format: 'iife',
name: 'sw',
file: 'public/sw.js'
},
plugins: [
replace({values: {...U, ...{'WB_DISABLE_DEV_LOGS': !debugWorkbox}}, preventAssignment: true}),
commonjs(),
resolve({
browser: true
}),
watchAssets({ assets: ['rollup.config.js', './public/css/bundle.css', './public/js/bundle.js'] }),
workbox({
"globDirectory": "public/",
"globPatterns": [
"index.html",
"css/bundle.css",
"js/bundle.js",
"CHANGELOG.json"
]
}),
production && terser()
],
watch: {
clearScreen: false,
include: []
}
}];