-
Notifications
You must be signed in to change notification settings - Fork 4
/
webpack.config.cjs
54 lines (53 loc) · 2.14 KB
/
webpack.config.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
const path = require('node:path');
module.exports = {
mode: 'development', // "production" | "development" - Chosen mode tells webpack to use its built-in optimizations accordingly. Production will result in less readable output
entry: {
main: './src/main.ts',
},
externalsPresets: {
node: true, // don't try to include node buildins
},
resolve: {
extensions: ['.js', '.json', '.ts'], // list of file extensions you want to allow into the bundle
extensionAlias: {
'.js': ['.js', '.ts'],
},
},
output: {
libraryTarget: 'commonjs2', // only supported module type for node
path: path.join(__dirname, 'dist'), // what folder to output compile bundle to
filename: '[name].cjs', // name of the main bundle entry point
},
optimization: {
concatenateModules: true, // concatenate multiple modules into a single one
emitOnErrors: true, // emit output files even if there are build errors
nodeEnv: 'production', // value of process.env.NODE_ENV inside of modules
usedExports: true, // determine which exports are used by modules and remove the unused ones
sideEffects: true, // skip modules that are side effect free when using reexports
},
target: 'node', // replace module requires with syntax to work in node
stats: 'minimal', // tells webpack to show a summary of what files it created
devtool: false, // tells webpack to create source maps, set to false if you're only using the compiled code in stuff that doesn't support source maps (eg a lambda or a docker container)
cache: true, // disable/enable caching - might want to turn this off for smaller projects where it's already fast
performance: {
hints: 'warning', // error if the bundle gets huge
maxAssetSize: 1e7, // 10 MB, AWS console size limit
},
module: {
// this block defines rules for how we process different file types in different locations
rules: [
{
// Include ts and js files for this loader
test: /\.(ts|js)$/,
use: [
{
loader: 'ts-loader',
options: {
transpileOnly: true,
},
},
],
},
],
},
};