This repository has been archived by the owner on Jan 13, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
/
rollup.config.js
118 lines (111 loc) · 3.12 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
111
112
113
114
115
116
117
118
import fs from 'fs';
import path from 'path';
import resolve from 'rollup-plugin-node-resolve';
import babel from 'rollup-plugin-babel';
import commonjs from 'rollup-plugin-commonjs';
import sourceMaps from 'rollup-plugin-sourcemaps';
import scss from 'rollup-plugin-scss';
import json from 'rollup-plugin-json';
import copy from 'rollup-plugin-copy';
import kebabCase from 'lodash/kebabCase';
import pkg from './package.json';
function createEntry(input, output, css, plugins = []) {
return {
input,
output,
// Indicate here external modules you don't wanna include in your bundle (i.e.: 'lodash')
external: ['video.js'],
plugins: [
// Allow json resolution
json(),
// Compile TypeScript files
// Allow bundling cjs modules (unlike webpack, rollup doesn't understand cjs)
commonjs(),
// Allow node_modules resolution, so you can use 'external' to control
// which external modules to include in the bundle
// https://github.com/rollup/rollup-plugin-node-resolve#usage
resolve(),
babel({
babelrc: true,
exclude: 'node_modules/**',
compact: false
}),
// Resolve source maps to the original source
sourceMaps(),
scss({
sass: require('sass'),
output: styles => {
if (styles && styles.length) {
const cssOutput =
css || output[0].file.replace(/\.(umd|es|iife).js/, '.css');
mkdirp(cssOutput.replace(/[^\/]*$/, ''));
fs.writeFileSync(cssOutput, styles);
}
}
}),
...plugins
]
};
}
const pluginsDir = 'source/Plugin';
const output = setFileName =>
['umd', 'es'].map(format => {
return {
file: setFileName(format),
format,
sourcemap: true,
globals: {
'video.js': 'videojs'
},
banner: `
/* eslint-disable */
/* VERSION: ${pkg.version} */
`
.trim()
.replace(/^(\s{2})+/gm, '')
.replace(/^ *\n/, '')
};
});
const distDir = 'dist';
export default [
createEntry(
'source/index.js',
output(format => path.join(distDir, `/videojs-plus.${format}.js`))
),
...fs.readdirSync(pluginsDir).map(pluginName => {
const kebabCaseName = kebabCase(pluginName);
const srcDir = `${pluginsDir}/${pluginName}/`;
const outDir = path.join(distDir, `/plugins/${kebabCaseName}`);
return createEntry(
path.join(srcDir, `${pluginName}.js`),
output(format => {
const name = format === 'umd' ? 'index' : `${kebabCaseName}.${format}`;
return `${outDir}/${name}.js`;
}),
`${outDir}/style.css`,
[
copy({
targets: [{ src: `${srcDir}/index.d.ts`, dest: outDir }]
})
]
);
})
];
function mkdirp(dir) {
return path
.resolve(dir)
.split(path.sep)
.reduce((acc, cur) => {
const currentPath = path.normalize(acc + path.sep + cur);
try {
fs.statSync(currentPath);
} catch (e) {
if (e.code === 'ENOENT') {
fs.mkdirSync(currentPath);
} else {
throw e;
}
}
return currentPath;
}, '');
}