forked from osbuild/cockpit-composer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
164 lines (158 loc) · 5.29 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
const path = require("path");
const webpack = require("webpack");
const CopyWebpackPlugin = require("copy-webpack-plugin");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const CleanWebpackPlugin = require("clean-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const ESLintPlugin = require("eslint-webpack-plugin");
const babelConfig = require("./babel.config");
// absolute path disables recursive module resolution, so build a relative one
const nodedir = path.relative(process.cwd(), path.resolve(process.env.SRCDIR || __dirname, "node_modules"));
const [mode, devtool] =
process.env.NODE_ENV === "production" ? ["production", "source-map"] : ["development", "inline-source-map"];
const output = {
path: path.resolve(__dirname, "./public/dist"),
filename: "[name].js",
sourceMapFilename: "[file].map",
};
// add istanbul as babel plugin to enable code coverage
process.argv.includes("--with-coverage") && babelConfig.plugins.push("istanbul");
const plugins = [
new CleanWebpackPlugin(["public/dist"]),
// automatically load jquery instead of having to import or require them everywhere
new webpack.ProvidePlugin({
$: "jquery",
jQuery: "jquery",
}),
// copy our assets
new CopyWebpackPlugin([
{
from: "./public/manifest.json",
},
]),
// main.js has to be injected into body and after <div id="main"></div>
new HtmlWebpackPlugin({
filename: "index.html",
template: "public/index.ejs",
inject: "body",
}),
// avoid multi chunks for every index.js inside pages folder
new webpack.optimize.LimitChunkCountPlugin({
maxChunks: 1,
}),
new MiniCssExtractPlugin({
filename: "[name].css",
chunkFilename: "[name].bundle.css",
}),
new ESLintPlugin({
files: ["components/**/*.js, core/**/*.js, pages/**/*.js, data/**/*.js"],
}),
];
module.exports = {
mode,
entry: "./main.js",
plugins,
output,
devtool,
externals: { cockpit: "cockpit", jQuery: "jquery" },
// disable noisy warnings about exceeding the recommended size limit
performance: {
maxEntrypointSize: 20000000,
maxAssetSize: 20000000,
},
resolve: { alias: { "font-awesome": path.resolve(nodedir, "font-awesome-sass/assets/stylesheets") } },
module: {
rules: [
{
test: /\.(js|jsx)$/,
include: [
path.resolve(__dirname, "./actions"),
path.resolve(__dirname, "./components"),
path.resolve(__dirname, "./core"),
path.resolve(__dirname, "./pages"),
path.resolve(__dirname, "./data"),
path.resolve(__dirname, "./main.js"),
],
use: {
loader: "babel-loader",
options: babelConfig,
},
},
// add type: "javascript/auto" when transforming JSON via loader to JS
{
include: [path.resolve(__dirname, "./routes.json")],
use: [
{
loader: "babel-loader",
options: babelConfig,
},
path.resolve(__dirname, "./utils/routes-loader.js"),
],
type: "javascript/auto",
},
{
test: /\.css$/,
use: [
MiniCssExtractPlugin.loader,
{
loader: "css-loader",
options: { url: false },
},
],
},
/* HACK: remove unwanted fonts from PatternFly's css */
{
test: /patternfly-cockpit.scss$/,
use: [
MiniCssExtractPlugin.loader,
{
loader: "css-loader",
options: { url: false },
},
{
loader: "string-replace-loader",
options: {
multiple: [
{
search: /src:url[(]"patternfly-icons-fake-path\/glyphicons-halflings-regular[^}]*/g,
replace: 'font-display:block; src:url("../base1/fonts/glyphicons.woff") format("woff");',
},
{
search: /src:url[(]"patternfly-fonts-fake-path\/PatternFlyIcons[^}]*/g,
replace: 'src:url("../base1/fonts/patternfly.woff") format("woff");',
},
{
search: /src:url[(]"patternfly-fonts-fake-path\/fontawesome[^}]*/,
replace: 'font-display:block; src:url("../base1/fonts/fontawesome.woff?v=4.2.0") format("woff");',
},
{
search: /src:url\("patternfly-icons-fake-path\/pficon[^}]*/g,
replace: 'src:url("../base1/fonts/patternfly.woff") format("woff");',
},
{
search: /@font-face[^}]*patternfly-fonts-fake-path[^}]*}/g,
replace: "",
},
],
},
},
{
loader: "sass-loader",
options: {
sassOptions: {
includePaths: [
// Teach webpack to resolve these references in order to build PF3 scss
path.resolve(nodedir, "font-awesome-sass", "assets", "stylesheets"),
path.resolve(nodedir, "patternfly", "dist", "sass"),
path.resolve(nodedir, "bootstrap-sass", "assets", "stylesheets"),
],
outputStyle: "compressed",
quietDeps: true,
},
},
},
],
},
],
},
};