-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathrollup.config.js
66 lines (55 loc) · 1.69 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
/* eslint one-var: "off" */
import path from 'path';
import copy from 'rollup-plugin-copy';
import serve from 'rollup-plugin-serve';
import uglify from 'rollup-plugin-uglify';
import livereload from 'rollup-plugin-livereload';
import { version, source, build, samples, directories } from './package.json';
const BANNER = `/**
* SvgDeCanvo ${version} - JavaScript Vector Library
* Copyright (c) 2015-2018 FusionCharts, Inc. <http://www.fusioncharts.com>
* Licensed under the MIT license.
*/`;
const { dist: BUILD_PATH, name: BUILD_FILE_NAME } = build;
const { root: SAMPLE_PATH } = samples;
const { test: SAMPLE_HTML_DIR } = directories;
const ENTRY = path.resolve(source.src, `${source.name}.js`);
function getOutput (args) {
let output = {
format: 'umd',
name: 'SvgDeCanvo'
};
const filePath = (args.watch || args.configDevelopment) ? SAMPLE_PATH : BUILD_PATH;
const fileName = (args.configMinify && args.configProduction)
? `${BUILD_FILE_NAME}-min.js`
: `${BUILD_FILE_NAME}.js`;
output.file = path.resolve(filePath, fileName);
if (!args.configMinify) {
output.banner = BANNER;
}
return output;
};
function getPlugins (args) {
let plugins = [];
if (args.watch) {
plugins.push(copy({
[`${SAMPLE_HTML_DIR}/index.html`]: `${SAMPLE_PATH}/index.html`,
verbose: true
}));
if (args.configDevelopment) {
plugins.push(serve({ contentBase: SAMPLE_PATH }));
plugins.push(livereload({ watch: SAMPLE_PATH }));
}
}
if (args.configMinify) {
plugins.push(uglify({ output: { preamble: BANNER } }));
}
return plugins;
};
export default args => {
return {
input: ENTRY,
output: getOutput(args),
plugins: getPlugins(args)
};
};