forked from tradingview/lightweight-charts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
81 lines (71 loc) · 2.22 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
const terser = require('rollup-plugin-terser').terser;
const nodeResolve = require('@rollup/plugin-node-resolve').default;
const replace = require('@rollup/plugin-replace');
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();
function getConfig(inputFile, type, isProd) {
const isModular = type === 'module';
const suffix = isModular ? 'esm' : 'standalone';
const mode = isProd ? 'production' : 'development';
const config = {
input: inputFile,
output: {
format: isModular ? 'esm' : 'iife',
file: `./dist/lightweight-charts.${suffix}.${mode}.js`,
banner: `
/*!
* @license
* TradingView Lightweight Charts v${currentVersion}
* Copyright (c) 2020 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: (type === 'module'),
properties: {
regex: /^_(private|internal)_/,
},
},
}),
],
external: id => isModular && /^fancy-canvas(\/.+)?$/.test(id),
};
return config;
}
const configs = [
getConfig('./lib/prod/src/index.js', 'module', false),
getConfig('./lib/prod/src/standalone.js', 'standalone', false),
];
if (process.env.NODE_ENV === 'production') {
configs.push(
getConfig('./lib/prod/src/index.js', 'module', true),
getConfig('./lib/prod/src/standalone.js', 'standalone', true)
);
}
// eslint-disable-next-line no-console
console.log(`Building version: ${currentVersion}`);
module.exports = configs;