-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathwebpack.config.js
More file actions
165 lines (143 loc) · 4.7 KB
/
webpack.config.js
File metadata and controls
165 lines (143 loc) · 4.7 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
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
const path = require('path');
// const webpack = require('webpack');
// const MinifyPlugin = require("babel-minify-webpack-plugin");
const HtmlWebpackPlugin = require('html-webpack-plugin');
// const CopyWebpackPlugin = require('copy-webpack-plugin');
// const HtmlWebpackIncludeAssetsPlugin = require('html-webpack-include-assets-plugin');
// const SriPlugin = require('webpack-subresource-integrity');
const CspHtmlWebpackPlugin = require("csp-html-webpack-plugin");
var cspOptions = {
enabled: true,
policy: {
'default-src': "'self'",
'base-uri': "'none'",
'object-src': "'none'",
'script-src': [
// "'unsafe-inline'",
"'self'",
"'unsafe-eval'"],
'style-src': [
// "'unsafe-inline'",
"'self'",
"'unsafe-eval'"],
'img-src': [
"'self'",
"data:",
"https://www.gravatar.com",
"https://raw.githubusercontent.com/keybase/client/master/browser/images/icon-keybase-logo-128.png",
"https://s3.amazonaws.com/keybase_processed_uploads/",
],
'connect-src': [
"'self'",
"https://keybase.io",
"https://onlykey.herokuapp.com", //for api
"wss://onlykey.herokuapp.com", //for gun
]
},
hashEnabled: {
'script-src': true,
'style-src': true
},
nonceEnabled: {
'script-src': true,
'style-src': true
},
//processFn: defaultProcessFn
};
var pageFiles = getPagesList();
let plugins = [
new HtmlWebpackPlugin({
app_pages: pageFiles,
dir_name: "./app",
filename: './index.html',
template: './src/index-src.html',
inject: 'body',
minify: (process.env.NODE_ENV === 'production') ? { collapseWhitespace: true, removeComments: true } : false,
hash: (process.env.NODE_ENV === 'production') ? true : false,
cache: false,
showErrors: false,
cspPlugin: cspOptions
}),
new HtmlWebpackPlugin({
app_pages: pageFiles,
dir_name: ".",
filename: './app/index.html',
template: './src/index-src.html',
inject: 'body',
minify: (process.env.NODE_ENV === 'production') ? { collapseWhitespace: true, removeComments: true } : false,
hash: (process.env.NODE_ENV === 'production') ? true : false,
cache: false,
showErrors: false,
cspPlugin: cspOptions
})
];
for (var i in pageFiles) {
var filename = pageFiles[i].name;
plugins.push(
new HtmlWebpackPlugin({
app_pages: pageFiles,
page: filename,
filename: (process.env.NODE_ENV === 'production') ? './app/' + filename + '.html' : './app/' + filename + '.html',
template: './src/app-src.html',
inject: 'body',
minify: (process.env.NODE_ENV === 'production') ? { collapseWhitespace: true, removeComments: true } : false,
hash: (process.env.NODE_ENV === 'production') ? true : false,
cache: false,
showErrors: false,
cspPlugin: cspOptions
})
);
}
plugins.push(new CspHtmlWebpackPlugin({}, {}));
module.exports = {
mode: process.env.NODE_ENV,
entry: [(process.env.NODE_ENV === 'production') ? './src/entry.js' : './src/entry-devel.js'],
externals: {
// u2f: './src/u2f-api.js',
// Virtru: './src/virtru-sdk.min.js'
},
output: {
path: path.resolve(__dirname, (process.env.OUT_DIR) ? process.env.OUT_DIR : './'),
filename: './app/bundle.[hash].js',
crossOriginLoading: 'anonymous'
},
plugins: plugins,
module: {
rules: [{
test: /\.page\.html$/i,
use: 'raw-loader',
}, {
test: /\.modal\.html$/i,
use: 'raw-loader',
}, {
test: /\.template\.html$/i,
use: 'raw-loader',
}]
},
};
function getPagesList() {
var _files = [];
var plugins = require("./src/plugins.js");
if (!(process.env.NODE_ENV === 'production')) {
plugins = [].concat(plugins, require("./src/plugins-devel.js"));
}
for (var i in plugins) {
if (plugins[i].pagesList) {
for (var j in plugins[i].pagesList) {
_files.push({
name: j,
icon: plugins[i].pagesList[j].icon,
title: plugins[i].pagesList[j].title,
sort: plugins[i].pagesList[j].sort
});
}
}
}
_files.sort(function(a,b){
if(!a.sort)a.sort=10000;
if(!b.sort)b.sort=10000;
return b.sort - a.sort;
});
_files.reverse();
return _files;
}