This repository was archived by the owner on Oct 30, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.ts
More file actions
118 lines (106 loc) · 2.78 KB
/
webpack.config.ts
File metadata and controls
118 lines (106 loc) · 2.78 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
118
/* eslint-disable @typescript-eslint/no-non-null-assertion */
import CopyWebpackPlugin from 'copy-webpack-plugin';
import ForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin';
import HtmlWebpackPlugin from 'html-webpack-plugin';
import path from 'path';
import TerserPlugin from 'terser-webpack-plugin';
import type { Configuration } from 'webpack';
import FaviconsWebpackPlugin from 'favicons-webpack-plugin';
import 'webpack-dev-server';
const config = (): Configuration => {
const mode =
process.env.NODE_ENV == 'production' ? 'production' : 'development';
const devMode = mode == 'development';
const babelLoader = {
loader: 'babel-loader',
options: {
presets: ['@babel/env'],
plugins: ['@babel/plugin-transform-runtime'],
},
};
const tsLoader = {
loader: 'ts-loader',
options: { transpileOnly: true },
};
const baseConfig: Configuration = {
entry: './src/index.tsx',
mode: mode,
module: {
rules: [
{
test: /\.(ts|js)x?$/,
exclude: /node_modules/,
use: [babelLoader, tsLoader],
},
],
},
output: {
path: path.resolve(__dirname, 'dist'),
publicPath: '/',
},
plugins: [
new CopyWebpackPlugin({
patterns: [{ from: './public' }],
}),
new ForkTsCheckerWebpackPlugin({
async: false,
eslint: { files: './**/*.{ts,tsx,js,jsx}' },
}),
new HtmlWebpackPlugin({ template: 'index.html' }),
new FaviconsWebpackPlugin({
logo: './assets/logo.png',
prefix: 'static/favicons',
outputPath: 'static/favicons',
cache: true,
favicons: {
appName: 'Utilly',
appDescription: 'The tool for the job',
developerName: 'jtsshieh',
developerURL: null, // prevent retrieving from the nearest package.json
background: '#ddd',
theme_color: '#007aff',
},
}),
],
resolve: {
extensions: ['.tsx', '.ts', '.js'],
},
};
if (devMode) {
baseConfig.devServer = {
contentBase: path.join(__dirname, 'public'),
compress: true,
port: 4000,
historyApiFallback: true,
};
baseConfig.devtool = 'cheap-module-eval-source-map';
baseConfig.output!.filename = 'static/js/[name].js';
baseConfig.resolve!.alias = {
'react-dom$': 'react-dom/profiling',
'scheduler/tracing': 'scheduler/tracing-profiling',
};
} else {
baseConfig.devtool = 'source-map';
baseConfig.optimization = {
minimize: !devMode,
minimizer: [new TerserPlugin({ sourceMap: true })],
splitChunks: {
chunks: 'all',
},
runtimeChunk: true,
};
baseConfig.output!.filename = 'static/js/[name].[contenthash].js';
}
const fileLoader = {
loader: 'file-loader',
options: {
name: 'static/assets/[name].[ext]?[contenthash]',
},
};
baseConfig.module?.rules?.push({
test: /\.(jpg|png|gif|svg|pdf|ico)$/,
use: [fileLoader],
});
return baseConfig;
};
export default config;