This repository has been archived by the owner on Feb 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
rollup.config.js
executable file
·110 lines (94 loc) · 2.77 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import babel from 'rollup-plugin-babel';
import cjs from 'rollup-plugin-commonjs';
import resolve from 'rollup-plugin-node-resolve';
import { uglify } from 'rollup-plugin-uglify';
import run from 'rollup-plugin-run';
import serve from 'rollup-plugin-serve'
import pkg from './package.json'
import fs from 'fs';
import { fsizeSync, rmdirsSync } from 'nodejs-fs-utils';
import boxen from 'boxen';
import chalk from 'chalk';
const production = !process.env.ROLLUP_WATCH;
const development = process.env.ROLLUP_WATCH;
const RUN = process.env.RUN;
// Default options
const devServerOptions = {
verbose: false,
contentBase: ['dist'],
host: 'localhost',
port: 8080,
headers: {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Headers': 'Origin, X-Requested-With, Content-Type, Accept, Range',
}
};
const boxOptions = {
borderColor: "gray",
padding: 1,
borderStyle: "round",
}
const logger = () => {
return {
writeBundle(bundle) {
const bundleSize = parseFloat(Math.round(fsizeSync(pkg.files[0])) / 1024).toFixed(2);
const filesPaths = [];
const extensionRegex = /\.[0-9a-z]+$/i;
const items = fs.readdirSync(pkg.files[0]);
for (var i=0; i<items.length; i++) {
const extension = items[i].match(extensionRegex)[0];
if (extension === '.js') {
filesPaths.push(chalk.white.bold('js: ')+chalk.white(`${items[i]}`));
}
else if (extension === '.css') {
filesPaths.push(chalk.white.bold('css: ')+chalk.white(`${items[i]}`));
}
}
if (development) {
const devContent = [
chalk.green.bold('FOR PLUGIN MANAGER:'),
chalk.white.bold('port: ')+chalk.white(devServerOptions.port),
...filesPaths,
];
console.log(boxen(devContent.join("\n"), boxOptions));
}
if (production) {
const productionContent = [
chalk.green.bold('PUBLISHING INFO'),
...filesPaths,
chalk.white.bold('size: ') + chalk.white(`${bundleSize}KB`) + chalk.gray(' (Keep it under 100KB)'),
chalk.white.bold('guide: ') + chalk.white('https://docs.figmaplus.com/#/developerGuide/publish'),
];
console.log(boxen(productionContent.join("\n"), boxOptions));
}
}
}
}
const distCleaner = () => {
return {
buildStart () {
rmdirsSync(pkg.files[0], { skipErrors: true });
}
}
}
export default [
// browser-friendly UMD build
{
input: 'src/index.js',
output: {
name: pkg.name,
file: `${pkg.files[0]}/${pkg.name}.js`,
format: 'umd'
},
plugins: [
distCleaner(),
resolve(),
babel({runtimeHelpers: true,}),
cjs(),
development && RUN && run(), // Dev mode: run the bundle to see output in console/terminal
development && serve(devServerOptions), // Dev Serve mode: serve bundle
production && uglify(), // Production: uglify bundle,
logger()
],
},
];