-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.ts
73 lines (71 loc) · 2.49 KB
/
rollup.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
63
64
65
66
67
68
69
70
71
72
73
import typescript from "rollup-plugin-typescript2";
import commonjs from "@rollup/plugin-commonjs";
import json from "@rollup/plugin-json";
import replace from "@rollup/plugin-replace";
import terser from "@rollup/plugin-terser";
import resolve from "@rollup/plugin-node-resolve";
import css from "rollup-plugin-css-only";
import {dts} from "rollup-plugin-dts";
import {DEFAULT_BUILD_DIR, DEFAULT_ROLLUP_BUILD_DIR, DEFAULT_ENTRY_DIR} from "./scripts/constant";
import * as process from "process";
if(!process.env.PACKAGE_DIR) {
throw new Error(`PACKAGE_DIR package must be specified via --environment flag.`);
}
function createPackageBuildConfig(packageDir: string) {
const inputFilePath = `${DEFAULT_ROLLUP_BUILD_DIR}/${packageDir}/${DEFAULT_ENTRY_DIR}`;
const outputFilePath = `${DEFAULT_ROLLUP_BUILD_DIR}/${packageDir}/${DEFAULT_BUILD_DIR}`
return{
input: `${inputFilePath}/index.ts`,
output: [
{
file: `${outputFilePath}/index.umd.js`,
format: 'umd',
name: packageDir,
exports: 'named',
},
{
file: `${outputFilePath}/index.cjs.js`,
format: 'cjs',
exports: 'named',
},
{
file: `${outputFilePath}/index.js`,
format: 'esm',
exports: 'named',
name: packageDir,
}
],
plugins: [
terser(),
replace({
preventAssignment: true,
'process.env.NODE_ENV': JSON.stringify('production'),
'__buildDate__': JSON.stringify(new Date().toISOString()),
'__version__': JSON.stringify(require('./package.json').version),
}),
typescript(),
json(),
commonjs(),
resolve(),
css({
output: `index.css`,
}),
],
}
}
function createPackageDTSBuildConfig(packageName: string) {
const inputFilePath = `${DEFAULT_ROLLUP_BUILD_DIR}/${packageName}/${DEFAULT_ENTRY_DIR}/index.ts`;
const outputFilePath = `${DEFAULT_ROLLUP_BUILD_DIR}/${packageName}/${DEFAULT_BUILD_DIR}/index.d.ts`
return {
input: inputFilePath,
output: {
file: outputFilePath,
format: 'es',
},
plugins: [dts()]
}
}
export default [
createPackageBuildConfig(process.env.PACKAGE_DIR),
createPackageDTSBuildConfig(process.env.PACKAGE_DIR)
]