-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathwebpack.config.cjs
More file actions
115 lines (111 loc) · 2.87 KB
/
Copy pathwebpack.config.cjs
File metadata and controls
115 lines (111 loc) · 2.87 KB
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
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CopyPlugin = require('copy-webpack-plugin');
const { InjectManifest } = require('workbox-webpack-plugin');
const webpack = require('webpack');
module.exports = (env, argv) => {
const isProduction = argv.mode === 'production';
// Basic config that's always applied
const config = {
entry: './src/index.tsx',
devtool: 'inline-source-map',
module: {
rules: [
{
test: /\.(ts|tsx)$/,
exclude: /node_modules/,
use: {
loader: 'ts-loader',
options: {
transpileOnly: true
}
}
},
{
test: /\.css$/,
use: ['style-loader', 'css-loader', 'postcss-loader']
}
]
},
resolve: {
extensions: ['.tsx', '.ts', '.js', '.jsx', '.mjs'],
extensionAlias: {
'.js': ['.js', '.ts', '.tsx', '.jsx'],
'.mjs': ['.mjs', '.js', '.ts', '.tsx', '.jsx']
},
fallback: {
path: false,
fs: false,
os: false,
crypto: false,
url: false
}
},
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, 'dist'),
publicPath: '/'
},
plugins: [
new HtmlWebpackPlugin({
template: './public/index.html',
inject: true,
// In development mode, add the cleanup script
...(isProduction ? {} : {
scripts: [
{ src: '/sw-cleanup.js', async: true, defer: true }
]
})
}),
new CopyPlugin({
patterns: [
{
from: 'public',
to: '',
globOptions: {
ignore: ['**/index.html']
}
}
],
}),
// Define environment variables that will be available to the application
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(isProduction ? 'production' : 'development')
}),
],
devServer: {
static: {
directory: path.join(__dirname, 'public'),
},
compress: true,
historyApiFallback: true,
hot: true,
port: 3000,
proxy: [{
context: ['/sync', '/api'],
target: 'http://localhost:8080',
ws: true,
changeOrigin: true
}],
},
experiments: { asyncWebAssembly: true },
target: 'web',
performance: {
hints: false,
maxEntrypointSize: 512000,
maxAssetSize: 512000,
},
};
// Only add Workbox in production mode to avoid development issues
if (isProduction) {
config.plugins.push(
new InjectManifest({
swSrc: './src/service-worker.ts',
swDest: 'service-worker.js',
exclude: [/\.map$/, /asset-manifest\.json$/],
maximumFileSizeToCacheInBytes: 10 * 1024 * 1024, // 10 MB
})
);
}
return config;
};