-
Notifications
You must be signed in to change notification settings - Fork 101
/
Copy pathwebpack.config.js
95 lines (85 loc) · 2.13 KB
/
webpack.config.js
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
95
// External modules
require('dotenv').config();
const path = require('path');
const chalk = require('chalk');
// Webpack plugin modules
const DotEnvPlugin = require('dotenv-webpack');
const NodemonPlugin = require('nodemon-webpack-plugin');
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
// Environment config
const isDevelopment = process.env.NODE_ENV === 'development';
const mode = isDevelopment ? 'development' : 'production';
console.log(chalk.blue.bold(`Webpack bundling for ${mode} environment`));
// Bundle config options
const BUNDLE = {
entry: './index.ts',
output: {
filename: 'app.js',
path: path.resolve(__dirname, 'build')
}
};
module.exports = {
mode,
target: 'node',
entry: BUNDLE.entry,
stats: 'errors-only',
node: {
__dirname: true,
__filename: true
},
module: getLoaders(),
plugins: getPlugins(),
resolve: {
extensions: ['.tsx', '.ts', '.js', '.json'],
alias: {
'@backend/config': path.resolve(__dirname, 'config'),
'@backend/graphql': path.resolve(__dirname, 'packages/graphql'),
'@backend/utils': path.resolve(__dirname, 'packages/utils'),
'@backend/db': path.resolve(__dirname, 'packages/db'),
graphql$: path.resolve(__dirname, 'node_modules/graphql/index.js')
}
},
output: BUNDLE.output
};
/**
* Loaders used by the application.
*/
function getLoaders() {
const graphql = {
test: /\.(graphql|gql)$/,
exclude: /node_modules/,
loader: 'graphql-tag/loader'
};
const esbuild = {
test: /\.(js|jsx|ts|tsx)?$/,
loader: 'esbuild-loader',
options: {
loader: 'tsx',
target: 'es2015'
},
exclude: /node_modules/
};
const loaders = {
rules: [graphql, esbuild]
};
return loaders;
}
/**
* Plugins
*/
function getPlugins() {
const dotEnv = new DotEnvPlugin();
const nodemon = new NodemonPlugin();
const typescriptChecker = new ForkTsCheckerWebpackPlugin({
async: true,
typescript: {
memoryLimit: 8192,
diagnosticOptions: {
semantic: true,
syntactic: true
}
}
});
// Order matters!
return [dotEnv, typescriptChecker, nodemon];
}