-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.config.ts
147 lines (125 loc) · 3.38 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
// Copyright (c) 2019-2020 FIUBioRG
// SPDX-License-Identifier: MIT
// eslint-disable unicorn/prefer-optional-catch-binding, unicorn/prefer-module, unicorn/prefer-optional-catch-binding
import { join } from 'node:path';
import {
CustomWebpackBrowserSchema,
TargetOptions
} from '@angular-builders/custom-webpack';
import {
Configuration,
DefinePlugin,
IgnorePlugin,
ProvidePlugin
} from 'webpack';
// @ts-ignore
import * as WebpackAssetsManifest from 'webpack-assets-manifest';
const nodeExternals = require('webpack-node-externals');
const SriPlugin = require('webpack-subresource-integrity');
const PurgeCSSPlugin = require('purgecss-webpack-plugin');
const glob = require('glob');
const DotenvPlugin = require('dotenv-webpack');
import * as pkg from './package.json';
import e from 'express';
const HASHES = ['sha256', 'sha384'];
export default (
config: Configuration,
_options: CustomWebpackBrowserSchema,
targetOptions: TargetOptions
) => {
config.target = 'web';
config.output!.crossOriginLoading = 'anonymous';
config.watchOptions = {
ignored: ['**/node_modules'],
poll: 1000
};
config.plugins!.push(
new DotenvPlugin({
safe: false,
systemvars: true,
}),
new DefinePlugin({
APP_VERSION: pkg.version
})
);
if (targetOptions.target === 'browser') {
config.module!.rules!.push({
test: /\.md$/,
use: ['html-loader', 'markdown-loader']
});
if (process.env.ENV === 'production') {
config.plugins!.push(
new PurgeCSSPlugin({
paths: glob.sync(`${join(__dirname, 'src')}**/*.html`, {
nodir: true
})
}),
new SriPlugin({
enabled: process.env.ENV === 'production',
hashFuncNames: HASHES
})
);
}
}
if (targetOptions.target === 'server') {
config.target = 'node';
config.resolve!.extensions!.push(
'.mjs',
'.graphql',
'.gql',
'.node',
'.prisma'
);
config.resolve!.fallback = {
querystring: require.resolve('querystring')
};
config.module!.rules!.push({
test: /\.mjs$/,
include: /node_modules/,
type: 'javascript/auto'
});
(config.externals as Array<any>).push(
nodeExternals({
allowlist: [/^(?!(livereload|concurrently|fsevents)).*/]
})
);
config.plugins!.push(
new IgnorePlugin({
checkResource(resource: string): boolean {
const imports = [
'@nestjs/microservices',
'@nestjs/microservices/microservices-module',
'@nestjs/websockets/socket-module',
'apollo-server-fastify',
'cache-manager',
'class-validator',
'class-transformer',
'ts-morph',
'supertest',
'formidable',
'class-transformer/storage',
'fsevents',
'bufferutil',
'utf-8-validate',
'react',
'ssh2',
'node-gyp',
'@ts-morph/common',
'@apollo/federation'
];
if (!imports.includes(resource)) {
return false;
}
try {
require.resolve(resource);
// eslint-disable-next-line unicorn/prefer-optional-catch-binding
} catch (error) {
return true;
}
return false;
}
})
);
}
return config;
};