This repository has been archived by the owner on Mar 21, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 66
/
rollup.config.js
71 lines (62 loc) · 1.71 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
import vue from 'rollup-plugin-vue';
import babel from 'rollup-plugin-babel';
import builtins from 'rollup-plugin-node-builtins';
import resolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';
import { uglify } from 'rollup-plugin-uglify';
import { rollup } from 'rollup';
import clone from 'lodash/cloneDeep';
import camelcase from 'camelcase';
import chalk from 'chalk';
import { default as vueConfig, pack } from './config/rollup-plugin-vue.config';
import babelConfig from './config/babel.config';
let cache;
const config = {
input: 'src/main.js',
output: [
{ format: 'es', file: `dist/${pack.name}.esm.js` },
{ format: 'cjs', file: `dist/${pack.name}.common.js` },
],
plugins: [
vue(vueConfig),
babel(babelConfig),
],
cache,
};
// --- DO NOT CHANGE BEYOND THIS ---
if (vueConfig.standalone) {
const options = clone(config);
options.output = [];
options.plugins = [
builtins(),
resolve({
module: true,
jsnext: true,
main: true,
browser: true,
}),
commonjs(),
].concat(options.plugins);
let promise = Promise.resolve();
promise.then(() => rollup(options).then(bundle => bundle.write({
format: 'umd',
file: `dist/${pack.name}.umd.js`,
name: camelcase(pack.name),
}))).then(() => {
options.plugins.push(uglify());
return rollup(options).then(bundle => bundle.write({
format: 'umd',
file: `dist/${pack.name}.min.js`,
name: camelcase(pack.name),
}));
}).then(() => {
console.log(chalk.cyan('Build complete.\n'))
}).catch(err => {
console.log(
chalk.red('Build Failed.\n'),
chalk.yellow(err),
chalk.yellow(err.stack)
)
});
}
export default config;