This repository has been archived by the owner on Feb 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwebpack.config.ts
126 lines (115 loc) · 3.04 KB
/
webpack.config.ts
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
119
120
121
122
123
124
125
126
import path from 'path';
import webpack, { Configuration } from 'webpack';
import HtmlWebpackPlugin from 'html-webpack-plugin';
import TerserWebpackPlugin from 'terser-webpack-plugin';
import CompressionWebpackPlugin from 'compression-webpack-plugin';
import ForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin';
/**
* resolve a path relative to the root directory of this project.
*
* @param args the remaining path vars passed to {@code path.resolve}.
*/
function pathResolve(...args: string[]): string {
return path.resolve(__dirname, ...args)
}
const excludes: string[] = [
pathResolve('vendor', 'node'),
pathResolve('node_modules')
]
const sharedConfig: Configuration = {
}
type EnvironmentType = { [key: string]: boolean }
type ConfigurationFunction = (env: String) => webpack.Configuration;
export const statsConfig = {
all: false,
modules: true,
maxModules: 0,
errors: true,
warnings: true,
logging: "warn",
colors: true,
}
let mainConfig: ConfigurationFunction = env => Object.assign({}, sharedConfig, {
entry: ['./client/index', 'webpack-hot-middleware/client?reload=true&quiet=true'],
output: {
path: pathResolve('build'),
filename: '[name].bundle.js',
chunkFilename: '[name].bundle.js',
},
mode: env || 'development',
devtool: (env === "production") ? false : "inline-source-map",
performance: {
hints: false
},
resolve: {
extensions: ['.ts', '.tsx', '.js', '.jsx', '.scss'],
alias: {
// use this to access from root of src hirearchy.
'@client': pathResolve('client'),
'@styles': pathResolve('client/styles'),
'@cstyles': pathResolve('client/styles/components'),
'@server': pathResolve('server'),
'@shared': pathResolve('shared'),
'@transmission': pathResolve('transmission'),
'@tests': pathResolve('tests'),
}
},
optimization: {
minimize: env === "production",
minimizer: [
new TerserWebpackPlugin({
terserOptions: {
output: {
comments: false,
}
},
extractComments: false
}),
new CompressionWebpackPlugin()
]
},
module: {
rules: [
{
test: /\.(ts|js)x?$/,
exclude: /node_modules/,
loader: 'babel-loader',
},
{
test: /\.(s[ca]ss|css)/,
use: [
'style-loader',
'css-loader',
'postcss-loader',
'sass-loader',
]
},
{
test: /\.(woff|woff2|eot|ttf|otf)$/,
loader: 'file-loader',
}
]
},
plugins: [
new ForkTsCheckerWebpackPlugin(),
new webpack.HotModuleReplacementPlugin(),
new HtmlWebpackPlugin({
template: './client/index.html',
minify: {
collapseWhitespace: env === "production",
}
}),
],
});
export default (env: EnvironmentType) => {
let environment: string = ""
if (env && env.production) {
environment = "production"
}
return [mainConfig].map(c => {
if (c instanceof Function) {
return (c as ConfigurationFunction)(environment)
}
return c
})
}