-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
44 lines (40 loc) · 1.12 KB
/
index.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
class GHPagesSPAWebpackPlugin {
constructor(options = {}) {
this.domain = options.domain;
}
apply(compiler) {
const { name } = this.constructor;
const { RedirectTemplate } = GHPagesSPAWebpackPlugin;
if (!this.domain) {
console.warn(
`${name}: "domain" option is empty. Please enter the "domain" option.`
);
} else {
compiler.hooks.emit.tapAsync(name, (compilation, done) => {
compilation.assets['404.html'] = {
source: () => RedirectTemplate,
size: () => RedirectTemplate.length,
};
compilation.assets.CNAME = {
source: () => this.domain,
size: () => this.domain.length,
};
done();
});
}
}
}
GHPagesSPAWebpackPlugin.RedirectTemplate = [
'<!doctype html>',
'<html>',
' <head>',
' <meta charset="utf-8">',
' <script type="text/javascript">',
' window.location.replace(',
" 'https://' + window.location.hostname + '/#' + window.location.pathname",
' );',
' </script>',
' </head>',
'</html>',
].join('\n');
module.exports = GHPagesSPAWebpackPlugin;