-
Notifications
You must be signed in to change notification settings - Fork 1
/
rollup.config.js
70 lines (62 loc) · 2.03 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
/* eslint-env node */
import path from 'path';
import filesize from 'rollup-plugin-filesize';
import { terser } from 'rollup-plugin-terser';
import pkg from './package.json';
// Config examples
// https://habr.com/en/post/440946/
// https://github.com/Polymer/lit-html/blob/master/rollup.config.js
// https://github.com/mobxjs/mobx/blob/master/scripts/build.js
// https://github.com/rollup/rollupjs.org/blob/master/rollup.config.js
// https://github.com/rollup/rollup/issues/863#issuecomment-306061779
// https://github.com/rollup/rollup/blob/master/rollup.config.js
// https://github.com/rollup/rollup-starter-lib/blob/master/rollup.config.js
const banner = `/**
* Rest-Api-Client v${pkg.version}
* https://github.com/archangel-irk/rest-api-client
* (c) Constantine Melnikov 2013 - 2019
* MIT License
*/`;
// Name for UMD export
const name = 'ApiClient';
const Format = {
CommonJS: 'cjs',
ESModule: 'esm',
UMD: 'umd', // works as amd, cjs and iife all in one.
};
const Mode = {
PRODUCTION: 'production',
DEVELOPMENT: 'development',
};
function generateBundleConfig(outputFile, format, mode) {
let plugins;
if (mode === Mode.PRODUCTION) {
plugins = [
// replacePlugin({ 'process.env.NODE_ENV': JSON.stringify('production') }),
// Минификатор совместимый с ES2015+, форк и наследник UglifyES,
terser({
warnings: 'verbose', // more detailed warnings
module: format === Format.ESModule,
}),
filesize(),
];
} else {
plugins = [filesize()];
}
return {
input: 'src/index.js',
output: {
file: outputFile,
format,
banner,
name: format === Format.UMD ? name : undefined,
exports: 'named',
sourcemap: mode === Mode.DEVELOPMENT ? 'inline' : undefined,
},
plugins,
};
}
export default [
generateBundleConfig(path.join('dist', 'api-client.development.js'), Format.ESModule, Mode.DEVELOPMENT),
generateBundleConfig(path.join('dist', 'api-client.production.min.js'), Format.ESModule, Mode.PRODUCTION),
];