This repository has been archived by the owner on Jul 23, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathwebpack.config.ts
78 lines (72 loc) · 1.77 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
import * as webpack from 'webpack';
import { resolve, join } from 'path';
import * as HtmlWebpackPlugin from 'html-webpack-plugin';
const { HotModuleReplacementPlugin } = webpack;
const port = 3000;
const context = __dirname + '/src';
interface WebpackEnvironment {
NODE_ENV: string;
}
module.exports = (env: WebpackEnvironment, argv: { mode: string }) => {
const appEntryPoints = argv.mode === 'production'
? ['./index']
: [
`webpack-dev-server/client?http://localhost:${port}`,
'webpack/hot/only-dev-server',
'./index'
];
const config: webpack.Configuration = {
name: 'client',
target: 'web',
context,
entry: {
app: appEntryPoints
},
output: {
filename: '[name].js',
path: resolve(__dirname, 'dist')
},
resolve: {
extensions: ['.ts', '.tsx', '.js', 'jsx']
},
devtool: argv.mode === 'production' ? 'source-map' : 'cheap-eval-source-map',
module: {
rules: [
{
enforce: 'pre',
test: /\.tsx?$/,
loader: 'tslint-loader',
exclude: /node_modules/,
options: {
configFile: resolve(__dirname, './tslint.json'),
emitErrors: true,
failOnHint: true,
typeCheck: true
}
},
{
test: /\.tsx?$/,
loader: 'ts-loader',
exclude: /node_modules/
}
]
},
plugins: [
new HtmlWebpackPlugin({
template: './index.html',
hash: true,
filename: 'index.html',
inject: 'body'
}),
new HotModuleReplacementPlugin()
]
};
if (argv.mode === 'development') {
config.devServer = {
contentBase: join(__dirname, 'dist'),
compress: true,
port: 9000
};
}
return config;
};