-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathwebpack.config.ts
More file actions
324 lines (310 loc) · 9.44 KB
/
webpack.config.ts
File metadata and controls
324 lines (310 loc) · 9.44 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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
/*
* Teragrep User Interface (ajs_01)
* Copyright (C) 2019-2026 Suomen Kanuuna Oy
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*
* Additional permission under GNU Affero General Public License version 3
* section 7
*
* If you modify this Program, or any covered work, by linking or combining it
* with other code, such other code is not for that reason alone subject to any
* of the requirements of the GNU Affero GPL version 3 as long as this Program
* is the same Program as licensed from Suomen Kanuuna Oy without any additional
* modifications.
*
* Supplemented terms under GNU Affero General Public License version 3
* section 7
*
* Origin of the software must be attributed to Suomen Kanuuna Oy. Any modified
* versions must be marked as "Modified version of" The Program.
*
* Names of the licensors and authors may not be used for publicity purposes.
*
* No rights are granted for use of trade names, trademarks, or service marks
* which are in The Program if any.
*
* Licensee must indemnify licensors and authors for any liability that these
* contractual assumptions impose on licensors and authors.
*
* To the extent this program is licensed as part of the Commercial versions of
* Teragrep, the applicable Commercial License may apply to this file if you as
* a licensee so wish it.
*/
'use strict';
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const CspHtmlWebpackPlugin = require('csp-html-webpack-plugin');
const webpack = require('webpack');
const CopyPlugin = require("copy-webpack-plugin");
//const NodePolyfillPlugin = require("node-polyfill-webpack-plugin")
// local configs
var is_debug = process.env.IS_DEBUG || 0;
var serverPort = process.env.SERVER_PORT || 8080;
var webPort = process.env.WEB_PORT || 9000;
var config = {
mode: 'production',
entry: {
vendor: [
'angular',
'jquery',
'jquery-ui/jquery-ui', // TODO update
'ace-builds/src-noconflict/ace',
'ace-builds/src-noconflict/ext-language_tools',
'bootstrap/dist/js/bootstrap.esm',
'@angular/compiler',
'@angular/core',
'@angular/common',
'@angular/platform-browser',
'@angular/router',
'@angular/forms',
'rxjs',
'angular/angular',
'angular-animate/angular-animate',
'angular-cookies/angular-cookies',
'angular-dragdrop/src/angular-dragdrop',
'angular-mocks/angular-mocks',
'angular-resource/angular-resource',
'angular-route/angular-route',
'angular-sanitize/angular-sanitize',
'angular-touch/angular-touch',
'angular-ui-ace/ui-ace', // TODO investigate alternatives
'd3/d3',
// TODO replace removed elastic input with CSS
'datatables.net-bs5',
'datatables.net-buttons-bs5',
'datatables.net-buttons/js/buttons.colVis.mjs',
'datatables.net-buttons/js/buttons.html5.mjs',
'datatables.net-buttons/js/buttons.print.mjs',
'datatables.net-rowgroup-bs5',
'datatables.net-searchpanes-bs5',
'datatables.net-select-bs5',
'jsdiff/diff',
'lodash/lodash', // TODO update
'ng-sortable/dist/ng-sortable',
'nvd3/build/nv.d3',
'select2/dist/js/select2', // TODO investigate alternatives
'cron-parser',
],
main: [
'./src/main.ts',
],
},
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'static/[name].[contenthash].js',
assetModuleFilename: 'static/[hash][ext][query]'
},
optimization: {
minimize: false,
runtimeChunk: 'single',
splitChunks: {
cacheGroups: {
vendor: {
test: /[\\/]node_modules[\\/]/,
name: 'vendors',
chunks: 'all',
},
},
},
},
devServer: {
allowedHosts: '127.0.0.1',
hot: true,
liveReload: true,
watchFiles: 'src/',
webSocketServer: 'ws',
compress: true,
port: webPort,
},
devtool: "source-map",
resolve: {
extensions: [".ts", ".tsx", ".js", ".jsx", ".json"],
/*
fallback: {
// for excel-builder
"crypto": require.resolve("crypto-browserify"),
"buffer": require.resolve("buffer"),
"stream": require.resolve("stream-browserify"),
},
*/
},
plugins: [
new CopyPlugin({
patterns: [
{ from: "node_modules/ace-builds/src-noconflict/mode-*.js", to: "[name][ext]" },
{ from: './src/assets', to: 'assets' },
//{ from: "src/assets/styles/ace-teragrep/theme-teragrep.js", to: "[name][ext]" } // TODO Fix theme-teragrep.js
],
}),
new HtmlWebpackPlugin({
filename: 'index.html',
template: './src/index.html',
inject: 'body'
}),
new MiniCssExtractPlugin({
filename: '/static/[name].[contenthash].css'
}),
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery',
"window.jQuery": "jquery",
bootstrap: 'bootstrap',
//process: 'process/browser',
//_: 'underscore', // for excel-builder
//window: 'global/window',
}),
new webpack.DefinePlugin({
'process.env': {
SERVER_PORT: serverPort,
WEB_PORT: webPort,
IS_DEBUG: is_debug
//PROD: isProd,
//BUILD_CI: (isCI) ? JSON.stringify(true) : JSON.stringify(false)
}
})
],
module: {
rules: [
{ test: /\.tsx?$/, loader: 'ts-loader' },
{
test: require.resolve('headroom.js'),
use: 'imports-loader?this=>window,define=>false,exports=>false'
},
{
test: /\.css$/i,
use: [
MiniCssExtractPlugin.loader,
{
loader: "css-loader",
options: {
sourceMap: true,
},
}
],
},
// two loaders because, index.html must not be hit by the ngtemplate-loader
{
test: /src\/app\/.*\.html$/,
use: [
{
loader: 'ngtemplate-loader?relativeTo=' + path.resolve(__dirname, './src/')
},
{
loader: 'html-loader',
options: {
esModule: false
}
}
],
},
{
test: /src\/components\/.*\.html/,
use: [
{
loader: 'ngtemplate-loader?relativeTo=' + path.resolve(__dirname, './src/')
},
{
loader: 'html-loader',
options: {
esModule: false
}
}
],
},
{
test: /\.(png|jpg|jpeg|gif|svg|woff|woff2|ttf|eot)$/,
type: 'asset/resource'
},
{
test: /index.html$/,
use: [
{ loader: 'html-loader' },
],
},
{
test: /\.(js|jsx)$/,
use: [
/*{
loader: 'angularjs-template-loader',
options: {
relativeTo: path.resolve(__dirname, 'src/app')
}
},*/
{
loader: 'babel-loader'
},
],
exclude: /(node_modules)/,
},
],
},
};
module.exports = (env, argv) => {
var cspSrc = ["'self'"]
var connectCspSrc = []
// Assume dev if argv is null
if (argv == null || argv.mode === 'development') {
console.info("INFO: Detected development mode, using development settings and injecting localhost cspSrc settings.");
config.mode = 'development';
// Allow CSP for localhost as well when in-dev
cspSrc.push("localhost:*");
connectCspSrc.push("ws://localhost:*");
}
else if (argv.mode === 'production') {
console.info("INFO: Detected production mode, using production settings.");
config.mode = 'production';
}
/*
// for pretendprod mode, we stay in production mode but enable localhost connectivity for local testing
if (env.pretendprod != null) {
console.info("INFO: Detected pretend production mode, injecting localhost cspSrc settings.");
cspSrc.push("localhost:*");
connectCspSrc.push("ws://localhost:*");
}
*/
config.plugins.push(
new CspHtmlWebpackPlugin(
{
'object-src': "'none'", // we will most likely never want to enable objects from any source
'script-src': cspSrc.concat(["'unsafe-eval'"]),
'worker-src': "'none'", // we do not have any webworkers registered right now
'style-src': cspSrc.concat(["'unsafe-inline'", "'unsafe-eval'"]),
'frame-src': cspSrc,
'base-uri': cspSrc,
'default-src': cspSrc,
'connect-src': cspSrc.concat(connectCspSrc),
'font-src': cspSrc.concat(["data:"]),
'img-src': cspSrc.concat(["data:"]),
'manifest-src': cspSrc,
'media-src': cspSrc
},
{
enabled: true,
hashingMethod: 'sha256',
hashEnabled: {
'script-src': true,
'style-src': false
},
nonceEnabled: {
'script-src': true,
'style-src': false
}
}
)
);
return config;
};