-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.mjs
99 lines (88 loc) · 2.77 KB
/
rollup.config.mjs
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
import fs from 'node:fs/promises';
import path from 'node:path';
import typescript from '@rollup/plugin-typescript';
import terser from '@rollup/plugin-terser';
const __dirname = path.dirname(new URL(import.meta.url).pathname),
{log, error} = console,
isDev = !process.env.NODE_ENV || process.env.NODE_ENV.toLowerCase().startsWith('dev'),
projectNames = ['fjl', 'fjl-validator', 'fjl-inputfilter'/*, 'fjl-validator-recaptcha'*/],
configs = projectNames.flatMap(projectName => {
const projectPath = path.join(__dirname, `./packages/${projectName}`),
configBase = {
input: path.join(projectPath, 'src/index.ts'),
treeshake: false,
},
plugins = [
typescript({
tsconfig: path.join(projectPath, './tsconfig.json'),
}),
terser()
],
outputGlobals = {},
outputBase = {
sourcemap: isDev,
globals: outputGlobals,
preserveModules: true,
preserveModulesRoot: path.join(projectPath, 'src')
};
if (projectName.includes('fjl-validator')) {
configBase.external = ['fjl'];
Object.assign(outputGlobals, {
fjl: 'fjl'
})
} else if (projectName === 'fjl-inputfilter') {
configBase.external = ['fjl', 'fjl-validator'];
Object.assign(outputGlobals, {
fjl: 'fjl',
'fjl-validator': 'fjlValidator'
});
}
return [{
...configBase,
output: {
...outputBase,
format: 'es',
dir: path.join(projectPath, 'dist/esm/'),
entryFileNames: '[name].mjs'
},
plugins: [
typescript({
tsconfig: path.join(projectPath, './tsconfig.prod.esm.json'),
compilerOptions: {
sourceMap: isDev
}
}),
terser()
]
}, {
...configBase,
output: {
...outputBase,
format: 'cjs',
dir: path.join(projectPath, 'dist/cjs/'),
entryFileNames: '[name].cjs'
},
plugins
}];
});
// Clean project distro paths
// ----
log('Cleaning dist paths:');
await Promise.all(projectNames.map(projectName => {
const distPath = path.join(__dirname, `./packages/${projectName}/dist/`);
log(`\n- ./packages/${projectName}/dist/`);
// Delete files in 'dist/' paths for each project
return fs.readdir(distPath)
.catch(() => [])
.then(files => files?.map(file => {
const filePath = path.join(distPath, file);
const projectPath = `./${filePath.split(__dirname)[1]}`;
return fs.rm(filePath, {recursive: true})
.then(() => null, // (log(`${projectPath} removed`), filePath),
() => log(`Skipping removal of ${projectPath}`))
}))
.then(removals => Promise.all(removals))
}))
.then(() => log('\nCleaning completed.'))
.catch(error);
export default configs;