-
Notifications
You must be signed in to change notification settings - Fork 3
/
rollup.config.js
117 lines (109 loc) · 3.07 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
import fs from 'fs-extra';
import uglify from 'rollup-plugin-uglify';
const now = Date.now();
fs.ensureDirSync('build');
fs.emptyDirSync('build');
fs.ensureDirSync('build/public/images');
fs.ensureDirSync('build/public/js');
fs.ensureDirSync('build/public/libs');
fs.ensureDirSync('build/public/libs/webcomponentsjs');
const filesToCopy = [{
from: 'functions/index-template.js',
to: 'functions/index.js',
}, {
from: 'public/images/logo.svg',
to: `build/public/images/logo.svg`,
}, {
from: 'public/images/loading.svg',
to: `build/public/images/loading.svg`,
}, {
from: 'public/images/icon.png',
to: `build/public/images/icon.png`,
}, {
from: 'public/images/icon-512.png',
to: `build/public/images/icon-512.png`,
}, {
from: 'public/sw.js',
to: 'build/public/sw.js',
}, {
from: 'public/robots.txt',
to: 'build/public/robots.txt',
}, {
from: 'public/manifest.json',
to: 'build/public/manifest.json',
}, {
from: './node_modules/@webcomponents/webcomponentsjs/webcomponents-hi-ce.js',
to: 'build/public/libs/webcomponentsjs/webcomponents-hi-ce.js',
}, {
from: './node_modules/@webcomponents/webcomponentsjs/webcomponents-hi-sd-ce.js',
to: 'build/public/libs/webcomponentsjs/webcomponents-hi-sd-ce.js',
}, {
from: './node_modules/@webcomponents/webcomponentsjs/webcomponents-hi-sd.js',
to: 'build/public/libs/webcomponentsjs/webcomponents-hi-sd.js',
}, {
from: './node_modules/@webcomponents/webcomponentsjs/webcomponents-hi.js',
to: 'build/public/libs/webcomponentsjs/webcomponents-hi.js',
}, {
from: './node_modules/@webcomponents/webcomponentsjs/webcomponents-loader.js',
to: 'build/public/libs/webcomponentsjs/webcomponents-loader.js',
}, {
from: './node_modules/@webcomponents/webcomponentsjs/webcomponents-sd-ce.js',
to: 'build/public/libs/webcomponentsjs/webcomponents-sd-ce.js',
}];
filesToCopy.forEach((file) => {
fs.copyFileSync(file.from, file.to);
});
const html = fs.readFileSync('public/index.html', 'utf-8');
const replacements = [{
files: ['functions/index.js', 'build/public/sw.js'],
replace: [{
from: /\[\[html\]\]/,
to: html.replace(/`/g, '\`'),
}, {
from: '// preload-cache',
to: `
document.querySelector('x-app').cache = {
items: {},
lists: {
news: {
'1': {
list: \${JSON.stringify(items)},
time: \${time},
}
},
newest: {},
show: {},
ask: {},
jobs: {},
},
maxAge: 60 * 1000 * 10,
};
`,
}, {
from: /\/js\/app\.js/g,
to: `/js/app-${now}.js`,
}, {
from: /\[\[rev\]\]/g,
to: now,
}],
}];
replacements.forEach((replacement) => {
replacement.files.forEach((file) => {
let input = fs.readFileSync(file, 'utf-8')
replacement.replace.forEach((replace) => {
input = input.replace(replace.from, replace.to);
});
fs.writeFileSync(file, input);
});
});
export default {
input: './public/src/components/app.js',
output: {
file: `./build/public/js/app-${now}.js`,
format: 'iife',
sourcemap: true,
},
plugins: [
uglify(),
]
};