generated from Alvadda/react-ts-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
90 lines (86 loc) · 2.28 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
const path = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const CopyPlugin = require('copy-webpack-plugin')
const { GenerateSW } = require('workbox-webpack-plugin')
const packageJson = require('./package.json')
var webpack = require('webpack')
require('dotenv').config({ path: './.env' })
const outputPath = path.resolve(__dirname, 'dist')
module.exports = ({ prod }) => {
const version = process.env.VERSION ?? packageJson.version
const plugins = [
new HtmlWebpackPlugin({
template: 'public/index.html',
}),
new webpack.DefinePlugin({
'process.env': JSON.stringify({ ...process.env, VERSION: version }),
}),
new CopyPlugin({
patterns: [{ from: 'public/pwa', to: './' }],
}),
new webpack.ProvidePlugin({
Buffer: ['buffer', 'Buffer'],
process: 'process/browser',
}),
]
if (prod) {
plugins.push(
new GenerateSW({
clientsClaim: true,
skipWaiting: true,
swDest: 'service-worker.js',
maximumFileSizeToCacheInBytes: 1000000000000,
})
)
}
return {
mode: 'development',
entry: './src/index.tsx',
devtool: 'inline-source-map',
output: {
path: outputPath,
filename: '[name].bundle.js',
chunkFilename: '[name].bundle.js',
},
resolve: {
extensions: ['.ts', '.tsx', '.js', '.json'],
alias: {
test: path.resolve(__dirname, 'src'),
},
fallback: {
process: require.resolve('process/browser'),
zlib: require.resolve('browserify-zlib'),
stream: require.resolve('stream-browserify'),
util: require.resolve('util'),
buffer: require.resolve('buffer'),
asset: require.resolve('assert'),
},
},
module: {
rules: [
{
test: /\.(ts|js)x?$/,
exclude: /node_modules/,
loader: 'babel-loader',
},
{
test: /\.(woff|woff2|eot|ttf|otf|svg)$/i,
type: 'asset/resource',
},
{
test: /\.s[ac]ss$/i,
use: ['style-loader', 'css-loader', 'sass-loader'],
},
{
test: /\.css$/i,
use: ['style-loader', 'css-loader'],
},
],
},
plugins,
devServer: {
historyApiFallback: true,
hot: true,
},
}
}