-
-
Notifications
You must be signed in to change notification settings - Fork 172
/
webpack.config.js
102 lines (98 loc) · 2.41 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
96
97
98
99
100
101
102
// @ts-check
"use strict";
/* eslint-disable n/no-unpublished-require */
const webpack = require("webpack");
const TerserPlugin = require("terser-webpack-plugin");
const nodeModulePrefixRe = /^node:/u;
const baseConfig = {
"target": "node",
"entry": "./extension.js",
"module": {
"rules": [
{
"test": /markdownlint-cli2.js$/
}
]
},
"output": {
"asyncChunks": false,
"path": __dirname,
"filename": "bundle.js",
"libraryTarget": "commonjs2"
},
"optimization": {
// "minimize": false,
// "moduleIds": "named",
"minimizer": [ new TerserPlugin({ "extractComments": false }) ]
},
"externals": {
"vscode": "commonjs vscode"
},
"plugins": [
// Rewrite requires to remove "node:" prefix
new webpack.NormalModuleReplacementPlugin(
nodeModulePrefixRe,
(resource) => {
const module = resource.request.replace(nodeModulePrefixRe, "");
resource.request = module;
}
)
],
"ignoreWarnings": [
{
"message": /(asset|entrypoint) size limit/
},
{
"message": /dependencies cannot be statically extracted/
},
{
"message": /lazy load some parts of your application/
}
]
};
const config = [
baseConfig,
{
...baseConfig,
"target": "webworker",
"output": {
...baseConfig.output,
"filename": "bundle.web.js",
"libraryTarget": "commonjs"
},
"plugins": [
...baseConfig.plugins,
// Intercept "node:stream/promises" lacking a browserify entry
new webpack.NormalModuleReplacementPlugin(
/^stream\/promises$/u,
(resource) => {
resource.request = require.resolve("./webworker/stream-promises.js");
}
),
// Intercept existing "unicorn-magic" package to provide missing import
new webpack.NormalModuleReplacementPlugin(
/^unicorn-magic$/u,
(resource) => {
resource.request = require.resolve("./webworker/unicorn-magic-stub.js");
}
),
// Intercept use of "process" to provide implementation
new webpack.ProvidePlugin({
"process": "process-wrapper"
})
],
"resolve": {
"fallback": {
"fs": false,
"os": require.resolve("./webworker/os-stub.js"),
"path": require.resolve("path-browserify"),
"process": require.resolve("./webworker/process-stub.js"),
"process-wrapper": require.resolve("./webworker/process-stub.js"),
"stream": require.resolve("stream-browserify"),
"url": require.resolve("./webworker/url-stub.js"),
"util": require.resolve("util")
}
}
}
];
module.exports = config;