-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.ts
94 lines (86 loc) · 2.18 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
import {BannerPlugin, Configuration} from 'webpack';
import {Levels, Log} from '@toreda/log';
import ForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin';
import Path from 'path';
import yargs from 'yargs';
const log = new Log({
consoleEnabled: true,
groupsStartEnabled: true,
globalLevel: Levels.ALL
});
interface BuildCmdArgs {
[k: string]: unknown;
env: string;
profiler: boolean;
}
const argv = yargs(process.argv.slice(2))
.options({
profiler: {
type: 'boolean',
demandOption: false,
default: false,
describe: 'Run profiler with build process'
},
env: {
choices: ['prod', 'dev'],
demandOption: false,
default: 'prod',
describe: 'Target environment build'
}
})
.showHelpOnFail(true).argv as BuildCmdArgs;
const isProd = argv.env === 'dev' ? false : true;
log.info(`Webpack Build`);
log.info(`-----------------------------`);
log.info(` build env: ${isProd ? 'prod' : 'dev'}`);
log.info(` profiler: ${argv.profiler === true ? 'enabled' : 'disabled'}`);
const config: Configuration = {
mode: argv.env === 'dev' ? 'development' : 'production',
devtool: isProd ? undefined : 'inline-source-map',
entry: './src/cli.ts',
output: {
/**
* Whether pathinfo is bundled with output. Webpack officially
* recommends disabling this for large codebases due to the GC
* impact for project bundling thousands of modules.
* */
pathinfo: true,
filename: 'cli-app.min.js',
path: Path.join(__dirname, 'dist'),
libraryTarget: 'commonjs',
library: 'app'
},
/** Only extensions listed here will be bundled.
* IMPORTANT: Missing files dont always throw during build and may
* only break when the bundle is loaded.
*/
resolve: {
extensions: ['.ts', '.tsx', '.js']
},
externals: [],
module: {
rules: [
{
// Include ts, tsx, js, and jsx files.
test: /\.(ts|js)x?$/,
use: {
loader: 'esbuild-loader',
options: {
loader: 'tsx',
target: 'esnext',
jsx: 'automatic'
}
}
}
]
},
target: 'node',
plugins: [new BannerPlugin({banner: '#!/usr/bin/env node', raw: true}), new ForkTsCheckerWebpackPlugin()],
externalsPresets: {
node: true
},
node: {
global: false
}
};
export default config;