-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
101 lines (96 loc) · 2.78 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
import { defineConfig } from 'rollup';
import typescript from '@rollup/plugin-typescript';
import { nodeResolve } from '@rollup/plugin-node-resolve';
import terser from '@rollup/plugin-terser';
import virtual from '@rollup/plugin-virtual';
import * as path from 'path';
import dts from 'rollup-plugin-dts';
import gitCommitInfo from 'git-commit-info';
const configuration = process.env.Configuration ?? 'Debug';
const isDebug = configuration !== 'Release';
const isContinuousIntegrationBuild = process.env.ContinuousIntegrationBuild === 'true' ? true : false;
let gitHash = (() => {
try {
const gitInfo = gitCommitInfo();
return gitInfo.hash;
} catch (e) {
return 'unknown';
}
})();
const constants = {
'env:configuration': `export default "${configuration}"`,
'env:gitHash': `export default "${gitHash}"`,
};
const plugins = isDebug ? [] : [terser({
ecma: 2022,
compress: {
defaults: true,
module: true,
ecma: 2022,
toplevel : true,
passes: 4
},
mangle: {
module: true,
toplevel : true,
// TODO properties:{ reserved:['leb128DecodeU64', 'leb128DecodeI64', 'leb128EncodeU64', 'leb128EncodeI64', 'buf', 'memory'] }
},
})];
const banner = '//! Pavel Savara licenses this file to you under the MIT license.\n';
const externalDependencies = ['module', 'fs', 'gitHash'];
const jsco = {
treeshake: !isDebug,
input: './src/index.ts',
output: [
{
format: 'es',
file: 'dist/index.js',
banner,
plugins,
sourcemap: true,
sourcemapPathTransform,
}
],
external: externalDependencies,
plugins: [
virtual(constants),
nodeResolve({
extensions: ['.ts'],
}),
typescript()
]
};
const jscoTypes = {
input: './src/index.ts',
output: [
{
format: 'es',
file: 'dist/index.d.ts',
banner: banner,
}
],
external: externalDependencies,
plugins: [dts()],
};
export default defineConfig([
jsco,
jscoTypes,
]);
const locationCache = {};
function sourcemapPathTransform(relativeSourcePath, sourcemapPath) {
let res = locationCache[relativeSourcePath];
if (res === undefined) {
if (!isContinuousIntegrationBuild) {
const sourcePath = path.resolve(
path.dirname(sourcemapPath),
relativeSourcePath
);
res = `file:///${sourcePath.replace(/\\/g, '/')}`;
} else {
relativeSourcePath = relativeSourcePath.substring(12);
res = `https://raw.githubusercontent.com/pavelsavara/jsco/${gitHash}/${relativeSourcePath}`;
}
locationCache[relativeSourcePath] = res;
}
return res;
}