Repository navigation
Expand file tree
/
Copy pathrollup.config.mjs
More file actions
86 lines (78 loc) · 1.95 KB
/
Copy pathrollup.config.mjs
File metadata and controls
86 lines (78 loc) · 1.95 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
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import terser from '@rollup/plugin-terser';
import postcss from 'rollup-plugin-postcss';
import copy from 'rollup-plugin-copy';
import del from 'rollup-plugin-delete';
import serve from 'rollup-plugin-serve';
import livereload from 'rollup-plugin-livereload';
import autoprefixer from 'autoprefixer';
import cssnano from 'cssnano';
const isWatch = process.env.ROLLUP_WATCH === 'true';
export default {
input: 'src/index.js',
output: {
file: 'dist/map.js',
format: 'iife',
sourcemap: !isWatch,
},
plugins: [
// Clean the dist directory before build.
del({ targets: 'dist/*' }),
// Resolve node modules and convert CommonJS to ES modules.
resolve(),
commonjs(),
// Bundle and minify CSS, extracting it to dist/map.css.
postcss({
extract: 'map.css',
minimize: true,
plugins: [autoprefixer(), cssnano()],
}),
// Minify the output JS bundle.
terser(),
// Copy and transform assets.
copy({
targets: [
{
src: ['src/index.html', 'src/small.html', 'src/embed.html'],
dest: 'dist',
transform: (contents) =>
contents.toString().replace(/\.\.\/dist\//g, ''),
},
{
src: 'src/index.html',
dest: 'dist/embed',
transform: (contents) =>
contents.toString().replace(/\.\.\/dist\//g, '../'),
},
{
src: 'src/_css/*.png',
dest: 'dist',
},
{
src: 'src/_img/marker-icons/*.png',
dest: 'dist/_img/marker-icons',
},
{
src: 'src/_json/areas.json',
dest: 'dist/_json',
transform: (contents) =>
JSON.stringify(JSON.parse(contents.toString())),
},
{
src: 'src/favicon.ico',
dest: 'dist',
},
],
}),
// Start dev server in watch mode.
isWatch &&
serve({
contentBase: 'dist',
port: 10015,
open: true,
}),
// Reload browser on changes in watch mode.
isWatch && livereload('dist'),
].filter(Boolean),
};