forked from pnp/pnpjs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
65 lines (58 loc) · 2.23 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
/**
* This webpack configuration file will create all of the bundles for each project.
* It expects that everything is built prior to bundling. (gulp build)
*/
const path = require("path"),
getSubDirNames = require("./tools/node-utils/getSubDirectoryNames"),
publishConfig = require("./pnp-publish"),
banner = require("./banner"),
webpack = require("webpack");
// static values
// we always bundle the es5 output
const buildOutputRoot = "./build/packages-es5/";
// get all the packages, but filter nodejs & documentation as we don't bundle that as it is never used in the browser
const packageSources = getSubDirNames(buildOutputRoot).filter(name => name !== "nodejs" && name !== "documentation");
const getDistFolder = (name) => path.join(publishConfig.packageRoot, name);
const libraryNameGen = (name) => name === "pnpjs" ? "pnp" : `pnp.${name}`;
// this is a config stub used to init the build configs.
const common = {
cache: true,
devtool: "source-map",
resolve: {
alias: {},
},
plugins: [
new webpack.BannerPlugin({
banner,
raw: true,
}),
]
};
// we need to setup the alias values for the local packages for bundling
for (let i = 0; i < packageSources.length; i++) {
common.resolve.alias[`@pnp/${packageSources[i]}`] = path.resolve(buildOutputRoot, packageSources[i]);
}
const bundleTemplate = (name, targetFolder) => Object.assign({}, common, {
mode: "development",
entry: path.resolve(buildOutputRoot, `${name}/index.js`),
output: {
filename: `${name}.es5.umd.bundle.js`,
library: libraryNameGen(name),
libraryTarget: "umd",
path: path.join(targetFolder, "dist"),
},
});
const bundleTemplateMin = (name, targetFolder) => Object.assign({}, common, {
mode: "production",
entry: path.resolve(buildOutputRoot, `${name}/index.js`),
output: {
filename: `${name}.es5.umd.bundle.min.js`,
library: libraryNameGen(name),
libraryTarget: "umd",
path: path.join(targetFolder, "dist"),
},
});
module.exports = [
...packageSources.map(pkgName => bundleTemplate(pkgName, getDistFolder(pkgName))),
...packageSources.map(pkgName => bundleTemplateMin(pkgName, getDistFolder(pkgName)))
];