-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
81 lines (69 loc) · 2.01 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
/*!
* Rollup config
* @see https://github.com/cferdinandi/build-tool-boilerplate
*/
// Plugins
import { terser } from 'rollup-plugin-terser';
import { nodeResolve } from '@rollup/plugin-node-resolve';
import pkg from './package.json';
// Configs
const configs = {
files: ['main.js'],
formats: ['iife', 'es'],
default: 'iife',
pathIn: 'src/assets/js',
pathOut: 'dist/assets/js',
minify: true,
sourceMap: false,
};
// Banner
const banner = `/*! ${configs.name ? configs.name : pkg.name} v${pkg.version} | (c) ${new Date().getFullYear()} ${pkg.author} | ${pkg.license} License | ${pkg.repository.url} */`;
/**
* Create single output
* @param {String} filename The filename
* @param {Boolean} minify Should we minify
* @return {Object} One output object
*/
const createOutput = (filename, minify) => configs.formats.map((format) => {
const output = {
file: `${configs.pathOut}/${filename}${format === configs.default ? '' : `.${format}`}${minify ? '.min' : ''}.js`,
format,
banner,
};
if (format === 'iife') {
output.name = configs.name ? configs.name : pkg.name;
}
if (minify) {
output.plugins = [terser()];
}
output.sourcemap = configs.sourceMap;
return output;
});
/**
* Create output formats
* @param {String} filename The filename
* @return {Array} The outputs array
*/
const createOutputs = (filename) => {
// Create base outputs
const outputs = createOutput(filename);
// If not minifying, return outputs
if (!configs.minify) return outputs;
// Otherwise, create second set of outputs
const outputsMin = createOutput(filename, true);
// Merge and return the two arrays
return outputs.concat(outputsMin);
};
/**
* Create export object
* @return {Array} The export object
*/
const createExport = () => configs.files.map((file) => {
const filename = file.replace('.js', '');
return {
input: `${configs.pathIn}/${file}`,
output: createOutputs(filename),
plugins: [nodeResolve()],
};
});
export default createExport();