forked from Checkmk/checkmk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
143 lines (140 loc) · 5.67 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
// 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 FixStyleOnlyEntriesPlugin = require("webpack-fix-style-only-entries");
const webpack = require("webpack");
module.exports = {
mode: "production",
devtool: "source-map",
entry: {
main: "./web/htdocs/js/index.js",
mobile: "./web/htdocs/js/mobile.js",
side: "./web/htdocs/js/side_index.js",
themes: [
"./web/htdocs/themes/facelift/theme.scss",
"./web/htdocs/themes/facelift/cma_facelift.scss",
"./web/htdocs/themes/modern-dark/theme.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",
},
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/ntop"),
],
},
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,
},
},
// 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/jakubpawlowicz/clean-css
{
loader: "postcss-loader",
},
// 1. Transform sass definitions into CSS
{
loader: "sass-loader",
options: {
prependData:
"$ENTERPRISE: " +
process.env.ENTERPRISE +
";\n" +
"$MANAGED: " +
process.env.MANAGED +
";",
sassOptions: {
// Hand over build options from webpack to SASS
includePaths: ["node_modules"],
// See https://github.com/sass/node-sass/blob/master/README.md#options
outputStyle: "expanded",
precision: 10,
},
},
},
],
},
],
},
plugins: [
new FixStyleOnlyEntriesPlugin(),
new webpack.EnvironmentPlugin(["ENTERPRISE", "MANAGED"]),
],
};
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..."
);
} else {
console.log("using Babel in Webpack mode '" + process.env.WEBPACK_MODE + "'");
let babel_loader = {
test: /\.js$/,
// Do not try to execute babel on all node_modules. But some d3 stuff seems to need it's help.
include: [
path.resolve(__dirname, "web/htdocs/js"),
path.resolve(__dirname, "enterprise/web/htdocs/js/modules"),
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"),
],
use: {
loader: "babel-loader",
options: {
presets: [
[
"@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,
},
],
],
plugins: ["@babel/plugin-transform-parameters"],
},
},
};
module.exports.module.rules.unshift(babel_loader);
}