-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
167 lines (154 loc) · 4.17 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
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
157
158
159
160
161
162
163
164
165
166
167
// import typescript from '@rollup/plugin-typescript';
import { nodeResolve } from '@rollup/plugin-node-resolve';
import tsConfigPaths from "rollup-plugin-tsconfig-paths";
import alias from "@rollup/plugin-alias";
import glob from 'glob';
import path from 'node:path';
import { fileURLToPath } from 'url';
import copy from 'rollup-plugin-copy';
import cleaner from 'rollup-plugin-cleaner';
import peerDepsExternal from 'rollup-plugin-peer-deps-external';
import { dts } from 'rollup-plugin-dts';
import swc from '@rollup/plugin-swc';
import json from '@rollup/plugin-json';
// Convert the import.meta.url to a file path
const __filename = fileURLToPath(import.meta.url);
// Get the directory name from the file path
const __dirname = path.dirname(__filename);
function getInputsFromGlob(pattern) {
return glob.sync(pattern).reduce((inputs, file) => {
const name = path.basename(file, path.extname(file));
if (name === 'public_api') return inputs;
inputs.push(file);
return inputs;
}, []);
}
const tsFilesSrc = getInputsFromGlob('src/**/**/**/**/*.ts');
const buildFolderPathPattern = /^(src\/)(.*?)([/][^/]+\.ts)$/gs;
const removeSrcPattern = /^(src[/\\])(.*?)/gs;
const normalizeUrl = (url) => url.replace(/\\/g, '/');
const removeSrcPath = (string) => normalizeUrl(string).replace(removeSrcPattern, '$2');
const removeSrcFileNamePath = (string) =>
normalizeUrl(string).replace(buildFolderPathPattern, '$2');
const basePlugins = [
// typescript({ outputToFilesystem: false }),
json(),
tsConfigPaths(),
peerDepsExternal(),
nodeResolve({ extensions: [".ts",".js", ".json"] }),
swc({
// SWC configuration
include: /\.ts?$/,
jsc: {
parser: {
syntax: 'typescript',
tsx: false,
},
baseUrl: '.',
target: 'ES2021',
},
module: {
type: 'commonjs',
},
tsconfig: path.resolve(__dirname, 'tsconfig.json'),
}),
];
const baseExternal = [
'node:module',
'ansi-colors',
'ora',
'inquirer',
'tty',
'node-emoji',
'ajv',
'@angular-devkit/core',
'@schematics/angular/utility/dependencies',
'@schematics/angular/utility/parse-name',
'@angular-devkit/schematics/tasks',
'@angular-devkit/schematics-cli',
'@angular-devkit/schematics',
'winston',
'winston-console-format'
];
export default [
{
input: 'src/public_api.ts',
output: [
{
dir: 'dist',
format: 'cjs',
preserveModules: true,
},
],
external: baseExternal,
plugins: [
...basePlugins,
cleaner({
targets: ['./dist/'],
silence: false,
}),
copy({
targets: [
{
src: 'package.json',
dest: 'dist',
transform: (contents) => {
const packageData = JSON.parse(contents.toString());
delete packageData.scripts;
delete packageData.devDependencies;
delete packageData.keywords;
delete packageData.engines;
return JSON.stringify(packageData, null, 2);
},
},
{
src: 'README.md',
dest: 'dist',
},
{
src: 'src/collection.json',
dest: 'dist',
},
{
src: 'src/**/**/*.json',
dest: 'dist/',
rename: (name, extension, fullPath) => {
return removeSrcPath(fullPath);
},
},
{
src: ['src/**/**/**/**/*.template', 'src/**/**/**/**/.*.template'],
dest: 'dist/',
rename: (name, extension, fullPath) => {
return removeSrcPath(fullPath);
},
},
],
hook: 'writeBundle',
}),
],
},
...tsFilesSrc.map((file) => ({
input: file,
output: {
dir: `dist/${removeSrcFileNamePath(file)}`,
format: 'cjs',
exports: 'auto',
},
plugins: [...basePlugins,
alias({
entries: [
{ find: 'utils', replacement: '../../utils' }
]
})
],
external: baseExternal,
})),
...tsFilesSrc.map((file) => ({
input: file,
output: {
dir: `dist/${removeSrcFileNamePath(file)}`,
},
plugins: [dts()],
})),
];