-
Notifications
You must be signed in to change notification settings - Fork 1
/
carbonio.webpack.js
101 lines (97 loc) · 2.35 KB
/
carbonio.webpack.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
/*
* SPDX-FileCopyrightText: 2022 Zextras <https://www.zextras.com>
*
* SPDX-License-Identifier: AGPL-3.0-only
*/
/* eslint-disable @typescript-eslint/no-var-requires */
/* eslint-disable no-param-reassign */
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const { DefinePlugin } = require('webpack');
const CopyPlugin = require('copy-webpack-plugin');
const commitHash = require('child_process').execSync('git rev-parse HEAD').toString().trim();
const baseStaticPath = `/static/iris/carbonio-admin-ui/${commitHash}/`;
module.exports = (conf, pkg, options, mode) => {
const server = `https://${options.host}`;
const root = 'carbonioAdmin';
conf.entry = {
index: path.resolve(process.cwd(), 'src', 'index.tsx')
};
conf.output.filename =
mode === 'development' ? 'zapp-shell.bundle.js' : '[name].[chunkhash:8].js';
conf.resolve.extensions.push('.d.ts');
conf.plugins.push(
new CopyPlugin({
patterns: [
{
from: 'assets/',
to: ''
}
]
}),
new DefinePlugin({
COMMIT_ID: JSON.stringify(commitHash.toString().trim()),
BASE_PATH: JSON.stringify(baseStaticPath)
}),
new HtmlWebpackPlugin({
inject: true,
template: path.resolve(process.cwd(), 'src', 'index.template.html'),
chunks: ['index'],
BASE_PATH: baseStaticPath,
SHELL_ENV: root
}),
new HtmlWebpackPlugin({
inject: false,
template: path.resolve(process.cwd(), 'commit.template'),
filename: 'commit',
COMMIT_ID: commitHash
})
);
conf.devServer = {
port: 9000,
historyApiFallback: {
index: `${baseStaticPath}/index.html`,
rewrites: [
{
from: new RegExp(`/${root}/*`),
to: `${baseStaticPath}/index.html`
}
]
},
server: 'https',
open: [`/${root}/`],
proxy: [
{
context: ['/static/login/**'],
target: server,
secure: false,
cookieDomainRewrite: {
'*': server,
[server]: 'localhost:9000'
}
},
{
context: ['!/static/iris/carbonio-admin-ui/**/*', `!/${root}/`, `!/${root}/**/*`],
target: server,
secure: false,
logLevel: 'debug',
cookieDomainRewrite: {
'*': server,
[server]: 'localhost:9000'
}
}
]
};
conf.externals = {};
conf.module.rules = [
...conf.module.rules,
{
test: /\.(woff(2)?|ttf|eot)$/,
type: 'asset/resource',
generator: {
filename: './files/[name][ext]'
}
}
];
return conf;
};