This repository was archived by the owner on Aug 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathwebpack.cli.config.ts
69 lines (64 loc) · 2 KB
/
webpack.cli.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
import * as t from 'io-ts';
import * as path from 'path';
import { getConfig } from '../../packages/shared/src/webpack/config';
import packageJson from './package.json';
process.env.VERSION = packageJson.version;
const { buildENV: guardoniBuildEnv, ...guardoniConfig } = getConfig({
cwd: __dirname,
outputDir: path.resolve(__dirname, 'build/guardoni'),
env: t.strict({}),
hot: false,
target: 'node16',
entry: {
cli: path.resolve(__dirname, 'src/guardoni/cli.ts'),
},
});
guardoniConfig.module?.rules?.push(
{
// also part of the puppeteer-extra hack
test: /\.js$/,
use: 'unlazy-loader',
},
{
// this is a hack to get webpack to be able to bundle
// puppeteer-extra, found here:
// https://github.com/berstend/puppeteer-extra/issues/93
// this also requires the TypeScript to emit import / export statements
// i.e. ES6+ nodules to work
test: /node_modules\/puppeteer-extra\/dist\/index\.esm\.js/,
loader: 'string-replace-loader',
options: {
// match a require function call where the argument isn't a string
// also capture the first character of the args so we can ignore it later
search: 'require[(]([^\'"])',
// replace the 'require(' with a '__non_webpack_require__(', meaning it will require the files at runtime
// $1 grabs the first capture group from the regex, the one character we matched and don't want to lose
replace: '__non_webpack_require__($1',
flags: 'g',
},
},
{
// this is required by canvas, part of linkedom
test: /\.node$/,
use: 'node-loader',
}
);
// guardoniConfig.externals = {
// puppeteer: "require('puppeteer')",
// 'puppeteer-extra': "require('puppeteer-extra')",
// 'puppeteer-extra-stealth-plugin': 'require("puppeteer-extra-stealth-plugin")',
// };
export default [
// guardoni cli
{
...guardoniConfig,
output: {
...guardoniConfig.output,
libraryTarget: 'commonjs',
},
node: {
__dirname: false,
},
devtool: 'source-map',
},
];