Repository navigation
Expand file tree
/
Copy pathwebpack.config.js
More file actions
118 lines (113 loc) · 2.89 KB
/
Copy pathwebpack.config.js
File metadata and controls
118 lines (113 loc) · 2.89 KB
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/* eslint-disable no-undef*/
const path = require("path");
const webpack = require("webpack");
const { merge } = require("webpack-merge");
const pkg = require("./package.json");
const ESLintPlugin = require("eslint-webpack-plugin");
const TerserPlugin = require('terser-webpack-plugin');
const { getBuildInfo } = require('./scripts/build-info.cjs');
base_config = {
target: "web",
output: {
path: path.resolve(__dirname, "build"),
},
experiments: {
outputModule: true, // Required for ES modules
},
resolve: {
extensions: [".ts", ".tsx", ".js", ".json"],
},
module: {
rules: [
{ test: /\.tsx?$/, loader: "ts-loader" },
{ test: /\.frag$/, loader: "raw-loader" },
{ test: /\.vert$/, loader: "raw-loader" },
],
},
plugins: [
new webpack.ProvidePlugin({
MMTF: path.resolve(__dirname, "./src/vendor/mmtf.js"),
$: "jquery",
}),
new ESLintPlugin({ exclude: ["node_modules"] }),
],
stats: {
errorDetails: true,
},
};
umd_config = {
entry: {
"3Dmol": ["./src/index.ts", "./src/SurfaceWorker.js", "./src/exporter.js"],
"3Dmol.ui": ["./src/ui/index.ts"],
},
output: {
library: "[name]",
libraryTarget: "umd",
globalObject: "this",
},
};
es6_config = {
entry: {
"3Dmol.es6": ["./src/3Dmol.ts"],
},
output: {
libraryTarget: "module",
},
}
env_config = {
development: {
mode: "development",
devtool: "inline-source-map",
output: {
filename: "[name].js",
},
},
production: {
mode: "production",
optimization: {
usedExports: false,
minimizer: [
new TerserPlugin({
parallel: true,
terserOptions: {
keep_classnames: true,
compress: true,
// Classic scripts inherit the host page's encoding when none is
// supplied. Escapes keep UI text intact in local/legacy pages.
format: { ascii_only: true },
mangle: {
reserved: ["MarchingCube"],
},
},
}),
],
},
output: {
filename: `[name]-min.js`,
},
},
};
module.exports = function (env, argv) {
const buildInfo = getBuildInfo(__dirname, pkg.version);
const banner = `${pkg.name} v${buildInfo.version}
Git: ${buildInfo.gitDescribe || 'unavailable'}
Commit: ${buildInfo.commit || 'unavailable'}
${pkg.description}
Author: ${pkg.author}`;
const build_config = {
plugins: [
new webpack.DefinePlugin({
__3DMOL_BUILD_INFO__: JSON.stringify(buildInfo),
}),
new webpack.BannerPlugin({
banner,
// Retain the banner after minification, before source maps are generated.
stage: webpack.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_SIZE + 1,
}),
],
};
return [
merge(base_config, umd_config, env_config[argv["mode"]], build_config),
merge(base_config, es6_config, env_config[argv["mode"]], build_config),
];
};