-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
104 lines (97 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
103
104
import webpack from 'webpack';
import { $ } from 'execa';
import { resolve as _resolve } from 'node:path';
const { BannerPlugin } = webpack;
const packages = [
[
'pmm',
{
['v8-compile-cache']: `v8-compile-cache`,
['pmm']: './src/index.ts',
['pmm-cli']: './src/pmm-cli.ts',
},
],
// [
// 'pmm-installer',
// {
// ['v8-compile-cache']: `v8-compile-cache`,
// ['installer']: './src/index.ts',
// },
// ],
];
class PublishLocalPlugin {
/** @type {import("webpack").WebpackPluginFunction} */
apply(compiler) {
compiler.hooks.done.tapPromise(
'PublishLocalPlugin',
async (compilation) => {
await $({
stdio: 'inherit',
cwd: compiler.options.context,
env: {
IS_CHILD_PROCESS: '1',
},
})`./scripts/release-local`.catch((e) => console.error(e));
return undefined;
}
);
}
}
export default (_, { mode = 'production' }) => {
const IS_DEV = mode !== 'production';
const BUILD_WATCH_RELEASE = !!process.env.BUILD_WATCH_RELEASE;
/** @type {import("webpack").Configuration[]} */
return packages.map(([pkgName, entry]) => {
const pkgPath = _resolve(`packages/${pkgName}`);
return {
mode: mode,
context: pkgPath,
target: 'node',
...(IS_DEV
? {
// development options
devtool: 'source-map',
}
: {
// production options
devtool: false,
}),
entry: entry,
output: {
path: _resolve(pkgPath, 'dist'),
libraryTarget: `commonjs`,
clean: true,
},
resolve: {
extensions: [`.ts`, `.js`, '.json'],
},
module: {
noParse: /v8-compile-cache/,
rules: [
{
test: /\.[cm]?(ts|js)$/,
loader: `babel-loader`,
},
],
},
stats: {
assetsSort: `!size`,
},
optimization: {
// webpack was redeclaring a var in the same scope
concatenateModules: false,
},
plugins: [
new BannerPlugin({
entryOnly: true,
banner: `#!/usr/bin/env node\n/* eslint-disable */`,
raw: true,
}),
BUILD_WATCH_RELEASE && new PublishLocalPlugin(),
].filter(Boolean),
watchOptions: {
ignored: ['**/node_modules', '**/package.json', '**/dist'],
},
};
});
};