-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.js
More file actions
117 lines (111 loc) · 3.39 KB
/
Copy pathwebpack.config.js
File metadata and controls
117 lines (111 loc) · 3.39 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
116
117
;(function() {
const crypto = require('crypto');
const _createHash = crypto.createHash;
crypto.createHash = (alg, opts) => _createHash(alg === 'md4' ? 'md5' : alg, opts);
})();
// @ts-check
/// <reference path="./src/serviceworker-webpack-plugin.d.ts" />
const path = require('path');
const webpack = require('webpack');
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const ServiceWorkerWebpackPlugin = require('serviceworker-webpack5-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const r = path.resolve.bind(null, __dirname);
const presetMode = process.env.NODE_ENV || 'development';
const isProduction = (presetMode === 'production');
const BASENAME = process.env.BASENAME || "/";
const VERSION = require("./version")();
/** @type {webpack.Configuration} */
module.exports = {
mode: presetMode,
context: __dirname,
devtool: isProduction ? false : 'cheap-module-source-map',
entry: {
'index': r("src/index.tsx"),
},
output: {
path: r("public"),
filename: isProduction ? "[id].[hash].js" : "[name].js",
},
optimization: {
splitChunks: false,
},
performance: {
maxAssetSize: 500 * 1000,
maxEntrypointSize: 500 * 1000,
},
module: {
rules: [
{
test: /\.m?js$/,
resolve: {
fullySpecified: false
}
},
{
test: /\.(js|json|ts|tsx)$/,
include: r("src"),
exclude: r("src/sw.ts"),
loader: 'ts-loader',
options: {
experimentalWatchApi: true,
configFile: r("tsconfig.json"),
},
},
{
test: /\.(js|json|ts|tsx|mjs)$/,
include: r("src/sw.ts"),
loader: 'ts-loader',
options: {
experimentalWatchApi: true,
configFile: r("tsconfig.sw.json"),
},
},
{
test: /\.css$/,
include: r('src'),
use: [
MiniCssExtractPlugin.loader,
'css-loader',
],
},
{
test: /\.(?:svg|png|webmanifest|ico)$/,
include: r('src'),
loader: 'file-loader',
options: {
esModule: false,
}
},
]
},
resolve: {
extensions: ['.js', '.json', '.mjs', '.ts', '.tsx', '.css'],
alias: {
'react': 'preact/compat',
'react-dom': 'preact/compat',
},
},
plugins: [
// new ForkTsCheckerWebpackPlugin({
// async: true,
// watch: r("/src"),
// tsconfig: r("tsconfig.json"),
// }),
new ServiceWorkerWebpackPlugin({
entry: r("src/sw.ts"),
}),
new webpack.EnvironmentPlugin({
...process.env,
VERSION,
BUILD_TIMESTAMP: +new Date(),
}),
new MiniCssExtractPlugin({
filename: isProduction ? "[id].[hash].css" : "[name].css",
}),
new HtmlWebpackPlugin({
template: r("src/index.html"),
})
]
}