/
webpack.node.cjs
65 lines (56 loc) · 1.48 KB
/
webpack.node.cjs
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
const path = require('path');
const nodeExternals = require('webpack-node-externals');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const devMode = (process.env.NODE_ENV !== 'production');
// This helper function is not strictly necessary.
// I just don't like repeating the path.join a dozen times.
function srcPath(subdir) {
return path.join(__dirname, 'src', subdir);
}
module.exports = {
// https://webpack.js.org/configuration/target/
// - default "web"
target: 'node',
mode: process.env.NODE_ENV || 'development',
entry: {
app: [path.resolve(__dirname, 'src/node/index.ts')],
},
output: {
path: path.resolve(__dirname, 'bin'),
filename: 'app.js',
pathinfo: true,
},
devtool: devMode ? 'inline-source-map' : false,
resolve: {
extensions: ['.tsx', '.ts', '.js'],
alias: {
'@main': srcPath('main'),
'@test': srcPath('test'),
'@images': srcPath('site/images'),
},
},
module: {
rules: [
// {
// test: /\.ts$/,
// enforce: 'pre',
// loader: 'tslint-loader',
// },
{
// Include ts, tsx, js, and jsx files.
test: /\.(ts|js)x?$/,
exclude: /node_modules/,
loader: 'babel-loader',
},
],
},
plugins: [
// clean folders
new CleanWebpackPlugin(),
],
stats: {
colors: true,
},
// https://webpack.js.org/configuration/externals/
externals: [nodeExternals()],
};