forked from tgrm/tgrm.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrollup.config.js
More file actions
74 lines (71 loc) · 2.5 KB
/
rollup.config.js
File metadata and controls
74 lines (71 loc) · 2.5 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
import autoprefixer from 'autoprefixer';
import { promisify } from 'util';
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 wri = promisify(wi.html);
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,nofollow"></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'
}),
{
async writeBundle() {
await fs.writeFile('404.html', await wri({
fileContent: readFileSync('./dist/index.html', 'utf-8'),
relativeTo: './dist',
images: true
}));
}
},
process.env.ROLLUP_WATCH && serve({
open: true,
openPage: '/404.html#taraflex',
contentBase: '',
historyApiFallback: false,
host: '127.0.0.1',
port: 3215,
})
]
};