-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebpack.config.mjs
91 lines (88 loc) · 3.34 KB
/
webpack.config.mjs
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
// @todo: https://github.com/webpack/webpack/issues/2933#issuecomment-774253975
import { createRequire } from 'module';
import { resolve } from 'path';
import { utilitas } from './index.mjs';
import NodePolyfillPlugin from 'node-polyfill-webpack-plugin';
import webpack from 'webpack';
const { __dirname } = utilitas.__(import.meta.url);
const require = createRequire(import.meta.url);
export default {
entry: './index.mjs',
experiments: { topLevelAwait: true },
mode: 'production',
devtool: 'source-map',
node: { __dirname: false, __filename: false },
optimization: { minimize: true },
plugins: [
new NodePolyfillPlugin(),
new webpack.ProvidePlugin({ Buffer: ['buffer', 'Buffer'] }),
new webpack.ProvidePlugin({ process: 'process/browser.js' }),
new webpack.NormalModuleReplacementPlugin(/node:/, (resource) => {
const mod = resource.request.replace(/^node:/, '');
switch (mod) {
case 'buffer': resource.request = 'buffer'; break;
case 'stream': resource.request = 'stream-browserify'; break; // readable-stream
case 'stream/web': resource.request = 'stream-browserify'; break; // readable-stream
case 'url': resource.request = 'url'; break;
default: throw new Error(`Not found ${mod}`);
}
}),
],
target: ['web'],
output: {
asyncChunks: false,
filename: 'utilitas.lite.mjs',
path: resolve(__dirname, 'dist'),
},
resolve: {
extensions: ['.mjs', '.cjs', '.js', '.json', '.node'],
fallback: {
'buffer': require.resolve('buffer/'),
'fs': require.resolve('browserify-fs'),
},
alias: {
'child_process': false,
'crypto': false,
'mathjs': false,
'os': false,
'worker_threads': false,
'file-type': 'file-type/core',
},
},
externals: [
{ './lib/bot.mjs': '{}' },
{ './lib/cache.mjs': '{}' },
{ './lib/callosum.mjs': '{}' },
{ './lib/dbio.mjs': '{}' },
{ './lib/email.mjs': '{}' },
{ './lib/hal.mjs': '{}' },
{ './lib/media.mjs': '{}' },
{ './lib/memory.mjs': '{}' },
{ './lib/network.mjs': '{}' },
{ './lib/sentinel.mjs': '{}' },
{ './lib/shell.mjs': '{}' },
{ './lib/sms.mjs': '{}' },
{ './lib/ssl.mjs': '{}' },
{ './lib/tape.mjs': '{}' },
{ './lib/vision.mjs': '{}' },
{ './lib/web.mjs': '{}' },
// { 'node:buffer': '{}' },
// { 'node:stream': '{}' },
// { 'node:fs': '{}' },
// { 'node:http': '{}' },
// { 'node:https': '{}' },
// { 'node:net': '{}' },
// { 'node:path': '{}' },
// { 'node:process': '{}' },
// { 'node:stream/web': '{}' },
// { 'node:url': '{}' },
// { 'node:util': '{}' },
// { 'node:zlib': '{}' },
],
ignoreWarnings: [warning =>
(warning?.loc?.start?.line === 75 && warning?.loc?.start?.column === 31 && warning?.loc?.end?.line === 75 && warning?.loc?.end?.column === 57) // event
||
(warning?.loc?.start?.line === 752 && warning?.loc?.start?.column === 44 && warning?.loc?.end?.line === 752 && warning?.loc?.end?.column === 56) // utilitas
],
// stats: 'detailed',
};