-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
rollup.config.js
102 lines (92 loc) · 2.51 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
91
92
93
94
95
96
97
98
99
100
101
102
const nodeResolve = require('@rollup/plugin-node-resolve').default;
const replace = require('@rollup/plugin-replace');
const terser = require('@rollup/plugin-terser').default;
const packageJson = require('./package.json');
function getDevBuildMetadata() {
const now = new Date();
return now.toISOString().replace(/:\d+\..+/g, '').replace(/[-T:]/g, '');
}
function getCurrentVersion() {
const isDev = process.env.BUILD_TAG !== 'release';
return `${packageJson.version}` + (isDev ? `-dev+${getDevBuildMetadata()}` : '');
}
const currentVersion = getCurrentVersion();
const year = new Date().getFullYear();
function getConfig(
inputFile,
{ format, isProd, isStandalone }
) {
const mode = isProd ? 'production' : 'development';
const extension = {
cjs: 'cjs',
esm: 'mjs',
iife: 'js',
}[format];
const config = {
input: inputFile,
output: {
format,
file: `./dist/lightweight-charts${isStandalone ? '.standalone' : ''}.${mode}.${extension}`,
banner: `
/*!
* @license
* TradingView Lightweight Charts™ v${currentVersion}
* Copyright (c) ${year} TradingView, Inc.
* Licensed under Apache License 2.0 https://www.apache.org/licenses/LICENSE-2.0
*/`.trim(),
},
plugins: [
nodeResolve(),
replace({
preventAssignment: true,
values: {
// make sure that this values are synced with src/typings/globals/index.d.ts
'process.env.NODE_ENV': JSON.stringify(
isProd ? 'production' : 'development'
),
'process.env.BUILD_VERSION': JSON.stringify(currentVersion),
},
}),
isProd &&
terser({
output: {
comments: /@license/,
// eslint-disable-next-line camelcase
inline_script: true,
},
mangle: {
module: format === 'esm' || format === 'cjs',
properties: {
regex: /^_(private|internal)_/,
},
},
}),
],
external: id => !isStandalone && /^fancy-canvas(\/.+)?$/.test(id),
};
return config;
}
const modes = [false];
if (process.env.NODE_ENV === 'production') {
modes.push(true);
}
const configs = [];
modes.forEach(mode => {
configs.push(
getConfig('./lib/prod/src/index.js', { format: 'esm', isProd: mode }),
getConfig('./lib/prod/src/index.js', {
format: 'esm',
isProd: mode,
isStandalone: true,
}),
getConfig('./lib/prod/src/index.js', { format: 'cjs', isProd: mode }),
getConfig('./lib/prod/src/standalone.js', {
format: 'iife',
isProd: mode,
isStandalone: true,
})
);
});
// eslint-disable-next-line no-console
console.log(`Building version: ${currentVersion}`);
module.exports = configs;