-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathwebpack.config.js
78 lines (70 loc) · 2.22 KB
/
webpack.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
const path = require("path")
const UglifyJsPlugin = require("uglifyjs-webpack-plugin")
const HtmlWebpackInlineSourcePlugin = require('html-webpack-inline-source-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin')
const glob = require("glob")
const fs = require('fs')
const favicon = "data:image/jpeg;base64,"+fs.readFileSync(path.resolve(__dirname,"public/favicon.ico")).toString('base64');
//TODO fails to load webfonts correctly
//may need to use a custom build of patternfly4 with cdn?
const TOKEN = "window.__DATA__ = [/**DATAKEY**/];"
class BashHook {
apply(compiler){
compiler.hooks.done.tap('DoneHook',(stats)=>{
const html = fs.readFileSync(path.resolve(__dirname,"build/index.embedded.html")).toString();
const index = html.indexOf(TOKEN)
if ( index < 0 ){
throw "could not find TOKEN in template"
}
fs.mkdirSync(path.resolve(__dirname,"build"),{recursive:true});
fs.writeFileSync(path.resolve(__dirname,"build/report.sh"),
`#!/bin/bash
#TODO create script :)
cat << 'EOF'
${html.substring(0,index)}
EOF
cat << EOF
window.__DATA__ = JSON.parse("\`cat \${1:-/dev/stdin} | sed 's/\\\"/\\\\\\"/g'\`")
EOF
cat << 'EOF'
${html.substring(index+TOKEN.length)}
EOF
`
);
})
}
}
module.exports = {
entry: {//|ttf|woff|woff2|ico|jpg|jpeg|png|svg
"bundle.js": glob.sync("build/static/?(js|css|media)/*.?(js|css|ico)").map(f => path.resolve(__dirname, f)),
},
output: {
path: __dirname + '/build/',
filename: "build/static/js/[name].min.js",
},
module: {
rules: [
{
test: /\.css$/,
use: ["style-loader", "css-loader"],
},
{
test: /\.(jpe?g|png|ttf|eot|ico|svg|woff(2)?)(\?[a-z0-9=&.]+)?$/,
exclude: path.resolve(__dirname, "node_modules"),
use: ['base64-inline-loader']
}
],
},
plugins: [
/*new UglifyJsPlugin()*/
new HtmlWebpackPlugin({
inlineSource: '.(js|css)$', // embed all javascript and css inline
template: './public/index.template.html',
inlineFavicon: favicon,
filename: 'index.embedded.html'
//favicon: "./public/favicon.ico",
}),
new HtmlWebpackInlineSourcePlugin(),
new BashHook()
],
}