-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.ts
109 lines (102 loc) · 2.8 KB
/
rollup.config.ts
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
103
104
105
106
107
108
109
// rollup.config.ts
import path from "node:path";
import { defineConfig, Plugin, RollupOptions } from "rollup";
import nodeResolve from "@rollup/plugin-node-resolve";
import typescript from "@rollup/plugin-typescript";
import commonjs from "@rollup/plugin-commonjs";
import json from "@rollup/plugin-json";
import copy from "rollup-plugin-copy";
//@ts-ignore
import { createPathTransform } from "rollup-sourcemap-path-transform";
// const sourcemapPathTransform = createPathTransform({
// prefixes: {
// "*src/": `${resolve(".", "nodefony", "src")}/`,
// "*config/": `${resolve(".", "nodefony", "config")}/`,
// "*decorators/": `${resolve(".", "nodefony", "decorators")}/`,
// "*service/": `${resolve(".", "nodefony", "service")}/`,
// "*controller/": `${resolve(".", "nodefony", "controller")}/`,
// "*entity/": `${resolve(".", "nodefony", "entity")}/`,
// "*command/": `${resolve(".", "nodefony", "command")}/`,
// },
// });
const external: string[] = [
"nodefony",
"@nodefony/http",
"@nodefony/security",
"@nodefony/framework",
"@nodefony/sequelize",
"@nodefony/mongoose",
"@nodefony/redis",
"@nodefony/test",
"@nodefony/user",
"tslib",
];
const sharedNodeOptions = defineConfig({
treeshake: {
moduleSideEffects: "no-external",
propertyReadSideEffects: false,
tryCatchDeoptimization: false,
},
output: {
dir: "./dist",
entryFileNames: `[name].js`,
exports: "auto",
format: "es",
externalLiveBindings: false,
freeze: false,
},
onwarn(warning, warn) {
if (warning.message.includes("Circular dependency")) {
return;
}
warn(warning);
},
});
function createNodePlugins(
isProduction: boolean,
sourceMap: boolean,
declarationDir: string | false
): Plugin[] {
const tab = [
nodeResolve({ preferBuiltins: true }),
typescript({
tsconfig: path.resolve("tsconfig.json"),
sourceMap,
declaration: declarationDir !== false,
declarationDir: declarationDir !== false ? declarationDir : undefined,
}),
commonjs({
extensions: [".js"],
//ignoreDynamicRequires: true
dynamicRequireTargets: [],
}),
json(),
copy({
targets: [],
}),
];
if (isProduction) {
//tab.push(terser());
}
return tab;
}
function createNodeConfig(isProduction: boolean): RollupOptions {
return defineConfig({
//input,
input: "index.ts",
...sharedNodeOptions,
output: {
...sharedNodeOptions.output,
sourcemap: !isProduction,
preserveModules: true,
preserveModulesRoot: "nodefony",
},
external,
plugins: [...createNodePlugins(isProduction, true, "dist/types")],
});
}
export default (commandLineArgs: any): RollupOptions => {
const isDev = commandLineArgs.watch;
const isProduction = !isDev;
return createNodeConfig(isProduction);
};