forked from zextras/carbonio-shell-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcarbonio.webpack.js
128 lines (123 loc) · 2.89 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
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
/*
* 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, ContextReplacementPlugin } = 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-shell-ui/${commitHash}/`;
// these have to match with the ones available in date-fns/locale
const supportedLocalesDateFns = [
'de',
'en-US',
'es',
'fr',
'hi',
'it',
'ja',
'nl',
'pl',
'pt',
'pt-BR',
'ro',
'ru',
'th',
'tr',
'vi',
'zh-CN'
/* TODO: For future languages
* 'ar','bg','ca','da','en-AU','en-GB','eu','fr-CA','hr','hu','ko','ms','sl','sv','ta','uk','zh-HK','zh-TW'
*/
];
module.exports = (conf, pkg, options, mode) => {
const server = `https://${options.host}`;
const root = 'carbonio';
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
}),
new HtmlWebpackPlugin({
inject: false,
template: path.resolve(process.cwd(), 'commit.template'),
filename: 'commit',
COMMIT_ID: commitHash
}),
new ContextReplacementPlugin(
/^date-fns[/\\]locale$/,
new RegExp(`\\.[/\\\\](${supportedLocalesDateFns.join('|')})[/\\\\]index\\.js$`)
)
);
conf.devServer = {
port: options.port,
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:${options.port}`
}
},
{
context: ['!/static/iris/carbonio-shell-ui/**/*', `!/${root}/`, `!/${root}/**/*`],
target: server,
secure: false,
logLevel: 'debug',
cookieDomainRewrite: {
'*': server,
[server]: `localhost:${options.port}`
}
}
]
};
conf.externals = {};
conf.module.rules = [
...conf.module.rules,
{
test: /\.(woff(2)?|ttf|eot)$/,
type: 'asset/resource',
generator: {
filename: './files/[name][ext]'
}
}
];
return conf;
};