generated from esm-bundle/autopublish-template
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.mjs
119 lines (112 loc) · 3.17 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
import url from 'node:url';
import path from 'node:path';
import { createRequire } from 'node:module';
import { babel } from '@rollup/plugin-babel';
import terser from '@rollup/plugin-terser';
import { nodeResolve } from '@rollup/plugin-node-resolve';
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 require = createRequire(import.meta.url);
const packageJson = require('single-spa-angular/package.json');
/** 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 = ['2022']
.map((ecma) => [
{
ecma,
angularPackage: 'single-spa-angular/internals',
filename: 'single-spa-angular-internals',
},
{
ecma,
angularPackage: 'single-spa-angular',
filename: 'single-spa-angular',
},
{
ecma,
angularPackage: 'single-spa-angular/elements',
filename: 'single-spa-angular-elements',
},
{
ecma,
angularPackage: 'single-spa-angular/parcel',
filename: 'single-spa-angular-parcel',
},
])
.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}`;
return {
input: path.join(
__dirname,
`node_modules/single-spa-angular/fesm${ecma}/${filename}.mjs`,
),
output: {
file: `${dir}/${filename}.${prod ? 'min.' : ''}js`,
format,
sourcemap: true,
banner: `/* esm-bundle - ${angularPackage}@${packageJson.version} - ${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: [
nodeResolve({ browser: true }),
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',
'@angular/common',
'single-spa-angular/internals',
],
};
}