rollup.config.js
3.82 KB
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
const generate = require('videojs-generate-rollup-config');
const worker = require('rollup-plugin-worker-factory');
const {terser} = require('rollup-plugin-terser');
const createTestData = require('./create-test-data.js');
const replace = require('@rollup/plugin-replace');
const strip = require('@rollup/plugin-strip');
const CI_TEST_TYPE = process.env.CI_TEST_TYPE || '';
let syncWorker;
// see https://github.com/videojs/videojs-generate-rollup-config
// for options
const options = {
input: 'src/videojs-http-streaming.js',
distName: 'videojs-http-streaming',
excludeCoverage(defaults) {
defaults.push(/^rollup-plugin-worker-factory/);
defaults.push(/^create-test-data!/);
return defaults;
},
globals(defaults) {
defaults.browser['@xmldom/xmldom'] = 'window';
defaults.test['@xmldom/xmldom'] = 'window';
return defaults;
},
externals(defaults) {
return Object.assign(defaults, {
module: defaults.module.concat([
'aes-decrypter',
'm3u8-parser',
'mpd-parser',
'mux.js',
'@videojs/vhs-utils'
])
});
},
plugins(defaults) {
// add worker and createTestData to the front of plugin lists
defaults.module.unshift('worker');
defaults.browser.unshift('worker');
// change this to `syncWorker` for syncronous web worker
// during unit tests
if (CI_TEST_TYPE === 'coverage') {
defaults.test.unshift('syncWorker');
} else {
defaults.test.unshift('worker');
}
defaults.test.unshift('createTestData');
if (CI_TEST_TYPE === 'playback-min') {
defaults.test.push('uglify');
}
// istanbul is only in the list for regular builds and not watch
if (CI_TEST_TYPE !== 'coverage' && defaults.test.indexOf('istanbul') !== -1) {
defaults.test.splice(defaults.test.indexOf('istanbul'), 1);
}
defaults.module.unshift('replace');
defaults.module.unshift('strip');
defaults.browser.unshift('strip');
return defaults;
},
primedPlugins(defaults) {
defaults = Object.assign(defaults, {
replace: replace({
// single quote replace
"require('@videojs/vhs-utils/es": "require('@videojs/vhs-utils/cjs",
// double quote replace
'require("@videojs/vhs-utils/es': 'require("@videojs/vhs-utils/cjs'
}),
uglify: terser({
output: {comments: 'some'},
compress: {passes: 2}
}),
strip: strip({
functions: ['TEST_ONLY_*'],
debugger: false,
sourceMap: false
}),
createTestData: createTestData()
});
defaults.worker = worker({type: 'browser', plugins: [
defaults.resolve,
defaults.json,
defaults.commonjs,
defaults.babel
]});
defaults.syncWorker = syncWorker = worker({type: 'mock', plugins: [
defaults.resolve,
defaults.json,
defaults.commonjs,
defaults.babel
]});
return defaults;
},
babel(defaults) {
const presetEnvSettings = defaults.presets[0][1];
presetEnvSettings.exclude = presetEnvSettings.exclude || [];
presetEnvSettings.exclude.push('@babel/plugin-transform-typeof-symbol');
return defaults;
}
};
if (CI_TEST_TYPE === 'playback' || CI_TEST_TYPE === 'playback-min') {
options.testInput = 'test/playback.test.js';
} else if (CI_TEST_TYPE === 'unit' || CI_TEST_TYPE === 'coverage') {
options.testInput = {include: ['test/**/*.test.js'], exclude: ['test/playback.test.js']};
}
const config = generate(options);
if (config.builds.browser) {
config.builds.syncWorkers = config.makeBuild('browser', {
output: {
name: 'httpStreaming',
format: 'umd',
file: 'dist/videojs-http-streaming-sync-workers.js'
}
});
config.builds.syncWorkers.plugins[0] = syncWorker;
}
// Add additonal builds/customization here!
// export the builds to rollup
export default Object.values(config.builds);