forked from lbryio/lbry-desktop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.base.config.js
120 lines (116 loc) · 3.3 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
const path = require('path');
const webpack = require('webpack');
const merge = require('webpack-merge');
const { DefinePlugin, ProvidePlugin } = require('webpack');
const { getIfUtils, removeEmpty } = require('webpack-config-utils');
const TerserPlugin = require('terser-webpack-plugin');
const NODE_ENV = process.env.NODE_ENV || 'development';
const { ifProduction } = getIfUtils(NODE_ENV);
const UI_ROOT = path.resolve(__dirname, 'src/ui/');
const STATIC_ROOT = path.resolve(__dirname, 'static/');
const DIST_ROOT = path.resolve(__dirname, 'dist/');
let baseConfig = {
mode: ifProduction('production', 'development'),
devtool: ifProduction(false, 'eval-source-map'),
optimization: {
minimizer: [
new TerserPlugin({
parallel: true,
terserOptions: {
mangle: true,
toplevel: true,
},
}),
],
},
node: {
__dirname: false,
},
devServer: {
historyApiFallback: true,
},
module: {
rules: [
{
test: /\.jsx?$/,
exclude: /node_modules/,
loader: 'babel-loader',
},
{
test: /\.module.scss$/,
use: [
'style-loader',
{
loader: 'css-loader',
options: {
modules: true,
},
},
'postcss-loader',
'sass-loader',
],
},
{
test: /\.s?css$/,
exclude: /\.module.scss$/,
use: ['style-loader', 'css-loader', 'postcss-loader', 'sass-loader'],
},
{
test: /\.(png|svg|gif)$/,
use: {
loader: 'file-loader',
options: {
outputPath: 'static/img',
name: '[name].[ext]',
},
},
},
{
test: /\.(woff|woff2)$/,
use: {
loader: 'file-loader',
options: {
outputPath: 'static/font',
},
},
},
{
test: /\.(vert|frag|glsl)$/,
use: {
loader: 'raw-loader',
},
},
{ test: /\.node$/, loader: 'node-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'),
'lbry-redux$': 'lbry-redux/dist/bundle.es.js',
// 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' }),
},
},
plugins: [
new webpack.IgnorePlugin(/^\.\/locale$/, /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.SDK_API_URL': JSON.stringify(process.env.SDK_API_URL),
'process.env.LBRY_API_URL': JSON.stringify(process.env.LBRY_API_URL),
}),
],
};
module.exports = baseConfig;