-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebpack.common.cjs
155 lines (154 loc) · 4.77 KB
/
webpack.common.cjs
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
const path = require("path");
const CopyPlugin = require("copy-webpack-plugin");
const { GitRevisionPlugin } = require("git-revision-webpack-plugin");
const TsconfigPathsPlugin = require("tsconfig-paths-webpack-plugin");
const webpack = require("webpack");
const VersionFile = require("webpack-version-file");
const gitRevisionPlugin = new GitRevisionPlugin();
module.exports = {
entry: {
app: path.resolve(__dirname, "src", "index.tsx"),
},
plugins: [
new webpack.IgnorePlugin({ resourceRegExp: /^\.\/(config|version)\.js$/ }),
gitRevisionPlugin,
new webpack.DefinePlugin({
COMMITHASH: JSON.stringify(gitRevisionPlugin.commithash()),
APP_VERSION: JSON.stringify(require("./package.json").version),
}),
new VersionFile({
output: "src/version.json",
package: "./package.json",
template: "./version.ejs",
data: {
buildDate: new Date(),
commitHash: JSON.stringify(gitRevisionPlugin.commithash()),
},
}),
new CopyPlugin({
patterns: [{ from: "src/version.json", to: "" }],
}),
new webpack.ProvidePlugin({
process: "process/browser",
}),
],
module: {
rules: [
{
test: /\.(tsx|ts|jsx)?$/,
include: path.resolve(__dirname, "src"),
use: [
{
loader: "ts-loader",
options: {
transpileOnly: true,
experimentalWatchApi: true,
},
},
],
},
{
test: /\.(svg|ttf|eot|woff|woff2)$/,
type: "asset/resource",
// only process modules with this loader
// if they live under a 'fonts' or 'pficon' directory
include: [
path.resolve(__dirname, "node_modules/patternfly/dist/fonts"),
path.resolve(
__dirname,
"node_modules/@patternfly/react-core/dist/styles/assets/fonts",
),
path.resolve(
__dirname,
"node_modules/@patternfly/react-core/dist/styles/assets/pficon",
),
path.resolve(
__dirname,
"node_modules/@patternfly/patternfly/assets/fonts",
),
path.resolve(
__dirname,
"node_modules/@patternfly/patternfly/assets/pficon",
),
],
},
{
test: /\.svg$/,
// only process SVG modules with this loader when they don't live under a
// 'fonts', or 'pficon' directory, those are handled with other loaders
include: (input) =>
input.indexOf("fonts") === -1 && input.indexOf("pficon") === -1,
type: "asset/inline",
},
{
test: /\.(jpg|jpeg|png|gif)$/i,
include: [
path.resolve(__dirname, "src"),
path.resolve(__dirname, "node_modules/patternfly"),
path.resolve(
__dirname,
"node_modules/@patternfly/patternfly/assets/images",
),
path.resolve(
__dirname,
"node_modules/@patternfly/react-styles/css/assets/images",
),
path.resolve(
__dirname,
"node_modules/@patternfly/react-core/dist/styles/assets/images",
),
path.resolve(
__dirname,
"node_modules/@patternfly/react-core/node_modules/@patternfly/react-styles/css/assets/images",
),
path.resolve(
__dirname,
"node_modules/@patternfly/react-table/node_modules/@patternfly/react-styles/css/assets/images",
),
path.resolve(
__dirname,
"node_modules/@patternfly/react-inline-edit-extension/node_modules/@patternfly/react-styles/css/assets/images",
),
],
type: "asset/inline",
use: [
{
options: {
limit: 5000,
outputPath: "images",
name: "[name].[ext]",
},
},
],
},
{
// this configuration is used to ensure that Webpack can correctly handle and resolve both .js and .mjs files,
// even if the paths to these modules are not fully specified. This can help avoid issues with module resolution and improve compatibility with various libraries and codebase
test: /\.m?js$/,
resolve: {
fullySpecified: false,
},
},
{
test: /\.txt$/,
type: "asset/resource",
include: [path.resolve(__dirname, "version.txt")],
},
],
},
output: {
filename: "[name].bundle.js",
path: path.resolve(__dirname, "dist"),
publicPath: "/",
},
resolve: {
extensions: [".ts", ".tsx", ".js", ".jsx"],
plugins: [
new TsconfigPathsPlugin({
configFile: path.resolve(__dirname, "./tsconfig.json"),
}),
],
symlinks: false,
cacheWithContext: false,
},
};