-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup.config.js
89 lines (82 loc) · 2.61 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
import path from 'path';
import { defineConfig } from 'rollup';
import { nodeResolve } from '@rollup/plugin-node-resolve';
import json from '@rollup/plugin-json';
import ts from 'rollup-plugin-typescript2';
import { terser } from 'rollup-plugin-terser';
import replace from '@rollup/plugin-replace';
const target = process.env.TARGET;
const env = process.env.NODE_NEV;
const packagesDir = path.resolve(__dirname, 'packages');
const packageDir = path.resolve(packagesDir, target);
const resolve = r => path.resolve(packageDir, r);
const packageJson = require(path.resolve(packageDir, 'package.json'));
const buildOptions = packageJson.buildOptions || {};
const name = packageDir.filename || path.basename(packageDir);
const outputConfigs = {
'esm-bundler': {
file: resolve(`dist/${name}.esm-bundler.js`),
format: `es`
},
'esm-browser': {
file: resolve(`dist/${name}.esm-browser.js`),
format: `es`
},
'cjs.prod': {
file: resolve(`dist/${name}.cjs.prod.js`),
format: `cjs`
},
cjs: {
file: resolve(`dist/${name}.cjs.js`),
format: `cjs`
},
global: {
file: resolve(`dist/${name}.global.js`),
format: `iife`
}
};
/**
* @description
* @param {string} format
* @param {*} output
* @returns { RollupOptions }
*/
function createConfig(format, output) {
output.name = buildOptions.name;
output.sourcemap = env === 'development';
return defineConfig({
input: resolve(`src/index.ts`),
output: {
...output,
globals: {
'@maxgraph/core': 'maxgraph'
},
exports: 'auto'
},
plugins: [
json(),
nodeResolve(),
ts({
tsconfig: path.resolve(__dirname, 'tsconfig.json'),
tsconfigOverride: {
compilerOptions: {
declaration: true,
declarationMap: false,
declarationDir: resolve('dist/types'),
allowJs: true
},
include: [resolve(`src/**/*.ts`)]
},
clean: true,
useTsconfigDeclarationDir: true
}),
env === 'production' && format !== 'cjs' ? terser() : false,
replace({
'process.env.NODE_ENV': JSON.stringify(env),
preventAssignment: true
})
].filter(Boolean),
external: ['@maxgraph/core']
});
}
export default buildOptions.formats.map(format => createConfig(format, outputConfigs[format]));