-
Notifications
You must be signed in to change notification settings - Fork 36
/
webpack.config.js
113 lines (108 loc) · 3.66 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
const webpack = require('webpack');
require('dotenv').config();
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const TerserPlugin = require('terser-webpack-plugin');
const ManifestPlugin = require('webpack-manifest-plugin');
const path = require('path');
const API_URLS = require('./common/api-urls-constants.js');
const PRODUCTION = process.env.NODE_ENV === 'production';
const commonPlugins = [new ManifestPlugin()];
const plugins = PRODUCTION
? commonPlugins.concat([
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify('production'),
npm_package_version: JSON.stringify(process.env.npm_package_version),
AUDIO_API_PASS: JSON.stringify(process.env.REACT_APP_AUDIO_API_PASS)
},
PRODUCTION: JSON.stringify(true),
API_URL: JSON.stringify(API_URLS.PRODUCTION),
AMRIT_KEERTAN_API_URL: JSON.stringify(API_URLS.AMRIT_KEERTAN),
AMRIT_KEERTAN_SHABADS_API_URL: JSON.stringify(API_URLS.AMRIT_KEERTAN_SHABADS),
SYNC_API_URL: JSON.stringify(API_URLS.SYNC.PRODUCTION),
BANIS_API_URL: JSON.stringify(API_URLS.BANIS),
BANNERS_URL: JSON.stringify(API_URLS.BANNERS),
CEREMONIES_URL: JSON.stringify(API_URLS.CEREMONIES),
DOODLE_URL: JSON.stringify(API_URLS.DOODLE),
WRITERS_API_URL: JSON.stringify(API_URLS.WRITERS),
GURBANIBOT_URL: JSON.stringify(API_URLS.GURBANIBOT)
})
])
: commonPlugins.concat([
new webpack.DefinePlugin({
'process.env': {
npm_package_version: JSON.stringify(process.env.npm_package_version),
AUDIO_API_PASS: JSON.stringify(process.env.REACT_APP_AUDIO_API_PASS)
},
PRODUCTION: JSON.stringify(false),
API_URL: JSON.stringify(API_URLS.DEVELOPMENT),
SYNC_API_URL: JSON.stringify(API_URLS.SYNC.LOCAL),
AMRIT_KEERTAN_API_URL: JSON.stringify(API_URLS.AMRIT_KEERTAN),
AMRIT_KEERTAN_SHABADS_API_URL: JSON.stringify(API_URLS.AMRIT_KEERTAN_SHABADS),
BANIS_API_URL: JSON.stringify(API_URLS.BANIS),
BANNERS_URL: JSON.stringify(API_URLS.BANNERS),
CEREMONIES_URL: JSON.stringify(API_URLS.CEREMONIES),
DOODLE_URL: JSON.stringify(API_URLS.DOODLE),
WRITERS_API_URL: JSON.stringify(API_URLS.WRITERS),
GURBANIBOT_URL: JSON.stringify(API_URLS.GURBANIBOT)
}),
new CleanWebpackPlugin(),
]);
const app = path.resolve(__dirname, 'src', 'js', 'index.js');
module.exports = {
mode: PRODUCTION ? 'production' : 'development',
entry: {
app,
},
output: {
path: path.resolve(__dirname, 'public/assets', 'js'),
chunkFilename: PRODUCTION ? 'chunks/[name]-[hash].js' : 'chunks/[name].js',
filename: PRODUCTION ? '[name]-[hash].js' : '[name].js',
publicPath: '/assets/js/',
},
devtool: PRODUCTION ? undefined : 'inline-source-map',
plugins,
resolve: {
extensions: ['.js', '.jsx', '.ts', '.tsx', '.mjs'],
alias: {
// Client root
'@': path.resolve(__dirname, 'src/js/'),
},
},
optimization: {
noEmitOnErrors: true,
minimizer: [new TerserPlugin()],
concatenateModules: true,
splitChunks: {
cacheGroups: {
// All dependencies in `node_modules` become part of vendor chunk
vendors: {
test: /[\\/]node_modules[\\/]/,
name: 'vendor',
chunks: 'all',
},
},
},
},
module: {
rules: [
{
test: /\.(tsx?)|(js)$/,
loader: 'babel-loader',
},
{
test: /\.less$/,
loader: 'less-loader', // compiles Less to CSS
},
{
test: /\.css$/i,
use: ['style-loader', 'css-loader'],
},
{
test: /\.mjs$/,
include: /node_modules/,
type: 'javascript/auto'
}
],
},
};