generated from esm-bundle/autopublish-template
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.mjs
122 lines (114 loc) · 3.4 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
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 materialPackages = fs
.readdirSync(
path.resolve(__dirname, "node_modules/@angular/material/fesm2020")
)
.filter((filename) => filename.endsWith(".mjs"))
.map((filename) => filename.replace(".mjs", ""))
.map((filename) => {
// `material` is a main entry-point.
const materialPackage =
filename === "material"
? "@angular/material"
: `@angular/material/${filename}`;
return { filename, materialPackage };
});
const packageJson = JSON.parse(
fs
.readFileSync(
path.resolve(__dirname, "node_modules/@angular/material/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,
});
// Construct a list of compilation targets, the list will be the following:
// [
// { ecma: '2015', filename: 'sort', angularPackage: '@angular/material/sort' },
// { ecma: '2020', filename: 'toolbar', angularPackage: '@angular/material/toolbar' },
// ...
// ]
const packages = ["2015", "2020"]
.map((ecma) =>
materialPackages.map(({ filename, materialPackage }) => ({
ecma,
filename,
angularPackage: materialPackage,
}))
)
.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/material/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\/.*/],
};
}