forked from cilium/hubble-ui
-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.config.js
169 lines (163 loc) · 4.55 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
/* eslint-disable @typescript-eslint/no-var-requires */
const path = require('path');
const webpack = require('webpack');
const inliner = require('@geakstr/sass-inline-svg');
const Dotenv = require('dotenv-webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const CircularDependencyPlugin = require('circular-dependency-plugin');
/* eslint-enable @typescript-eslint/no-var-requires */
const isProduction = process.env.NODE_ENV === 'production';
const isDevelopment = process.env.NODE_ENV === 'development';
const stylesLoaders = ({ enableSass, enableModules }) => {
const sassOpts = {
modules: enableModules
? {
mode: 'local',
localIdentName: '[name]_[local]_[hash:base64:5]',
exportLocalsConvention: 'camelCase',
}
: false,
importLoaders: 2,
sourceMap: true,
url: false,
};
const cssOpts = {
modules: enableModules
? {
mode: 'local',
localIdentName: '[name]_[local]_[hash:base64:5]',
exportLocalsConvention: 'camelCase',
}
: false,
importLoaders: 1,
sourceMap: true,
url: false,
};
return [
{
loader: MiniCssExtractPlugin.loader,
},
{
loader: 'css-loader',
options: enableSass ? sassOpts : cssOpts,
},
].concat(
enableSass
? [
{
loader: 'sass-loader',
options: {
sourceMap: true,
implementation: require('sass'),
sassOptions: {
functions: {
...require('@geakstr/sass-inline-svg'),
'svg-icon($path, $selectors: null)': inliner(
path.join(__dirname, 'src/icons/blueprint'),
{
optimize: true,
encodingFormat: 'uri',
},
),
},
},
},
},
]
: [],
);
};
module.exports = {
target: 'web',
entry: path.resolve(__dirname, './src/index.tsx'),
mode: isProduction ? 'production' : 'development',
watch: isDevelopment,
devtool: isProduction ? 'source-map' : 'inline-source-map',
output: {
path: path.resolve(__dirname, './server/public'),
filename: isProduction
? 'bundle.[name].[contenthash].js'
: 'bundle.[name].js',
devtoolModuleFilenameTemplate: isProduction
? undefined
: '[absolute-resource-path]',
assetModuleFilename: 'static/media/[name].[hash:8][ext][query]',
},
stats: {
colors: true,
},
resolve: {
extensions: ['.tsx', '.ts', '.js', '.jsx', '.json', '.mjs'],
alias: {
'~backend': path.resolve(__dirname, './backend'),
'~': path.resolve(__dirname, './src/'),
},
},
module: {
rules: [
{
enforce: 'pre',
test: /\.(js|jsx|mjs|ts|tsx)$/,
loader: 'source-map-loader',
include: path.resolve(__dirname, 'src'),
},
{
test: /\.js$/,
type: 'javascript/auto',
},
{
test: /\.ts(x?)$/,
exclude: /node_modules/,
use: ['babel-loader', 'ts-loader'],
},
{
test: /\.(bmp|gif|jpg|jpeg|png|woff|woff2|eot|ttf)$/,
type: 'asset',
},
{
test: /\.svg$/,
exclude: /node_modules/,
use: ['svg-react-loader'],
},
{
test: /\.css$/,
use: stylesLoaders({ enableSass: false, enableModules: false }),
},
{
test: /.blueprint\.scss$/,
use: stylesLoaders({ enableSass: true, enableModules: false }),
},
{
test: /\.s[ac]ss$/,
use: stylesLoaders({ enableSass: true, enableModules: true }),
exclude: /.blueprint\.scss$/,
},
],
},
plugins: [
new CircularDependencyPlugin({
exclude: /node_modules/,
failOnError: true,
allowAsyncCycles: false,
cwd: process.cwd(),
}),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
'process.env.BLUEPRINT_NAMESPACE': JSON.stringify('bp3'),
}),
new MiniCssExtractPlugin({
filename: 'bundle.[name].[contenthash].css',
chunkFilename: '[id].chunk.bundle.[name].[contenthash].css',
}),
new Dotenv({
path: `.env${isProduction ? '.production' : '.development'}`,
}),
new HtmlWebpackPlugin({
filename: path.resolve(__dirname, `./server/public/index.html`),
template: path.resolve(__dirname, `./src/index.html`),
chunksSortMode: 'auto',
minify: true,
}),
],
};