-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
87 lines (84 loc) · 1.89 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
const webpack = require('webpack');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const { GenerateSW } = require('workbox-webpack-plugin');
module.exports = (_, options) => {
const isProduction = (options.mode === 'production');
const homepage = process.env.PUBLIC_URL ?? (require('./package.json').homepage || '');
const publicUrl = isProduction ? homepage : '';
const commit = process.env.COMMIT?.slice(0, 8);
return {
entry: './src/index.tsx',
resolve: {
extensions: [
'.js',
'.jsx',
'.ts',
'.tsx',
],
},
devServer: {
contentBase: '/src/App/public',
historyApiFallback: true,
port: 8000,
host: '0.0.0.0',
},
devtool: 'source-map',
output: {
filename: 'index.js',
publicPath: `${publicUrl}/`,
path: `${__dirname}/build`, // eslint-disable-line no-undef
},
module: {
rules: [
{
test: /\.ts(x?)$/,
exclude: /node_modules/,
use: [
{
loader: 'ts-loader'
}
]
},
{
enforce: 'pre',
test: /\.js$/,
loader: 'source-map-loader'
},
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: [{
loader: 'babel-loader',
options: { presets: ['@babel/react', '@babel/env'] },
}],
},
{
test: /\.css$/,
use: ['style-loader', 'css-loader'],
},
],
},
plugins: [
new CopyWebpackPlugin({
patterns: [
{ from: 'src/App/public', filter: path => !path.endsWith('.html'), },
],
}),
new HtmlWebpackPlugin({
template: 'src/App/public/index.html',
inject: 'body',
publicUrl: publicUrl
}),
new webpack.HotModuleReplacementPlugin(),
new webpack.NoEmitOnErrorsPlugin(),
new GenerateSW(),
new webpack.DefinePlugin({
'process.env': {
PUBLIC_URL: JSON.stringify(publicUrl),
COMMIT: JSON.stringify(commit),
},
}),
],
};
};