forked from project-koku/koku-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
193 lines (189 loc) · 5.64 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
const path = require('path');
const webpack = require('webpack');
const weblog = require('webpack-log');
const log = weblog({
name: 'wds',
});
const HtmlWebpackPlugin = require('html-webpack-plugin');
const HtmlReplaceWebpackPlugin = require('html-replace-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const GitRevisionPlugin = require('git-revision-webpack-plugin');
const gitRevisionPlugin = new GitRevisionPlugin({
branch: true,
});
const gitBranch = process.env.BRANCH || gitRevisionPlugin.branch();
const appEnv = process.env.APP_ENV;
const fileRegEx = /\.(png|woff|woff2|eot|ttf|svg|gif|jpe?g|png)(\?[a-z0-9=.]+)?$/;
const srcDir = path.resolve(__dirname, './src');
const distDir = path.resolve(__dirname, './public/');
let deploymentEnv = 'apps';
let release = '';
const betaBranch =
gitBranch === 'master' ||
gitBranch === 'qa-beta' ||
gitBranch === 'prod-beta';
if (!appEnv && betaBranch) {
deploymentEnv = 'beta/apps';
release = 'beta';
}
const publicPath = `/${deploymentEnv}/cost-management/`;
log.info(`appEnv=${appEnv}`);
log.info(`gitBranch=${gitBranch}`);
log.info(`publicPath=${publicPath}`);
module.exports = env => {
const isProduction = env === 'production';
const stats = {
excludeAssets: fileRegEx,
colors: true,
modules: false,
};
return {
stats: stats,
mode: isProduction ? 'production' : 'development',
devtool: isProduction ? 'source-maps' : 'eval',
entry: [
require.resolve(
'@red-hat-insights/insights-frontend-components/components/Skeleton.css'
),
require.resolve('patternfly/dist/css/patternfly.css'),
require.resolve('patternfly/dist/css/patternfly-additions.css'),
require.resolve('@patternfly/patternfly/patternfly-variables.css'),
require.resolve('@patternfly/patternfly/utilities/Display/display.css'),
require.resolve('@patternfly/patternfly/utilities/Flex/flex.css'),
path.join(srcDir, './styles/global.css'),
path.join(srcDir, 'index.tsx'),
],
output: {
path: distDir,
filename: isProduction ? '[chunkhash].bundle.js' : '[name].bundle.js',
publicPath: publicPath,
},
module: {
rules: [
{
test: /\.tsx?$/,
use: [
{
loader: 'ts-loader',
},
!isProduction && {
loader: 'babel-loader',
options: {
plugins: [
// See https://github.com/babel/babel/issues/8049
[
'@babel/plugin-syntax-typescript',
{
isTSX: true,
},
],
[
'@babel/plugin-syntax-decorators',
{
legacy: true,
},
],
'@babel/plugin-syntax-jsx',
'@babel/plugin-syntax-dynamic-import',
'react-hot-loader/babel',
],
},
},
].filter(Boolean),
},
{
test: /\.html?$/,
use: [
{
loader: 'html-loader',
},
],
},
{
test: /\.css$/i,
sideEffects: true,
use: [
isProduction ? MiniCssExtractPlugin.loader : 'style-loader',
'css-loader',
],
},
{
test: fileRegEx,
loader: 'file-loader',
},
],
},
plugins: [
new webpack.DefinePlugin({
'process.env.APP_PUBLIC_PATH': JSON.stringify(publicPath),
'process.env.VERSION': JSON.stringify(gitRevisionPlugin.version()),
'process.env.COMMITHASH': JSON.stringify(
gitRevisionPlugin.commithash()
),
'process.env.BRANCH': JSON.stringify(gitRevisionPlugin.branch()),
}),
new CopyWebpackPlugin([
{
from: path.join(srcDir, 'locales'),
to: path.join(distDir, 'locales'),
},
]),
new HtmlWebpackPlugin({
template: path.join(srcDir, 'index.html'),
}),
new HtmlReplaceWebpackPlugin([
{
pattern: '@@env',
replacement: deploymentEnv,
},
]),
new MiniCssExtractPlugin({
filename: isProduction ? '[contenthash].css' : '[name].css',
chunkFilename: isProduction ? '[contenthash].css' : '[id].css',
}),
// development plugins
!isProduction && new webpack.HotModuleReplacementPlugin(),
//production plugins
].filter(Boolean),
optimization: {
splitChunks: {
cacheGroups: {
commons: {
test: /[\\/]node_modules[\\/](react|react-dom|redux)[\\/]/,
name: 'vendor',
chunks: 'all',
},
},
},
},
performance: {
assetFilter: assetFilename =>
!(fileRegEx.test(assetFilename) || /\.map$/.test(assetFilename)),
},
resolve: {
extensions: ['.tsx', '.ts', '.js'],
plugins: [
new TsconfigPathsPlugin({
configFile: path.resolve(__dirname, './tsconfig.json'),
}),
],
},
devServer: {
stats: stats,
contentBase: false,
historyApiFallback: {
index: `${publicPath}/index.html`,
},
hot: true,
port: 8002,
disableHostCheck: true,
headers: {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Headers':
'Origin, X-Requested-With, Content-Type, Accept, Authorization',
},
},
};
};