forked from SVG-Edit/svgedit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
227 lines (218 loc) · 5.8 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
/* eslint-env node */
// NOTE:
// See rollup-config.config.js instead for building the main (configurable)
// user entrance file
import babel from 'rollup-plugin-babel';
import {terser} from 'rollup-plugin-terser';
import replace from 'rollup-plugin-re';
const {lstatSync, readdirSync} = require('fs'); // eslint-disable-line import/no-commonjs
const {join, basename} = require('path'); // eslint-disable-line import/no-commonjs
const localeFiles = readdirSync('editor/locale');
const extensionFiles = readdirSync('editor/extensions');
const isDirectory = (source) => {
return lstatSync(source).isDirectory();
};
const getDirectories = (source) => {
return readdirSync(source).map((nme) => join(source, nme)).filter((i) => isDirectory(i));
};
const extensionLocaleDirs = getDirectories('editor/extensions/ext-locale');
const extensionLocaleFiles = [];
extensionLocaleDirs.forEach((dir) => {
readdirSync(dir).forEach((file) => {
extensionLocaleFiles.push([dir, file]);
});
});
/**
* @external RollupConfig
* @type {PlainObject}
* @see {@link https://rollupjs.org/guide/en#big-list-of-options}
*/
/**
* @param {PlainObject} config
* @param {boolean} config.minifying
* @param {string} [config.format='umd'} = {}]
* @returns {external:RollupConfig}
*/
function getRollupObject ({minifying, format = 'umd'} = {}) {
const nonMinified = {
input: 'editor/svg-editor.js',
output: {
format,
sourcemap: minifying,
file: `dist/index-${format}${minifying ? '.min' : ''}.js`,
name: 'svgEditor'
},
plugins: [
babel({
plugins: ['transform-object-rest-spread']
})
]
};
if (minifying) {
nonMinified.plugins.push(terser());
}
return nonMinified;
}
// For debugging
// getRollupObject; // eslint-disable-line no-unused-expressions
export default [
// The first four are for those not using our HTML (though
// not currently recommended)
/**/
getRollupObject(),
getRollupObject({minifying: true}),
getRollupObject({minifying: true, format: 'es'}),
getRollupObject({minifying: false, format: 'es'}),
// **/
...[true, false].map((min) => {
return {
input: 'editor/svgcanvas.js',
output: {
format: 'iife',
sourcemap: min,
name: 'SvgCanvas',
file: `dist/svgcanvas-iife${min ? '.min' : ''}.js`
},
plugins: [
babel({
plugins: ['transform-object-rest-spread']
}),
min ? terser() : null
]
};
}),
...extensionLocaleFiles.map(([dir, file]) => {
const lang = file.replace(/\.js$/, '').replace(/-/g, '_');
return {
input: join(dir, file),
output: {
format: 'iife',
name: `svgEditorExtensionLocale_${basename(dir)}_${lang}`,
file: `dist/extensions/ext-locale/${basename(dir)}/${file}`
},
plugins: [babel()]
};
}),
{
input: 'editor/redirect-on-lacking-support.js',
output: {
format: 'iife',
file: `dist/redirect-on-lacking-support.js`
},
plugins: [babel()]
},
{
input: 'editor/jspdf/jspdf.plugin.svgToPdf.js',
output: {
format: 'iife',
file: `dist/jspdf.plugin.svgToPdf.js`
},
plugins: [babel()]
},
{
input: 'editor/extensions/imagelib/index.js',
output: {
format: 'iife',
file: 'dist/extensions/imagelib/index.js'
},
plugins: [
babel({
plugins: ['transform-object-rest-spread']
})
]
},
{
input: 'editor/extensions/imagelib/openclipart.js',
output: {
format: 'iife',
file: 'dist/extensions/imagelib/openclipart.js'
},
plugins: [
babel({
plugins: ['transform-object-rest-spread']
})
]
},
{
input: 'editor/external/dom-polyfill/dom-polyfill.js',
output: {
format: 'iife',
file: 'dist/dom-polyfill.js'
},
plugins: [babel()]
},
{
input: 'editor/canvg/canvg.js',
output: {
format: 'iife',
name: 'canvg',
file: 'dist/canvg.js'
},
plugins: [babel()]
},
...localeFiles.map((localeFile) => {
// lang.*.js
const localeRegex = /^lang\.([\w-]+?)\.js$/;
const lang = localeFile.match(localeRegex);
if (!lang) {
return undefined;
}
return {
input: 'editor/locale/' + localeFile,
output: {
format: 'iife',
name: 'svgEditorLang_' + lang[1].replace(/-/g, '_'),
file: 'dist/locale/' + localeFile
},
plugins: [
// Probably don't need here, but...
babel()
]
};
}),
...extensionFiles.map((extensionFile) => {
// ext-*.js
const extensionName = extensionFile.match(/^ext-(.+?)\.js$/);
if (!extensionName) {
return undefined;
}
return {
input: 'editor/extensions/' + extensionFile,
output: {
format: 'iife',
name: 'svgEditorExtension_' + extensionName[1].replace(/-/g, '_'),
file: 'dist/extensions/' + extensionFile
},
plugins: [
replace({
patterns: [
/*
// In place of replacing imports with globals, we supply
// what we can to the extension callback in svgcanvas.js
// (`addExtension` -> `getPrivateMethods`)
{
match: /editor\/extensions/,
test: '// <CONDITIONAL-ADD>: ',
replace: ''
},
*/
...[
// For now, we'll replace with globals
// We'll still make at least one import: editor/ext-locale/storage/
`import '../svgpathseg.js';`
].map((tst) => {
return {
match: /editor\/extensions/,
test: tst,
replace: ''
};
})
]
}),
babel({
plugins: ['transform-object-rest-spread']
})
]
};
})
].filter((exp) => exp);