-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrollup.config.mjs
More file actions
156 lines (143 loc) · 3.29 KB
/
Copy pathrollup.config.mjs
File metadata and controls
156 lines (143 loc) · 3.29 KB
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
/**
* Rollup Configuration
*
* Bundles the project into:
* - dist/index.cjs - Minified CommonJS bundle
* - dist/index.d.ts - Bundled type definitions
*/
import commonjs from '@rollup/plugin-commonjs';
import resolve from '@rollup/plugin-node-resolve';
import terser from '@rollup/plugin-terser';
import typescript from '@rollup/plugin-typescript';
import dts from 'rollup-plugin-dts';
import fs from 'node:fs';
import path from 'node:path';
const external = [
'@automapper/core',
'@automapper/pojos',
'commander',
'fs',
'node:fs',
'path',
'node:path',
'typescript',
'util',
'node:util',
'os',
'node:os',
];
const terserOptions = {
compress: {
drop_console: false,
drop_debugger: true,
ecma: 2020,
},
format: {
comments: false,
},
};
const SRC_ALIAS_PREFIX = '@/';
const RESOLVABLE_EXTENSIONS = ['.ts', '.tsx', '.js', '.jsx'];
function resolveProjectAlias(importPath) {
const targetPath = path.resolve(process.cwd(), importPath.slice(SRC_ALIAS_PREFIX.length));
const directMatch = resolveAliasCandidate(targetPath);
if (directMatch) {
return directMatch;
}
for (const extension of RESOLVABLE_EXTENSIONS) {
const indexMatch = resolveAliasCandidate(path.join(targetPath, `index${extension}`));
if (indexMatch) {
return indexMatch;
}
}
return null;
}
function resolveAliasCandidate(candidatePath) {
if (fs.existsSync(candidatePath) && fs.statSync(candidatePath).isFile()) {
return candidatePath;
}
for (const extension of RESOLVABLE_EXTENSIONS) {
const withExtension = `${candidatePath}${extension}`;
if (fs.existsSync(withExtension) && fs.statSync(withExtension).isFile()) {
return withExtension;
}
}
return null;
}
function projectAliasPlugin() {
return {
name: 'project-alias',
resolveId(source) {
if (!source.startsWith(SRC_ALIAS_PREFIX)) {
return null;
}
return resolveProjectAlias(source);
},
};
}
export default [
// Main bundle - minified CommonJS
{
input: 'src/index.ts',
output: {
file: 'dist/index.cjs',
format: 'cjs',
sourcemap: false,
exports: 'named',
},
external,
plugins: [
projectAliasPlugin(),
resolve({
preferBuiltins: true,
extensions: ['.ts', '.tsx', '.js', '.jsx'],
}),
typescript({
tsconfig: './tsconfig.json',
declaration: false,
declarationMap: false,
module: 'ESNext',
}),
commonjs({
extensions: ['.js', '.ts'],
}),
terser(terserOptions),
],
},
// CLI executable bundle
{
input: 'bin/figma-connecter.ts',
output: {
file: 'dist/figma-connecter.cjs',
format: 'cjs',
sourcemap: false,
},
external,
plugins: [
projectAliasPlugin(),
resolve({
preferBuiltins: true,
extensions: ['.ts', '.tsx', '.js', '.jsx'],
}),
typescript({
tsconfig: './tsconfig.json',
declaration: false,
declarationMap: false,
module: 'ESNext',
}),
commonjs({
extensions: ['.js', '.ts'],
}),
],
},
// Type definitions bundle
{
input: 'src/index.ts',
output: {
file: 'dist/index.d.ts',
format: 'es',
},
external,
plugins: [projectAliasPlugin(), dts()],
},
];