forked from unlight/nest-typescript-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.ts
More file actions
70 lines (67 loc) · 2.42 KB
/
webpack.config.ts
File metadata and controls
70 lines (67 loc) · 2.42 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
/* eslint-disable no-console, import/max-dependencies, tslint/config */
import webpack = require('webpack');
import { Configuration } from 'webpack';
import path = require('path');
import { loader } from 'webpack-loader-helper';
import WebpackNotifierPlugin = require('webpack-notifier');
import nodeExternals = require('webpack-node-externals');
const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');
const pollInterval = 1000;
const defaultOptions = {
test: false,
coverage: false,
prod: process.argv.indexOf('--mode=production') !== -1 || process.argv.indexOf('--env.prod') !== -1,
get dev(): boolean {
return !this.prod;
},
get mode() {
return this.prod ? 'production' : 'development';
},
devtool: 'inline-cheap-module-source-map',
};
type ConfigOptions = Partial<Record<keyof typeof defaultOptions, any>>;
module.exports = (options: ConfigOptions = {}): Configuration => {
options = { ...defaultOptions, ...options };
for (const [key, value] of Object['entries'](options)) {
(value === true) ? process.stdout.write(`${key} `) : (process.stdout.write(value ? `${key}:${value} ` : ''));
}
return {
entry: [`webpack/hot/poll?${pollInterval}`, './src/server.ts'],
target: 'node',
devtool: options.devtool,
output: {
path: `${__dirname}/app_bin`,
filename: 'server.js',
},
mode: options.mode,
resolve: {
extensions: ['.tsx', '.ts', '.js'],
plugins: [
new TsconfigPathsPlugin({}),
],
},
externals: [
nodeExternals({ whitelist: [`webpack/hot/poll?${pollInterval}`] }),
],
module: {
rules: [
{
test: /.tsx?$/,
exclude: /node_modules/,
use: [
loader('ts', { transpileOnly: true, compilerOptions: {} })
]
},
],
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
new webpack.EnvironmentPlugin({
PROGRAM: 'webpack',
NODE_ENV: 'development',
}),
new webpack.BannerPlugin({ banner: 'require("source-map-support").install();', raw: true, entryOnly: false }),
new WebpackNotifierPlugin({ excludeWarnings: true, sound: false }),
],
};
};