forked from glpi-project/glpi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.webpack.config.js
209 lines (191 loc) · 6.58 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
197
198
199
200
201
202
203
204
205
206
207
208
209
const webpack = require('webpack');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const { globSync } = require('glob');
const path = require('path');
const libOutputPath = 'public/lib';
const scssOutputPath = 'css/lib';
/*
* External libraries files build configuration.
*/
let config = {
entry: function () {
// Create an entry per *.js file in lib/bundle directory.
// Entry name will be name of the file (without ext).
let entries = {};
const files = globSync(path.resolve(__dirname, 'lib/bundles') + '/!(*.min).js');
for (const file of files) {
entries[path.basename(file, '.js')] = file;
}
return entries;
},
output: {
path: path.resolve(__dirname, libOutputPath),
publicPath: '', // keep URLs relative to output path
},
module: {
rules: [
{
// Load scripts with no compilation for packages that are directly providing "dist" files.
// This prevents useless compilation pass and can also
// prevents incompatibility issues with the webpack require feature.
// It also removes existing sourcemaps that cannot be used correctly.
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/jquery-migrate'),
path.resolve(__dirname, 'node_modules/photoswipe'),
path.resolve(__dirname, 'node_modules/rrule'),
path.resolve(__dirname, 'lib/blueimp/jquery-file-upload'),
],
use: ['script-loader', 'strip-sourcemap-loader'],
},
{
// Test for a polyfill (or any file) and it won't be included in your
// bundle
test: path.resolve(__dirname, 'node_modules/jquery.fancytree/dist/modules/jquery.fancytree.ui-deps.js'),
use: 'null-loader',
},
{
// Build styles
test: /\.css$/,
use: [MiniCssExtractPlugin.loader, 'css-loader'],
},
{
// Copy images and fonts
test: /\.((gif|png|jp(e?)g)|(eot|ttf|svg|woff2?))$/,
type: 'asset/resource',
generator: {
filename: function (pathData) {
// Keep only relative path
var sanitizedPath = path.relative(__dirname, pathData.filename);
// Sanitize name
sanitizedPath = sanitizedPath.replace(/[^\\/\w-.]/, '');
// Remove the first directory (lib, node_modules, ...) and empty parts
// and replace directory separator by '/' (windows case)
sanitizedPath = sanitizedPath.split(path.sep)
.filter(function (part, index) {
return '' != part && index != 0;
}).join('/');
return sanitizedPath;
},
},
},
],
},
plugins: [
new webpack.ProvidePlugin(
{
process: 'process/browser', // required by some libs (including `popper.js`)
}
),
new CleanWebpackPlugin(
{
cleanOnceBeforeBuildPatterns: [
path.join(process.cwd(), libOutputPath + '/**/*'),
path.join(process.cwd(), scssOutputPath + '/**/*')
]
}
), // Clean lib dir content
new MiniCssExtractPlugin(), // Extract styles into CSS files
],
resolve: {
// Use only main file in requirement resolution as we do not yet handle modules correctly
mainFields: [
'main',
],
},
mode: 'none', // Force 'none' mode, as optimizations will be done on release process
devtool: 'source-map', // Add sourcemap to files
stats: {
// Limit verbosity to only usefull information
all: false,
errors: true,
errorDetails: true,
warnings: true,
entrypoints: true,
timings: true,
},
};
// Copy raw JS and SCSS files
var filesToCopy = [
// JS files
{
package: '@fullcalendar/core',
from: 'locales/*.js',
},
{
package: 'flatpickr',
context: 'dist',
from: 'l10n/*.js',
},
{
package: 'flatpickr',
context: 'dist',
from: 'themes/*.css',
},
{
package: 'select2',
context: 'dist',
from: 'js/i18n/*.js',
},
{
package: 'tinymce',
from: 'skins/**/*',
},
{
package: 'tinymce-i18n',
from: 'langs6/*.js',
},
// SCSS files
{
package: '@fontsource/inter',
from: '{scss/mixins.scss,files/*all-[0-9]00*.woff,files/*[0-9]00*.woff2}',
to: scssOutputPath,
},
{
package: '@tabler/core',
from: 'src/scss/**/*.scss',
to: scssOutputPath,
},
{
package: '@tabler/icons-webfont',
from: '{fonts/*,tabler-icons.scss}',
to: scssOutputPath,
},
{
package: 'bootstrap',
from: 'scss/**/*.scss',
to: scssOutputPath,
},
{
package: 'select2',
from: 'src/scss/**/*.scss',
to: scssOutputPath,
},
];
let copyPatterns = [];
for (let s = 0; s < filesToCopy.length; s++) {
let specs = filesToCopy[s];
let to = (specs.to || libOutputPath) + '/' + specs.package.replace(/^@/, ''); // remove leading @ in case of prefixed package
let context = 'node_modules/' + specs.package;
if (Object.prototype.hasOwnProperty.call(specs, 'context')) {
context += '/' + specs.context;
}
let copyParams = {
context: path.resolve(__dirname, context),
from: specs.from,
to: path.resolve(__dirname, to),
toType: 'dir',
};
if (Object.prototype.hasOwnProperty.call(specs, 'ignore')) {
copyParams.ignore = specs.ignore;
}
copyPatterns.push(copyParams);
}
config.plugins.push(new CopyWebpackPlugin({patterns:copyPatterns}));
module.exports = config;