-
Notifications
You must be signed in to change notification settings - Fork 13
/
webpack.config.js
123 lines (121 loc) · 4.21 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
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const webpack = require('webpack');
const dotenv = require('dotenv');
dotenv.config();
const IS_RELEASE =
process.env.NODE_ENV === 'production' || process.env.NODE_ENV === 'staging' || process.env.NODE_ENV === 'test';
module.exports = {
entry: './src/main.tsx',
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, 'dist'),
publicPath: 'auto',
},
mode: IS_RELEASE ? 'production' : 'development',
devtool: IS_RELEASE ? 'source-map' : 'eval-cheap-module-source-map',
target: 'web',
module: {
rules: [
{
test: /\.(s*)css$/,
use: [
'css-hot-loader',
MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: {
sourceMap: !IS_RELEASE,
url: false,
},
},
{
loader: 'sass-loader',
options: { sourceMap: !IS_RELEASE },
},
{
loader: 'sass-resources-loader',
options: {
resources: require(path.resolve(__dirname, 'src/components/shared/styles/index.js')),
},
},
],
},
{
test: /\.svg$/,
exclude: /node_modules/,
use: [
{
loader: 'svg-sprite-loader',
options: {
extract: true,
spriteFilename: 'bot-sprite.svg',
},
},
{
loader: 'svgo-loader',
options: {
plugins: [{ removeUselessStrokeAndFill: false }, { removeUnknownsAndDefaults: false }],
},
},
],
},
{
test: /\.(js|jsx|ts|tsx)$/,
exclude: /node_modules/,
loader: 'babel-loader',
},
{
test: /\.xml$/,
exclude: /node_modules/,
use: 'raw-loader',
},
],
},
resolve: {
alias: {
react: path.resolve('./node_modules/react'),
'react-dom': path.resolve('./node_modules/react-dom'),
'@/external': path.resolve(__dirname, './src/external'),
'@/components': path.resolve(__dirname, './src/components'),
'@/hooks': path.resolve(__dirname, './src/hooks'),
'@/utils': path.resolve(__dirname, './src/utils'),
'@/constants': path.resolve(__dirname, './src/constants'),
},
extensions: ['.js', '.jsx', '.ts', '.tsx'],
plugins: [new TsconfigPathsPlugin()],
fallback: {
url: require.resolve('url/'), // Add this line to include the 'url' polyfill
},
},
plugins: [
new HtmlWebpackPlugin({
template: './index.html',
}),
new MiniCssExtractPlugin({
filename: '[name].css',
chunkFilename: '[id].css',
}),
new webpack.DefinePlugin({
'process.env': JSON.stringify(process.env),
}),
new CopyWebpackPlugin({
patterns: [
{ from: 'node_modules/@deriv/deriv-charts/dist/*', to: 'js/smartcharts/[name][ext]' },
{ from: 'node_modules/@deriv/deriv-charts/dist/chart/assets/*', to: 'assets/[name][ext]' },
{ from: path.join(__dirname, 'public'), to: '' },
],
}),
],
devServer: {
static: {
directory: path.join(__dirname, 'public'),
},
compress: true,
port: 8443,
hot: true,
},
};