This repository has been archived by the owner on Apr 28, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 862
/
rollup.config.js
72 lines (60 loc) · 1.7 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
// Plugins
import { terser } from 'rollup-plugin-terser';
import pkg from './package.json';
// Configs
var configs = {
name: 'SmoothScroll',
files: ['smooth-scroll.js', 'smooth-scroll.polyfills.js'],
formats: ['umd'],
default: 'umd',
pathIn: 'src/',
pathOut: 'dist/',
minify: true
};
// Banner
var banner = `/*! ${configs.name ? configs.name : pkg.name} v${pkg.version} | (c) ${new Date().getFullYear()} ${pkg.author.name} | ${pkg.license} License | ${pkg.repository.url} */`;
var createOutput = function (filename, minify) {
return configs.formats.map(function (format) {
var output = {
file: `${configs.pathOut}/${filename}${format === configs.default ? '' : `.${format}`}${minify ? '.min' : ''}.js`,
format: format,
banner: banner
};
if (format === 'iife' || format === 'umd') {
output.name = configs.name ? configs.name : pkg.name;
}
if (minify) {
output.plugins = [terser()];
}
return output;
});
};
/**
* Create output formats
* @param {String} filename The filename
* @return {Array} The outputs array
*/
var createOutputs = function (filename) {
// Create base outputs
var outputs = createOutput(filename);
// If not minifying, return outputs
if (!configs.minify) return outputs;
// Otherwise, ceate second set of outputs
var outputsMin = createOutput(filename, true);
// Merge and return the two arrays
return outputs.concat(outputsMin);
};
/**
* Create export object
* @return {Array} The export object
*/
var createExport = function (file) {
return configs.files.map(function (file) {
var filename = file.replace('.js', '');
return {
input: `${configs.pathIn}/${file}`,
output: createOutputs(filename)
};
});
};
export default createExport();