-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.ts
More file actions
69 lines (57 loc) · 1.54 KB
/
webpack.config.ts
File metadata and controls
69 lines (57 loc) · 1.54 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
import * as path from 'path'
import { argv } from 'process'
import { BannerPlugin, Configuration } from 'webpack'
import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer'
const srcPath = (subdir: string) => path.join(__dirname, 'src', subdir)
const mode =
argv[argv.indexOf('--mode') + 1] === 'development'
? 'development'
: 'production'
console.log(mode)
const analyze = process.env.ANALYZE !== undefined ?? false
const bundleName =
mode === 'development' ? 'bars-dev' : analyze ? 'bars-analyze' : 'bars'
const config: Configuration = {
target: 'node',
mode,
entry: './src/index.ts',
output: {
path: path.resolve(__dirname, mode === 'development' ? 'build' : 'dist'),
filename: `${bundleName}.js`,
},
plugins: [
new BannerPlugin({
banner: '#!/usr/bin/env node',
raw: !analyze,
}),
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
new BundleAnalyzerPlugin({
analyzerMode: analyze ? 'server' : 'disabled',
}),
],
module: {
rules: [
{
test: /\.js$/,
use: 'babel-loader',
exclude: /node_modules/,
},
{
test: /\.ts(x)?$/,
loader: 'ts-loader',
exclude: /node_modules/,
},
],
},
devtool: mode === 'development' ? 'source-map' : undefined,
externals: ['utf-8-validate', 'bufferutil', 'react-devtools-core'],
resolve: {
extensions: ['.tsx', '.ts', '.js'],
alias: {
'@lib': srcPath('lib'),
'@type': srcPath('types'),
},
},
}
export default config