-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
85 lines (77 loc) · 2.19 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
import path from 'path';
import fs from 'fs';
import { nodeResolve } from '@rollup/plugin-node-resolve';
import typescript from '@rollup/plugin-typescript';
import { babel } from '@rollup/plugin-babel';
import { terser } from 'rollup-plugin-terser';
function getEntryPoints() {
const entries = {};
// Handle src directory
const srcIndex = path.resolve('src/index.ts');
if (fs.existsSync(srcIndex)) {
entries['GA4CustomTask'] = srcIndex;
}
// Handle tasks directory
const tasksDir = path.resolve('tasks');
fs.readdirSync(tasksDir, { withFileTypes: true }).forEach((entry) => {
if (entry.isDirectory()) {
const subDir = path.join(tasksDir, entry.name);
const indexFile = path.join(subDir, 'index.ts');
if (fs.existsSync(indexFile)) {
entries[entry.name] = indexFile;
}
}
});
return entries;
}
const entries = getEntryPoints();
const outputDir = path.resolve('dist');
const configs = Object.entries(entries).map(([name, input]) => {
const isSrc = name === 'GA4CustomTask';
const outputPath = isSrc
? path.join(outputDir, `${name}.js`)
: path.join(outputDir, 'tasks', `${name}.js`);
return {
input,
output: [
{
file: outputPath,
format: isSrc ? 'umd' : 'iife',
sourcemap: false,
name: isSrc ? 'GA4CustomTask' : name,
exports: 'default',
},
{
file: outputPath.replace(/\.js$/, '.min.js'),
format: isSrc ? 'umd' : 'iife',
sourcemap: false,
name: isSrc ? 'GA4CustomTask' : name,
exports: 'default',
plugins: [ terser({
compress: {
drop_console: false,
},
format: {
beautify: false,
comments: false,
}
})],
},
],
plugins: [
nodeResolve({
extensions: ['.js', '.ts'],
}),
typescript({
tsconfig: './tsconfig.json',
sourceMap: false,
}),
babel({
babelHelpers: 'bundled',
exclude: 'node_modules/**',
presets: ['@babel/preset-env'],
}),
],
};
});
export default configs;