-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrollup.config.js
98 lines (94 loc) · 2.31 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
import resolve from '@rollup/plugin-node-resolve';
import terser from '@rollup/plugin-terser';
const typo3Exports = [
'autosize',
'bootstrap',
'broadcastchannel.js',
'cropperjs',
'd3-dispatch',
'd3-drag',
'd3-selection',
'ev-emitter',
'imagesloaded',
'interactjs',
'jquery',
'@lit/reactive-element',
'lit',
'lit-element',
'lit-html',
'moment',
'moment-timezone',
'nprogress',
'sortablejs',
'tablesort.dotsep.js',
'tablesort',
'taboverride',
];
const typo3Prefixes = [
'@typo3/',
'@lit/reactive-element/',
'lit/',
'lit-element/',
'lit-html/',
'flatpickr/',
];
const lowerDashedToUpperCamelCase = (str) => str.replace(/([-\/])([a-z])/g, (_str, sep, letter) => (sep === '/' ? '/' : '') + letter.toUpperCase());
export function typo3Resolve() {
return {
name: 'typo3Resolve',
resolveId(id) {
const external = true
for (const exportName of typo3Exports) {
if (id === exportName) {
return { id, external }
}
}
for (const exportPrefix of typo3Prefixes) {
if (id.startsWith(exportPrefix)) {
if (!id.endsWith('.js')) {
id += '.js'
}
return { id, external }
}
}
},
renderChunk(code, chunk, outputOptions) {
if (outputOptions.format !== 'amd') {
return;
}
// Resolve "@typo3/ext-name/module-name.js" into "TYPO3/CMS/ExtName/ModuleName" for TYPO3 v11 (AMD) builds
return code.replace(
/(["'])@typo3\/([^\/]+)\/([^"']+)\.js\1/g,
(match, quotes, extension, path) => lowerDashedToUpperCamelCase(`${quotes}TYPO3/CMS/${extension}/${path}${quotes}`)
)
}
}
}
export default {
input: [
'./Build/src/AlternativeGenerator.js',
'./Build/src/CreditsViewHelper.js',
'./Build/src/AjaxMetaGenerate.js',
'./Build/src/ContextMenuActions.js',
],
output: [
{
dir: './Resources/Public/JavaScript/ECMAScript6',
format: 'es',
plugins: [terser()]
},
{
dir: './Resources/Public/JavaScript/Amd',
entryFileNames: (chunkInfo) => lowerDashedToUpperCamelCase('/' + chunkInfo.name).substring(1) + '.js',
format: 'amd',
plugins: [terser()]
},
],
plugins: [
typo3Resolve(),
resolve({
mainFields: ['module', 'main'],
modulesOnly: true
}),
],
}