-
Notifications
You must be signed in to change notification settings - Fork 2
/
rollup.config.js
84 lines (81 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
import { nodeResolve } from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import typescript from "@rollup/plugin-typescript";
import cleaner from "rollup-plugin-cleaner";
import terser from "@rollup/plugin-terser";
import pluginReplace from "@rollup/plugin-replace";
import { copyFile } from "fs/promises";
import { join, dirname, basename } from 'path';
import { glob } from 'glob';
const pkg = require("./package.json");
export default {
input: "src/index.ts",
output: [
{ file: pkg.main, name: "tsLuxon", format: "umd", sourcemap: true },
{ file: pkg.main.replace(".js", ".min.js"), name: "tsLuxon", format: "umd", sourcemap: "inline", plugins: [terser()] },
{ file: pkg.exports.import.default, format: "es", sourcemap: true },
{ file: pkg.exports.import.default.replace(".mjs", ".min.mjs"), format: "es", sourcemap: "inline", plugins: [terser()] }
],
external: [],
watch: {
include: "src/**"
},
plugins: [
cleaner({
targets: [
"./dist/"
]
}),
// Compile TypeScript files
typescript({
// tsconfig: "tsconfig.json"
}),
// Allow bundling cjs modules (unlike webpack, rollup doesn't understand cjs)
commonjs(),
// Enable Terser
terser(),
// Allow node_modules resolution, so you can use 'external' to control
// which external modules to include in the bundle
// https://github.com/rollup/rollup-plugin-node-resolve#usage
nodeResolve(),
pluginReplace({
preventAssignment: !0,
values: {
__BUILD_VRS__: () => pkg.version
}
}),
// copyAndRename("dist/index.d.ts", "dist/index.d.mts"),
copyAndRename('dist/**/*.d.ts', filename => filename.replace('.d.ts', '.d.mts'))
]
};
/*
function copyAndRename(src, dest) {
return {
name: "copy-and-rename",
writeBundle() {
copyFile(src, dest)
.catch((err) => {
console.error("copyAndRename: error copying file!", err);
});
}
};
}
*/
function copyAndRename(pattern, renameFn) {
return {
name: 'copy-and-rename',
async writeBundle() {
try {
const files = await glob(pattern);
await Promise.all(files.map(async (file) => {
console.info("WORKING ON FILE", file);
const filePath = dirname(file);
const dest = join(filePath, renameFn(basename(file)));
await copyFile(file, dest);
}));
} catch (copyError) {
console.error('Error copying files:', copyError);
}
}
};
}