This repository has been archived by the owner on Oct 18, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
55 lines (52 loc) · 1.56 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
import svelte from 'rollup-plugin-svelte';
import resolve from '@rollup/plugin-node-resolve';
import { terser } from 'rollup-plugin-terser';
import livereload from 'rollup-plugin-livereload';
import serve from 'rollup-plugin-serve';
import copy from 'rollup-plugin-copy';
import css from 'rollup-plugin-css-only';
import fs from 'fs';
import posthtml from 'posthtml';
import { hash } from 'posthtml-hash';
import rimraf from 'rimraf';
import preprocess from 'svelte-preprocess';
const PROD = !process.env.ROLLUP_WATCH;
const OUT_DIR = 'build';
const OUT_FILE = `${OUT_DIR}/index.html`;
const hashStatic = () => ({
name: 'hash-static',
buildStart: () => rimraf.sync(OUT_DIR),
writeBundle: () => {
posthtml([hash({ path: OUT_DIR })])
.process(fs.readFileSync(OUT_FILE, 'utf-8'))
.then((result) => fs.writeFileSync(OUT_FILE, result.html));
},
});
export default {
input: 'src/index.js',
output: {
sourcemap: !PROD,
format: 'iife',
name: 'app',
file: `${OUT_DIR}/bundle.[hash].js`,
},
plugins: [
copy({ targets: [{ src: 'public/*', dest: OUT_DIR }] }),
svelte({
compilerOptions: {
dev: !PROD,
},
preprocess: preprocess(),
}),
css({ output: 'bundle.[hash].css' }),
resolve(),
!PROD &&
serve({
contentBase: [OUT_DIR],
port: 8080,
}),
!PROD && livereload({ watch: OUT_DIR }),
PROD && terser(),
PROD && hashStatic(),
],
};