-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
rollup.config.js
110 lines (99 loc) · 3.21 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 glob from 'glob';
import { nodeResolve } from '@rollup/plugin-node-resolve';
import polyfill from 'rollup-plugin-polyfill';
import path from 'path';
import fs from 'fs';
import { createRequire } from "module";
export const root = './src';
const resolvePath = (f) => path.resolve(f);
const isBundle = (name) => /["']bundle all["'];/.test(fs.readFileSync(`${root}/${name}`).toString());
export const removeBundle = (name) => ((bundle) => !bundle.includes(name));
export const files = glob.sync('kendo.*.js', { cwd: root });
export const thirdParty = ['jquery', 'jquery.js', './jquery.js'];
export const externals = glob.sync(`${root}/kendo.*.js`).map(resolvePath).concat(thirdParty);
export const cultures = glob.sync('cultures/*.js', { cwd: root });
export const messages = glob.sync('messages/*.js', { cwd: root });
const require = createRequire(import.meta.url);
export const version = require('./build/gulp/kendo-version').version;
const globals = {
jquery: '$'
};
// Used only for the source code bundle.
const babelArg = process.argv.includes("--configBabel");
const babel = babelArg ? require('@rollup/plugin-babel') : null;
export function transformCodePlugin() {
return {
name: 'transform-kendo-modules',
renderChunk(code) {
code = code
.replace(/(\.+\/)+(kendo[\.\w]+)/gm, '$2');
return {
code: code
};
}
};
}
export function addKendoVersion() {
return {
name: 'transform-kendo-modules',
renderChunk(code) {
code = code
.replace(/\$KENDO_VERSION/gm, version);
return {
code: code
};
}
};
}
/**
* @type {import('rollup').OutputOptions}
*/
export const baseOptions = {
globals: globals,
strict: false
};
/**
* @type {import('rollup').RollupOptions}
*/
const resourcesConfig = (name, options = {}) => ({
input: `${root}/${name}`,
output: [{
format: "umd",
dir: `./dist/raw-js/${options.dir}`,
sourcemap: false,
...baseOptions
}],
external: ['../kendo.core.js'],
treeshake: false,
plugins: [
transformCodePlugin(),
addKendoVersion(),
polyfill(['../kendo.core.js']),
babel ? babel({ babelHelpers: 'bundled' }) : null // Used only for the source code bundle.
]
});
/**
* @type {import('rollup').RollupOptions}
*/
const configMap = (name) => ({
input: `${root}/${name}`,
output: [{
format: 'umd',
dir: './dist/raw-js',
sourcemap: false,
name: name.replace('.', ''),
...baseOptions
}],
external: isBundle(name) ? thirdParty : externals.filter(removeBundle(name)),
treeshake: false,
plugins: [
transformCodePlugin(),
addKendoVersion(),
name === 'kendo.core.js' || isBundle(name) ? polyfill(['jquery']) : null,
nodeResolve(),
babel ? babel({ babelHelpers: 'bundled' }) : null // Used only for the source code bundle.
]
});
export default files.map((name) => configMap(name))
.concat(cultures.map((name) => resourcesConfig(name, { dir: 'cultures' })))
.concat(messages.map((name) => resourcesConfig(name, { dir: 'messages' })));