-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.config.cjs
72 lines (65 loc) · 1.81 KB
/
webpack.config.cjs
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
const path = require('path')
module.exports = async (env) => {
if (!env.ROOT) throw new Error(`Missing ROOT`)
const frameworkDir = path.relative(env.ROOT, path.resolve('@companion-module/base'))
const pkgJson = require(path.join(env.ROOT, 'package.json'))
if (!pkgJson.main) throw new Error(`Missing main in package.json`)
let webpackExt = {}
try {
webpackExt = require(path.join(env.ROOT, 'build-config.cjs'))
console.log('Found additional webpack configuration')
} catch (e) {
// Ignore
}
let externalsExt = []
if (Array.isArray(webpackExt.externals)) externalsExt = webpackExt.externals
else if (webpackExt.externals) externalsExt = [webpackExt.externals]
return {
entry: {
main: './' + pkgJson.main, // path.join(frameworkDir, 'dist/entrypoint.js'),
// Allow for custom entrypoints
...webpackExt.entry,
},
mode: env.dev ? 'development' : 'production',
// devtool: env.dev ? undefined : 'source-map', // TODO - this would be nice, but I think the files have to be uploaded directly to sentry which is problematic...
output: {
path: path.resolve(env.ROOT, 'pkg'),
},
context: path.resolve(env.ROOT, '.'),
target: 'node',
externals: [
// Allow for custom externals
...externalsExt,
],
experiments: {
topLevelAwait: true,
},
optimization: {
minimize: !webpackExt.disableMinifier,
},
module: {
rules: [
// {
// test: /\.json$/,
// type: 'asset/source',
// },
// {
// test: /BUILD$/,
// type: 'asset/resource',
// generator: {
// filename: 'BUILD',
// },
// },
],
},
plugins: [
// Let modules define additional plugins. Hopefully this won't conflict with anything we add
...(webpackExt.plugins || []),
],
node: webpackExt.useOriginalStructureDirname
? {
__dirname: true,
}
: undefined,
}
}