This repository has been archived by the owner on Aug 3, 2022. It is now read-only.
forked from Xantios/cockpit-docker
-
Notifications
You must be signed in to change notification settings - Fork 11
/
webpack.config.js
executable file
·263 lines (233 loc) · 7.46 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
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
/* --------------------------------------------------------------------
* Fill in module info here.
*/
var info = {
entries: {
"docker/docker": [
"docker/containers.js"
],
"docker/console": [
"docker/console.js",
],
},
tests: [
"docker/test-docker",
],
files: [
"docker/console.html",
"docker/index.html",
"docker/images/drive-harddisk-symbolic.svg",
"docker/manifest.json",
"docker/css",
"docker/js",
"docker/fonts"
]
};
var externals = {
"cockpit": "cockpit",
"jquery": "jQuery",
};
/* ---------------------------------------------------------------------
* Implementation
*/
var webpack = require("webpack");
var copy = require("copy-webpack-plugin");
var html = require('html-webpack-plugin');
var miniCssExtractPlugin = require('mini-css-extract-plugin');
var path = require("path");
var fs = require("fs");
/* These can be overridden, typically from the Makefile.am */
var srcdir = process.env.SRCDIR || __dirname;
var builddir = process.env.BUILDDIR || __dirname;
var distdir = builddir + path.sep + "dist";
var libdir = path.resolve(srcdir, "pkg" + path.sep + "lib");
var nodedir = path.resolve(srcdir, "node_modules");
var section = process.env.ONLYDIR || null;
/* A standard nodejs and webpack pattern */
var production = process.env.NODE_ENV === 'production';
/*
* Note that we're avoiding the use of path.join as webpack and nodejs
* want relative paths that start with ./ explicitly.
*
* In addition we mimic the VPATH style functionality of GNU Makefile
* where we first check builddir, and then srcdir. In order to avoid
* people having to run ./configure to hack on Cockpit we also help
* resolve files that have a '.in' suffix if the resulting file
* doesn't exist.
*/
function vpath(/* ... */) {
var filename = Array.prototype.join.call(arguments, path.sep);
var expanded = builddir + path.sep + filename;
if (fs.existsSync(expanded))
return expanded;
expanded = srcdir + path.sep + filename;
if (!fs.existsSync(expanded) && fs.existsSync(expanded + ".in"))
return expanded + ".in";
return expanded;
}
/* Qualify all the paths in entries */
Object.keys(info.entries).forEach(function(key) {
if (section && key.indexOf(section) !== 0) {
delete info.entries[key];
return;
}
info.entries[key] = info.entries[key].map(function(value) {
if (value.indexOf("/") === -1)
return value;
else
return vpath("pkg", value);
});
});
/* Qualify all the paths in files listed */
var files = [];
info.files.forEach(function(value) {
if (!section || value.indexOf(section) === 0)
files.push({ from: vpath("pkg", value), to: value });
});
info.files = files;
// Hide mini-css-extract-plugin spam logs
class CleanUpStatsPlugin {
shouldPickStatChild(child) {
return child.name.indexOf('mini-css-extract-plugin') !== 0;
}
apply(compiler) {
compiler.hooks.done.tap('CleanUpStatsPlugin', (stats) => {
const children = stats.compilation.children;
if (Array.isArray(children)) {
stats.compilation.children = children
.filter(child => this.shouldPickStatChild(child));
}
});
}
}
var plugins = [
new copy(info.files),
new miniCssExtractPlugin("[name].css"),
new CleanUpStatsPlugin(),
new webpack.ProvidePlugin({
$: "jquery",
jQuery: "jquery"
}),
];
var output = {
path: distdir,
filename: "[name].js",
sourceMapFilename: "[file].map",
};
/* Only minimize when in production mode */
if (production) {
/* Rename output files when minimizing */
output.filename = "[name].min.js";
}
/* Fill in the tests properly */
info.tests.forEach(function(test) {
var ext = production ? ".min.js" : ".js";
if (!section || test.indexOf(section) === 0) {
info.entries[test] = vpath("pkg", test + ".js");
plugins.push(new html({
title: path.basename(test),
filename: test + ".html",
template: libdir + path.sep + "qunit-template.html",
builddir: test.split("/").map(function() { return "../" }).join(""),
script: path.basename(test + ext),
inject: false,
}));
}
});
var aliases = {
"d3": "d3/d3.js",
"moment": "moment/moment.js",
};
/* HACK: To get around redux warning about reminimizing code */
if (production)
aliases["redux/dist/redux"] = "redux/dist/redux.min.js";
var babel_loader = {
loader: "babel-loader",
options: {
presets: [
["@babel/env", {
"targets": {
"chrome": "57",
"firefox": "52",
"safari": "10.3",
"edge": "16",
"opera": "44"
}
}],
"@babel/preset-react"
]
}
}
module.exports = {
mode: production ? 'production' : 'development',
resolve: {
alias: aliases,
modules: [ libdir, nodedir ],
extensions: ["*", ".js", ".json"]
},
entry: info.entries,
output: output,
externals: externals,
plugins: plugins,
devtool: "source-map",
// disable noisy warnings about exceeding the recommended size limit
performance: {
maxAssetSize: 20000000,
maxEntrypointSize: 20000000,
},
module: {
rules: [
{
enforce: 'pre',
test: /\.(js|es6|jsx)$/,
exclude: /\/node_modules\/.*\//, // exclude external dependencies
loader: "eslint-loader"
},
{
test: /\.js$/,
exclude: /\/node_modules\/.*\//, // exclude external dependencies
loader: 'strict-loader' // Adds "use strict"
},
/* these modules need to be babel'ed, they cause bugs in their dist'ed form */
{
test: /\/node_modules\/.*(@novnc|react-table).*\.js$/,
use: babel_loader
},
{
test: /\.(js|jsx|es6)$/,
// exclude external dependencies; it's too slow, and they are already plain JS except the above
exclude: /\/node_modules\/.*\//,
use: babel_loader
},
{
test: /\.css$/,
use: [
miniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: { url: false }
}
],
},
{
test: /\.scss$/,
use: [
miniCssExtractPlugin.loader,
"css-loader",
'sass-loader',
{
loader: 'sass-resources-loader',
// Make PF3 and PF4 variables globably accessible to be used by the components scss
options: {
resources: [
path.resolve(libdir, './_global-variables.scss'),
path.resolve(nodedir, './@patternfly/patternfly/patternfly-variables.scss'),
path.resolve(nodedir, './patternfly/dist/sass/patternfly/_variables.scss')
],
},
},
]
},
],
}
};