-
Notifications
You must be signed in to change notification settings - Fork 67
/
Copy pathwebpack.base.config.js
151 lines (146 loc) · 4.94 KB
/
webpack.base.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
require('dotenv-defaults').config();
const path = require('path');
const webpack = require('webpack');
const Dotenv = require('dotenv-webpack');
const { DefinePlugin, ProvidePlugin } = require('webpack');
const { getIfUtils } = require('webpack-config-utils');
const TerserPlugin = require('terser-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const NODE_ENV = process.env.NODE_ENV || 'development';
const { ifProduction } = getIfUtils(NODE_ENV);
const UI_ROOT = path.resolve(__dirname, 'ui/');
const optInPlugins = [];
if (NODE_ENV !== 'development' && process.env.BUNDLE_ANALYZER_ENABLED) {
// noinspection JSUnresolvedVariable
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
optInPlugins.push(new BundleAnalyzerPlugin({
analyzerMode: 'static',
openAnalyzer: false,
reportFilename: process.env.BUNDLE_ANALYZER_FILENAME || 'report.html',
}));
}
/**
* @typedef { import('webpack').Configuration } Configuration
*
* @type {Configuration}
*/
let baseConfig = {
mode: ifProduction('production', 'development'),
devtool: ifProduction('source-map', 'eval-cheap-module-source-map'),
optimization: {
minimizer: [
new TerserPlugin({
parallel: true,
terserOptions: {
sourceMap: true,
},
}),
],
moduleIds: 'deterministic',
},
node: {
__dirname: false,
},
devServer: {
historyApiFallback: true,
},
module: {
rules: [
{
test: /\.jsx?$/,
loader: 'babel-loader',
options: {
plugins: ['@babel/plugin-syntax-dynamic-import'],
},
},
{
test: /\.s?css$/,
exclude: /style\.lazy\.scss/,
use: [
// MiniCssExtractPlugin.loader,
'style-loader',
'css-loader',
'postcss-loader',
'sass-loader',
],
},
{
test: /style\.lazy\.scss/,
use: [
MiniCssExtractPlugin.loader,
// 'style-loader',
'css-loader',
'postcss-loader',
'sass-loader',
],
},
{
test: /\.(png|jpg|gif|svg)$/,
type: 'asset/resource',
},
{
test: /\.(vert|frag|glsl)$/,
use: {
loader: 'raw-loader',
},
},
],
},
// Allows imports for all directories inside '/ui' :)
resolve: {
modules: [UI_ROOT, 'node_modules', __dirname],
extensions: ['.js', '.jsx', '.json', '.scss'],
alias: {
config: path.resolve(__dirname, 'config.js'),
homepage: 'util/homepage.js',
homepages: process.env.CUSTOM_HOMEPAGE === 'true' ? path.resolve(__dirname, 'custom/homepages/v2') : ('homepages'),
memes: process.env.CUSTOM_HOMEPAGE === 'true' ? path.resolve(__dirname, 'custom/homepages/meme/index.js') : path.resolve(__dirname, 'homepages/meme/index.js'),
lbryinc: 'extras/lbryinc',
recsys: 'extras/recsys',
// Build optimizations for 'redux-persist-transform-filter'
'redux-persist-transform-filter': 'redux-persist-transform-filter/index.js',
'lodash.get': 'lodash-es/get',
'lodash.set': 'lodash-es/set',
'lodash.unset': 'lodash-es/unset',
'lodash.pickby': 'lodash-es/pickBy',
'lodash.isempty': 'lodash-es/isEmpty',
'lodash.forin': 'lodash-es/forIn',
'lodash.clonedeep': 'lodash-es/cloneDeep',
...ifProduction({}, { 'react-dom': '@hot-loader/react-dom' }),
},
symlinks: false,
},
plugins: [
new webpack.IgnorePlugin({ resourceRegExp: /^\.\/locale$/, contextRegExp: /moment$/ }),
new webpack.EnvironmentPlugin(['NODE_ENV']),
new DefinePlugin({
__static: `"${path.join(__dirname, 'static').replace(/\\/g, '\\\\')}"`,
'process.env.NODE_ENV': JSON.stringify(NODE_ENV),
'process.env.LBRY_API_URL': JSON.stringify(process.env.LBRY_API_URL),
'process.env.SENTRY_AUTH_TOKEN': JSON.stringify(process.env.SENTRY_AUTH_TOKEN),
'process.env.MOONPAY_SECRET_KEY': JSON.stringify(process.env.MOONPAY_SECRET_KEY),
}),
new ProvidePlugin({
Buffer: ['buffer', 'Buffer'],
process: 'process/browser',
__: [path.resolve(path.join(__dirname, 'ui/i18n')), '__'],
assert: [path.resolve(path.join(__dirname, 'ui/asserts')), 'assert'],
}),
new Dotenv({
allowEmptyValues: true, // allow empty variables (e.g. `FOO=`) (treat it as empty string, rather than missing)
systemvars: true, // load all the predefined 'process.env' variables which will trump anything local per dotenv specs.
silent: false, // hide any errors
defaults: true, // load '.env.defaults' as the default values if empty.
}),
new MiniCssExtractPlugin({
filename: NODE_ENV === 'development' ? '[name].css' : '[name].[contenthash]-1009.css',
chunkFilename: NODE_ENV === 'development' ? '[name].css' : '[name].[contenthash]-1009.css',
}),
...optInPlugins,
],
stats: {
errorDetails: true,
warnings: false,
},
};
module.exports = baseConfig;