-
Notifications
You must be signed in to change notification settings - Fork 11
/
webpack.config.js
196 lines (187 loc) · 5.5 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
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
/**
* ---------------------------------------------------------------------
* ITSM-NG
* Copyright (C) 2022 ITSM-NG and contributors.
*
* https://www.itsm-ng.org
*
* based on GLPI - Gestionnaire Libre de Parc Informatique
* Copyright (C) 2003-2014 by the INDEPNET Development Team.
*
* ---------------------------------------------------------------------
*
* LICENSE
*
* This file is part of ITSM-NG.
*
* ITSM-NG is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* ITSM-NG 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ITSM-NG. If not, see <http://www.gnu.org/licenses/>.
* ---------------------------------------------------------------------
*/
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const glob = require('glob');
const path = require('path');
const libOutputPath = 'public/lib';
/*
* GLPI core files build configuration.
*/
const glpiConfig = {
entry: {
glpi: path.resolve(__dirname, 'js/main.js'),
},
output: {
filename: '[name].js',
path: path.resolve(__dirname, 'public/build'),
},
mode: 'none',
devtool: 'source-map',
stats: {
all: false,
errors: true,
errorDetails: true,
warnings: true,
entrypoints: true,
timings: true,
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env'],
},
},
},
],
},
};
/*
* External libraries files build configuration.
*/
const libsConfig = {
entry: () => {
const entries = {};
const files = glob.sync(path.resolve(__dirname, 'lib/bundles') + '/!(*.min).js');
files.forEach(file => {
entries[path.basename(file, '.js')] = file;
});
return entries;
},
output: {
filename: '[name].js',
path: path.resolve(__dirname, libOutputPath),
},
module: {
rules: [
{
test: /\.js$/,
include: [
path.resolve(__dirname, 'node_modules/@fullcalendar'),
path.resolve(__dirname, 'node_modules/codemirror'),
path.resolve(__dirname, 'node_modules/cystoscape'),
path.resolve(__dirname, 'node_modules/cytoscape-context-menus'),
path.resolve(__dirname, 'node_modules/gridstack'),
path.resolve(__dirname, 'node_modules/jquery-migrate'),
path.resolve(__dirname, 'node_modules/jstree'),
path.resolve(__dirname, 'node_modules/photoswipe'),
path.resolve(__dirname, 'node_modules/rrule'),
path.resolve(__dirname, 'vendor/blueimp/jquery-file-upload'),
],
use: ['script-loader', 'strip-sourcemap-loader'],
},
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env'],
},
},
},
{
test: /\.css$/i,
use: [MiniCssExtractPlugin.loader, 'css-loader'],
},
{
test: /\.(gif|png|jpe?g|eot|ttf|svg|woff2?)$/,
use: {
loader: 'file-loader',
options: {
name: (filename) => {
const sanitizedPath = path.relative(__dirname, filename)
.replace(/[^\\/\w-.]/g, '')
.split(path.sep)
.filter((part, index) => part && index !== 0)
.join('/');
return sanitizedPath;
},
},
},
},
],
},
plugins: [
new CleanWebpackPlugin(),
new MiniCssExtractPlugin({ filename: '[name].css' }),
],
resolve: {
mainFields: ['main'],
fallback: {
tty: require.resolve('tty-browserify'),
stream: require.resolve('stream-browserify'),
buffer: require.resolve('buffer/'),
os: require.resolve('os-browserify/browser'),
},
},
mode: 'none',
devtool: 'source-map',
stats: {
all: false,
errors: true,
errorDetails: true,
warnings: true,
entrypoints: true,
timings: true,
},
};
const libs = {
'@fullcalendar': [{ context: 'core', from: 'locales/*.js' }],
flatpickr: [
{ context: 'dist', from: 'l10n/*.js' },
{ context: 'dist', from: 'themes/*.css' },
],
'jquery-ui': [{ context: 'ui', from: 'i18n/*.js' }],
select2: [{ context: 'dist', from: 'js/i18n/*.js' }],
'tinymce-i18n': [{ from: 'langs/*.js' }],
};
const generateCopyPatterns = (libPackage, packageName) => {
const to = `${libOutputPath}/${packageName.replace(/^@/, '')}`;
return libPackage.map(entry => ({
context: path.resolve(__dirname, `node_modules/${packageName}`, entry.context || ''),
from: entry.from,
to: path.resolve(__dirname, to),
toType: 'dir',
...(entry.ignore && { ignore: entry.ignore }),
}));
};
Object.entries(libs).forEach(([packageName, libPackage]) => {
const copyPatterns = generateCopyPatterns(libPackage, packageName);
libsConfig.plugins.push(new CopyWebpackPlugin({ patterns: copyPatterns }));
});
module.exports = [glpiConfig, libsConfig];