-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebpack.ts
69 lines (60 loc) · 1.66 KB
/
webpack.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 path from 'path';
import type { Configuration, StatsOptions } from 'webpack';
import { webpack } from 'webpack';
import { createWebpackConfig } from './createWebpackConfig';
import { getPackages } from './packages';
enum WebpackBuilds {
BUILD = 'build',
SERVE = 'serve',
}
type WebpackBuildOptions = {
[key in WebpackBuilds]: Configuration;
};
function getWebpackConfigs(): WebpackBuildOptions {
const outputDir = path.resolve('./out');
const sourceDir = path.resolve('./src');
const packages = getPackages(sourceDir);
const defaultStats: StatsOptions = {
all: false,
errors: true,
warnings: true,
timings: true,
};
const watchOptions = {
aggregateTimeout: 600,
ignored: ['/node_modules/', '/tooling/', '/lib'],
};
return {
[WebpackBuilds.BUILD]: createWebpackConfig({
entryPoints: packages,
outputDir: outputDir,
suffix: '.package',
additionalConfiguration: {
devtool: 'source-map',
stats: { ...defaultStats, chunks: true },
},
serve: false,
root: ['bitmovin', 'playerx', '[name]'],
}),
[WebpackBuilds.SERVE]: createWebpackConfig({
entryPoints: packages,
outputDir: outputDir,
suffix: '.package',
additionalConfiguration: {
devtool: 'source-map',
stats: defaultStats,
watch: true,
watchOptions,
},
serve: true,
root: ['bitmovin', 'playerx', '[name]'],
}),
};
}
const target = ((process.env.TARGET as WebpackBuilds) || WebpackBuilds.BUILD).trim();
const webpackConfig = getWebpackConfigs()[target];
webpack(webpackConfig, (err, _stats) => {
if (err) {
console.error(err);
}
});