-
-
Notifications
You must be signed in to change notification settings - Fork 20
/
webpack.config.ts
69 lines (64 loc) · 1.63 KB
/
webpack.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 path from "node:path"
import TerserPlugin from 'terser-webpack-plugin'
import type { Configuration } from "webpack"
import * as glob from "glob"
const LIBRARY_NAME = "Threestrap";
const PATHS = {
entryPoint: path.resolve(__dirname, "src/index.js"),
libraryBundles: path.resolve(__dirname, "build"),
testBundle: path.resolve(__dirname, "build_tests"),
testFiles: glob.sync("./test/**/*.spec.js"),
};
const umdBase = (path: string): Configuration => ({
// The output defines how and where we want the bundles. The special value
// `[name]` in `filename` refers to the keys of `entry`. With a UMD target,
// when including the bundle in a browser, the bundle will be available as
// `window.entryKeyName`.
output: {
path,
filename: "[name].js",
libraryTarget: "umd",
library: LIBRARY_NAME,
umdNamedDefine: true,
},
resolve: {
extensions: [".js"],
},
// Activate source maps for the bundles in order to preserve the original
// source when the user debugs the application
devtool: "source-map",
});
const library: Configuration = {
entry: {
threestrap: [PATHS.entryPoint],
"threestrap.min": [PATHS.entryPoint],
},
externals: {
three: "THREE",
},
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
test: /\.min\.js$/,
}),
],
},
}
const configs: Configuration[] = [
{
...umdBase(PATHS.libraryBundles),
...library,
name: "threestrap",
},
{
...umdBase(PATHS.testBundle),
name: "tests",
mode: "development",
devtool: "eval",
entry: {
tests: PATHS.testFiles
}
}
]
export default configs