-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
50 lines (43 loc) · 1.19 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
import eslint from '@rollup/plugin-eslint';
import terser from '@rollup/plugin-terser';
import typescript from '@rollup/plugin-typescript';
import fs from 'fs';
import ZipPack from 'unplugin-zip-pack/vite';
import cleanPlugin from 'vite-plugin-clean';
import cp from 'vite-plugin-cp';
const ENTRYPOINTS_PATH = 'src/entrypoints';
const makePathToIndex = name => `${ENTRYPOINTS_PATH}/${name}/index.ts`;
if (!process.env.package) {
throw new Error('package not specified, pass argument package:PACKAGE_NAME');
}
const fileName = process.env.package;
const path = makePathToIndex(fileName);
if (!fs.existsSync(path)) {
throw new Error(`Package doesn't have index.ts file (path="${path}")`);
}
const pathToDir = `dist/${fileName}`;
export default {
input: path,
output: {
format: 'es',
file: `${pathToDir}/index.js`
},
plugins: [
cleanPlugin({
targetFiles: pathToDir
}),
typescript({module: 'ESNext'}),
eslint(),
terser(),
cp({
targets: [
{src: 'package.json', dest: `dist/${fileName}`},
{src: 'package-lock.json', dest: `dist/${fileName}`}
]
}),
ZipPack({
in: pathToDir,
out: `${pathToDir}/${fileName}.zip`
})
]
};