forked from angular/angular
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup.config.js
90 lines (81 loc) · 2.6 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
87
88
89
90
const node = require('@rollup/plugin-node-resolve').default;
const commonjs = require('@rollup/plugin-commonjs');
const MagicString = require('magic-string');
// Parse the stamp file produced by Bazel from the version control system
let version = '<unknown>';
if (bazel_version_file) {
const versionTag = require('fs')
.readFileSync(bazel_version_file, {encoding: 'utf-8'})
.split('\n')
.find((s) => s.startsWith('STABLE_PROJECT_VERSION'));
// Don't assume STABLE_PROJECT_VERSION exists
if (versionTag) {
version = versionTag.split(' ')[1].trim();
}
}
/** Removed license banners from input files. */
const stripBannerPlugin = {
name: 'strip-license-banner',
transform(code, _filePath) {
const banner = /(\/\**\s+\*\s@license.*?\*\/)/s.exec(code);
if (!banner) {
return;
}
const [bannerContent] = banner;
const magicString = new MagicString(code);
const pos = code.indexOf(bannerContent);
magicString.remove(pos, pos + bannerContent.length).trimStart();
return {
code: magicString.toString(),
map: magicString.generateMap({
hires: true,
}),
};
},
};
// Add 'use strict' to the bundle, https://github.com/angular/angular/pull/40456
// When rollup build esm bundle of zone.js, there will be no 'use strict'
// since all esm bundles are `strict`, but when webpack load the esm bundle,
// because zone.js is a module without export and import, webpack is unable
// to determine the bundle is `esm` module or not, so it doesn't add the 'use strict'
// which webpack does to all other `esm` modules which has export or import.
// And it causes issues such as https://github.com/angular/angular/issues/40215
// `this` should be `undefined` but is assigned with `Window` instead.
const banner = `'use strict';
/**
* @license Angular v${version}
* (c) 2010-2024 Google LLC. https://angular.io/
* License: MIT
*/`;
module.exports = {
external: (id) => {
if (id[0] === '.') {
// Relative paths are always non external.
return false;
}
if (/zone\.js[\\/]lib/.test(id)) {
return false;
}
return /rxjs|electron/.test(id);
},
plugins: [
node({
mainFields: ['es2015', 'module', 'jsnext:main', 'main'],
}),
commonjs(),
stripBannerPlugin,
],
output: {
globals: {
electron: 'electron',
'rxjs/Observable': 'Rx',
'rxjs/Subscriber': 'Rx',
'rxjs/Subscription': 'Rx',
'rxjs/Scheduler': 'Rx.Scheduler',
'rxjs/scheduler/asap': 'Rx.Scheduler',
'rxjs/scheduler/async': 'Rx.Scheduler',
'rxjs/symbol/rxSubscriber': 'Rx.Symbol',
},
banner,
},
};