forked from Checkmk/checkmk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
179 lines (172 loc) · 7.01 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
// Copyright (C) 2019 tribe29 GmbH - License: GNU General Public License v2
// This file is part of Checkmk (https://checkmk.com). It is subject to the terms and
// conditions defined in the file COPYING, which is part of this source code package.
const path = require("path");
const RemoveEmptyScriptsPlugin = require("webpack-remove-empty-scripts");
const TerserPlugin = require("terser-webpack-plugin");
const webpack = require("webpack");
module.exports = {
mode: "production",
devtool: "source-map",
optimization: {
minimizer: [
new TerserPlugin({
terserOptions: {
format: {
comments: false,
},
},
extractComments: false,
}),
],
},
entry: {
main: "./web/htdocs/js/index.ts",
mobile: "./web/htdocs/js/mobile.ts",
side: "./web/htdocs/js/side_index.ts",
facelift: "./web/htdocs/themes/facelift/theme.scss",
modern_dark: "./web/htdocs/themes/modern-dark/theme.scss",
cma: "./web/htdocs/themes/facelift/cma_facelift.scss",
},
output: {
path: path.resolve(__dirname, "web/htdocs/js"),
filename: "[name]_min.js",
publicPath: "js",
// Keep this until we have cleaned up our JS files to work as modules and changed all call sites
// from HTML code to work with the modules. Until then we need to keep the old behaviour of loading
// all JS code in the global namespace
libraryTarget: "window",
libraryExport: "cmk_export",
},
externals: {
// canvas-5-polyfill for IE11: tell webpack that canvas is provided by the browser
canvas: 'canvas',
},
resolve: {
modules: [
"node_modules",
path.resolve(__dirname, "web/htdocs/js/modules"),
path.resolve(__dirname, "web/htdocs/js/modules/figures"),
path.resolve(__dirname, "web/htdocs/js/modules/node_visualization"),
path.resolve(__dirname, "enterprise/web/htdocs/js/modules"),
path.resolve(__dirname, "enterprise/web/htdocs/js/modules/figures"),
path.resolve(__dirname, "enterprise/web/htdocs/js/modules/ntop"),
path.resolve(__dirname, "enterprise/web/htdocs/js/modules/license_usage"),
],
// added this because otherwise it won't find any imported ts files inside of a js file
extensions: [".ts", ".js"],
},
module: {
rules: [
// needed for theme CSS files
{
test: /\.scss$/,
use: [
// 5. Write to theme specific file
{
loader: "file-loader",
options: {
regExp: /\/([a-z0-9_-]+)\/([a-z0-9_-]+)\.scss$/,
name: "../themes/[1]/[2].css",
},
},
// 4. Extract CSS definitions from JS wrapped CSS
{
loader: "extract-loader",
},
// 3. Interpret and resolve @import / url()
{
loader: "css-loader",
options: {
url: false,
importLoaders: 2,
esModule: false,
sourceMap: false,
},
},
// 2. Some postprocessing of CSS definitions (see postcss.config.js)
// - add browser vendor prefixes https://github.com/postcss/autoprefixer
// - minifies CSS with https://github.com/cssnano/cssnano
{
loader: "postcss-loader",
},
// 1. Transform sass definitions into CSS
{
loader: "sass-loader",
options: {
additionalData:
"$ENTERPRISE: " +
process.env.ENTERPRISE +
";\n" +
"$MANAGED: " +
process.env.MANAGED +
";",
sassOptions: {
// Hand over build options from webpack to SASS
includePaths: ["node_modules"],
// dart-sass supports "expanded" and "compressed":
// https://github.com/sass/dart-sass#javascript-api
outputStyle: "expanded",
precision: 10,
},
},
},
],
},
],
},
plugins: [
new RemoveEmptyScriptsPlugin(),
new webpack.EnvironmentPlugin(["ENTERPRISE", "MANAGED"]),
],
};
let babel_loader = {
// Do not try to execute babel on all node_modules. But some d3 stuff seems to need it's help.
exclude: /node_modules/,
include: [
path.resolve(__dirname, "web/htdocs/js"),
path.resolve(__dirname, "node_modules/d3"),
path.resolve(__dirname, "node_modules/d3-flextree"),
path.resolve(__dirname, "node_modules/d3-sankey"),
path.resolve(__dirname, "node_modules/crossfilter2"),
// Additional packages needed for D3js v6:
path.resolve(__dirname, "node_modules/internmap"),
path.resolve(__dirname, "node_modules/delaunator"),
],
use: {
loader: "babel-loader",
options: {
presets: [
"@babel/typescript"
],
plugins: ["@babel/plugin-transform-parameters",
"@babel/proposal-class-properties",
"@babel/proposal-object-rest-spread"
],
},
},
};
if (process.env.WEBPACK_MODE === "quick") {
console.log(
"not using Babel in Webpack mode '" +
process.env.WEBPACK_MODE +
"', let's hope you know what your're doing..."
);
babel_loader["test"]= /\.ts?$/;
} else {
console.log("using Babel in Webpack mode '" + process.env.WEBPACK_MODE + "'");
babel_loader["test"]= /\.(ts|js)?$/;
babel_loader["use"]["options"]["presets"].unshift(
[
"@babel/preset-env",
{
//debug: true,
// This adds polyfills when needed. Requires core-js dependency.
// See https://babeljs.io/docs/en/babel-preset-env#usebuiltins
useBuiltIns: "usage",
corejs: 3,
},
]
)
}
module.exports.module.rules.unshift(babel_loader);