forked from fullcalendar/fullcalendar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup.locales.js
120 lines (105 loc) · 3.13 KB
/
rollup.locales.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
119
120
const path = require('path')
const globby = require('globby')
const esbuild = require('rollup-plugin-esbuild').default
const { externalizeRelative } = require('./scripts/lib/new-rollup')
/*
needs locales-all to run first
compiles from *SRC* files.
we use sucrase to transpile the ts files.
normally we wouldn't use sucrase because it produces JS that's too advanced for the browsers we want to support,
but the locale files are simple so it'll be fine.
*/
let srcLocaleFiles = globby.sync('packages/core/src/locales/*.ts')
let bundleDirs = globby.sync('packages?(-premium)/bundle', { onlyDirectories: true })
let esbuildInstance = esbuild({
target: 'ie11',
})
module.exports = [
// locales-all.js, for CORE
{
input: 'packages/core/src/locales-all.ts',
output: {
format: 'cjs',
exports: 'named',
file: 'packages/core/locales-all.js'
},
plugins: [
externalizeRelative(), // resulting bundle will import the individual locales
dumbDownInputForIE11(),
esbuildInstance
]
},
// locales-all.js, for BUNDLES
{
input: 'packages/core/src/locales-all.ts',
output: bundleDirs.map((bundleDir) => ({
format: 'iife',
name: 'FullCalendar', // for bundleWrapLocalesAll
file: path.join(bundleDir, 'locales-all.js')
})).concat({
format: 'iife',
name: 'FullCalendar', // for bundleWrapLocalesAll
file: path.join('packages/core/locales-all.global.js') // FOR CORE
}),
plugins: [
dumbDownInputForIE11(),
esbuildInstance,
bundleWrapLocalesAll()
]
},
// locales/*.js, for CORE
...srcLocaleFiles.map((srcLocaleFile) => ({
input: srcLocaleFile,
output: {
format: 'cjs',
exports: 'named',
file: path.join('packages/core/locales', path.basename(srcLocaleFile, '.ts') + '.js')
},
plugins: [
dumbDownInputForIE11(),
esbuildInstance
]
})),
// locales/*.js, for BUNDLES
...srcLocaleFiles.map((srcLocaleFile) => ({
input: srcLocaleFile,
output: bundleDirs.map((bundleDir) => ({
format: 'iife',
name: 'FullCalendar', // for bundleWrapLocalesAll
file: path.join(bundleDir, 'locales', path.basename(srcLocaleFile, '.ts') + '.js')
})).concat({
format: 'iife',
name: 'FullCalendar', // for bundleWrapLocalesAll
file: path.join('packages/core/locales', path.basename(srcLocaleFile, '.ts') + '.global.js') // FOR CORE
}),
plugins: [
dumbDownInputForIE11(),
esbuildInstance,
bundleWrapLocalesEach()
]
}))
]
function bundleWrapLocalesAll() {
return {
renderChunk(code) {
return code.replace(/^var FullCalendar = \(/, '[].push.apply(FullCalendar.globalLocales, ') // needs to be by-reference. can't reassign
}
}
}
function bundleWrapLocalesEach() {
return {
renderChunk(code) {
return code.replace(/^var FullCalendar = /, 'FullCalendar.globalLocales.push')
}
}
}
// needs to go before esbuild
function dumbDownInputForIE11() {
return {
transform(code) {
code = code.replace(/\bconst\b/g, 'var')
code = code.replace(/(\w+)(\([\w:, ]*\)\s*{)/g, '$1: function$2')
return code
}
}
}