forked from pnp/pnpjs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
86 lines (73 loc) · 2.52 KB
/
rollup.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
const getSubDirNames = require("./tools/node-utils/getSubDirectoryNames"),
sourcemaps = require("rollup-plugin-sourcemaps"),
uglify = require("rollup-plugin-uglify"),
globals = require("rollup-plugin-node-globals"),
nodeResolve = require("rollup-plugin-node-resolve"),
banner = require("./banner");
const packageSources = getSubDirNames("./build/packages/");
const packageSourcesEs5 = getSubDirNames("./build/packages-es5/");
const libraryNameGen = (name) => name === "pnpjs" ? "pnp" : `pnp.${name}`;
const globalPackageRefs = packageSources.reduce((o, c) => {
o[`@pnp/${c}`] = libraryNameGen(c);
return o;
}, {});
const sharedPlugins = [
sourcemaps(),
globals(),
nodeResolve({
only: ["tslib"],
}),
];
const externals = packageSources.map(c => `@pnp/${c}`).concat(["adal-angular/dist/adal.min.js", "adal-node"]);
const es2015ConfigGen = (moduleName) => Object.assign({}, {
input: `./build/packages/${moduleName}/index.js`,
plugins: [...sharedPlugins],
external: externals,
output: {
file: `./dist/packages/${moduleName}/dist/${moduleName}.js`,
format: "es",
sourcemap: true,
banner,
}
});
const es5ConfigGen = (moduleName) => Object.assign({}, {
input: `./build/packages-es5/${moduleName}/index.js`,
plugins: [...sharedPlugins],
external: externals,
output: [{
file: `./dist/packages/${moduleName}/dist/${moduleName}.es5.umd.js`,
format: "umd",
name: libraryNameGen(moduleName),
sourcemap: true,
globals: globalPackageRefs,
banner,
},
{
file: `./dist/packages/${moduleName}/dist/${moduleName}.es5.js`,
format: "es",
sourcemap: true,
banner,
}]
});
const es5MinConfigGen = (moduleName) => Object.assign({}, {
input: `./build/packages-es5/${moduleName}/index.js`,
plugins: [...sharedPlugins, uglify.uglify({
output: {
comments: (node, comment) => comment.type === "comment2" ? /@license/i.test(comment.value) : false,
}
})],
external: externals,
output: [{
file: `./dist/packages/${moduleName}/dist/${moduleName}.es5.umd.min.js`,
format: "umd",
name: libraryNameGen(moduleName),
sourcemap: true,
globals: globalPackageRefs,
banner,
}]
});
module.exports = [
...packageSources.map(pkgName => es2015ConfigGen(pkgName)),
...packageSourcesEs5.map(pkgName => es5ConfigGen(pkgName)),
...packageSourcesEs5.map(pkgName => es5MinConfigGen(pkgName))
];