generated from esm-bundle/autopublish-template
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.mjs
100 lines (94 loc) · 2.65 KB
/
rollup.config.mjs
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
import fs from "fs";
import url from "url";
import path from "path";
import { babel } from "@rollup/plugin-babel";
import { terser } from "rollup-plugin-terser";
import { createEs2015LinkerPlugin } from "@angular/compiler-cli/linker/babel";
import {
ConsoleLogger,
NodeJSFileSystem,
LogLevel,
} from "@angular/compiler-cli";
const __dirname = new url.URL(".", import.meta.url).pathname;
const packageJson = JSON.parse(
fs
.readFileSync(
path.resolve(__dirname, "node_modules/@angular/elements/package.json")
)
.toString()
);
/** File system used by the Angular linker plugin. */
const fileSystem = new NodeJSFileSystem();
/** Logger used by the Angular linker plugin. */
const logger = new ConsoleLogger(LogLevel.info);
/**
* The linker plugin is used to make output files AOT compatible, so they don't
* require the `@angular/compiler` at runtime.
*/
const linkerPlugin = createEs2015LinkerPlugin({
fileSystem,
logger,
linkerJitMode: false,
});
const packages = ["2015", "2020"]
.map((ecma) => [
{
ecma,
angularPackage: "@angular/elements",
filename: "elements",
},
])
.flat();
export default packages
.map(({ ecma, angularPackage, filename }) => [
createConfig({
ecma,
prod: false,
format: "system",
angularPackage,
filename,
}),
createConfig({
ecma,
prod: true,
format: "system",
angularPackage,
filename,
}),
createConfig({ ecma, prod: false, format: "es", angularPackage, filename }),
createConfig({ ecma, prod: true, format: "es", angularPackage, filename }),
])
.flat();
function createConfig({ ecma, prod, format, angularPackage, filename }) {
const dir = (format === "es" ? "." : format) + `/es${ecma}/ivy`;
return {
input: path.join(
__dirname,
`node_modules/@angular/elements/fesm${ecma}/${filename}.mjs`
),
output: {
file: `${dir}/angular-${filename}.${prod ? "min." : ""}js`,
format,
sourcemap: true,
banner: `/* esm-bundle - ${angularPackage}@${packageJson.version} - Ivy - ${format} format - es${ecma} - Use of this source code is governed by an MIT-style license that can be found in the LICENSE file at https://angular.io/license */`,
},
plugins: [
babel({ plugins: [linkerPlugin] }),
prod &&
terser({
format: {
ecma,
comments: /esm-bundle/,
},
compress: {
global_defs: {
ngJitMode: false,
ngDevMode: false,
ngI18nClosureMode: false,
},
},
}),
],
external: ["rxjs", "rxjs/operators", "@angular/core"],
};
}