-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.config.ts
62 lines (52 loc) · 1.77 KB
/
build.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
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { OutputPlugin } from 'rollup';
import { defineBuildConfig } from 'unbuild';
const ROOT_DIR = path.dirname(fileURLToPath(import.meta.url));
/**
* Rollup plugin to convert the prettier config files to .json format.
*/
const prettierJsonConfig: OutputPlugin = {
// TODO: Mover implementación a otro paquete
name: 'prettierJsonConfig',
async generateBundle(_outputOptions, bundle) {
// Filter only prettier files
const prettierFilesNames = Object.keys(bundle).filter(
(name) => name.startsWith('prettier') && name.endsWith('.mjs')
);
// console.log(_outputOptions, bundle);
const files = prettierFilesNames.map((name) => bundle[name]);
for (const bundleFile of files) {
if (bundleFile.type === 'chunk' && bundleFile.facadeModuleId) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const sourceFile = await import(bundleFile.facadeModuleId); // The original TS
this.emitFile({
type: 'asset',
fileName: bundleFile.fileName.replace('.mjs', '.json'),
source: JSON.stringify(sourceFile, null, 2),
});
}
}
},
};
export default defineBuildConfig({
rollup: {
inlineDependencies: true,
output: {
minifyInternalExports: true,
preserveModules: true,
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore Type instantiation is excessively deep and possibly infinite.
plugins: [prettierJsonConfig],
},
},
externals: [
//
'@elegantech/prettier-multi-config/presets',
'@elegantech/prettier-multi-config',
],
alias: {
'~': path.resolve(ROOT_DIR, './src'),
},
outDir: path.resolve(ROOT_DIR, './dist'),
});