This repository has been archived by the owner on Nov 10, 2019. It is now read-only.
forked from tgrm/tgrm.github.io
-
Notifications
You must be signed in to change notification settings - Fork 1
/
rollup.config.js
83 lines (81 loc) · 3.03 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
import autoprefixer from 'autoprefixer';
import crypto from 'crypto';
import cssnano from 'cssnano';
import { promises as fs, readFileSync } from 'fs';
import postcss from 'postcss';
import cssImport from 'postcss-import';
import html from 'rollup-plugin-bundle-html';
import sass from 'rollup-plugin-sass';
import serve from 'rollup-plugin-serve';
import { terser } from 'rollup-plugin-terser';
import uncss from 'uncss';
import wi from 'web-resource-inliner';
const template = `<html><head><meta charset="UTF-8"><link rel="icon" type="image/png" href="data:image/png;base64,${readFileSync('./tg.png').toString('base64')}"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="robots" content="noindex,"></head><body><a id="wrapper" href="#"><span id="label"></span></a></body></html>`;
export default {
input: 'index.js',
output: {
format: 'esm',
file: 'dist/bundle.js',
},
plugins: [
sass({
output: true,
processor: css => postcss(
cssImport(),
//@ts-ignore
autoprefixer(),
cssnano({ preset: ['advanced', { discardComments: { removeAll: true } }] }),
).process(css, { from: undefined }).then(c => new Promise((resolve, reject) => (
//@ts-ignore
uncss(template, { raw: c.css }, (err, output) => {
if (err) {
reject(err)
} else {
resolve(output)
}
})
)))
}),
terser({
ecma: 5,
module: true,
toplevel: true,
mangle: {
reserved: ['location', 'document']
}
}),
html({
template,
filename: 'index.html',
inject: 'body'
}),
{
writeBundle: () => new Promise((resolve, reject) => {
wi.html({
fileContent: readFileSync('./dist/index.html', 'utf-8').replace('<html>', '<html manifest="/tg/app.appcache">'),
relativeTo: './dist',
images: true
}, async (err, content) => {
if (err) {
reject(err)
} else {
await Promise.all([
fs.writeFile('index.html', content),
fs.writeFile('app.appcache', 'CACHE MANIFEST\n# ' + crypto.createHash('md5').update(content).digest('base64').replace(/=/g, ''))
]);
resolve();
}
});
})
},
process.env.ROLLUP_WATCH && serve({
open: true,
openPage: '/index.html#taraflex',
verbose: true,
contentBase: '',
historyApiFallback: false,
host: '127.0.0.1',
port: 3215,
})
]
};