-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
executable file
·118 lines (112 loc) · 4.18 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
const HtmlWebpackPlugin = require('html-webpack-plugin');
const InterpolateHtmlPlugin = require('interpolate-html-plugin');
const path = require('path');
const fs = require('fs');
const webpack = require('webpack');
const appLocalDomainName = process.env.APP_LOCAL_DOMAIN_NAME;
let devServerConfig = {
historyApiFallback: true,
hot: true,
compress: true,
port: process.env.FRONTEND_LOCAL_PORT || 3000,
allowedHosts: [appLocalDomainName], // To avoid "Invalid Host header" error
};
if (process.env.REACT_APP_API_URL.includes("https://")) {
devServerConfig.server = {
// Enable HTTPS
type: 'https',
options: {
key: fs.readFileSync(path.resolve(__dirname, `${appLocalDomainName}.key`)),
cert: fs.readFileSync(path.resolve(__dirname, `${appLocalDomainName}.chain.crt`)),
// ca_cert: fs.readFileSync(path.resolve(__dirname, 'ca.crt')),
// passphrase: 'password',
},
};
}
console.log('devServerConfig:', devServerConfig);
module.exports = {
mode: 'development',
entry: './src/index.tsx',
// entry: './src/index.jsx',
target: 'web',
module: {
rules: [
{
test: /\.(js|jsx|tsx)$/,
// exclude: /node_modules/,
resolve: {
fullySpecified: false,
},
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env', '@babel/preset-react', '@babel/preset-typescript'],
plugins: ['@babel/plugin-proposal-class-properties']
}
}
},
{
test: /\.css$/,
use: ['style-loader', 'css-loader', 'postcss-loader'],
},
{
test: /\.svg$/, // Match SVG files
type: 'asset/resource',
generator: {
filename: 'images/[name][ext][query]' // Output path for the SVG files
}
},
],
},
resolve: {
extensions: ['.*', '.js', '.jsx', '.tsx'],
alias: {
'@': path.resolve(__dirname, 'src/'),
},
fallback: {
"os": require.resolve("os-browserify/browser"),
"url": require.resolve("url"),
"crypto": require.resolve("crypto-browserify"),
"stream": require.resolve("stream-browserify"),
"assert": require.resolve("assert"),
"vm": require.resolve("vm-browserify"),
"tty": require.resolve("tty-browserify"),
"constants": require.resolve("constants-browserify"),
}
},
plugins: [
new HtmlWebpackPlugin({
template: './public/index.html',
filename: "./index.html",
favicon: "./public/favicon.ico",
manifest: "./public/manifest.json",
publicPath: '/'
}),
new webpack.DefinePlugin({
// Environment variables
'process.env': {
// PUBLIC_URL: JSON.stringify(`https://${appLocalDomainName}`),
REACT_APP_VERSION: JSON.stringify(process.env.REACT_APP_VERSION || fs.readFileSync('version.txt', 'utf8')),
REACT_APP_API_URL: JSON.stringify(process.env.REACT_APP_API_URL || `https://${appLocalDomainName}`),
REACT_APP_DEBUG: JSON.stringify(process.env.REACT_APP_DEBUG || '0'),
REACT_APP_URI_PREFIX: JSON.stringify(process.env.REACT_APP_URI_PREFIX || 'exampleapp_frontend'),
REACT_APP_X_TOKEN: JSON.stringify(process.env.REACT_APP_X_TOKEN || ''),
REACT_APP_APP_NAME: JSON.stringify(process.env.REACT_APP_APP_NAME || 'exampleapp'),
}
}),
new webpack.ProvidePlugin({
process: 'process/browser',
}),
// This solves the %PUBLIC_URL% issue in public/index.html file...
new InterpolateHtmlPlugin({
PUBLIC_URL: '',
}),
],
devServer: devServerConfig,
output: {
path: path.resolve(__dirname, 'dist'),
filename: '[name].bundle.js',
publicPath: '/',
clean: true,
},
}