forked from SVG-Edit/svgedit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup.config.js
195 lines (188 loc) · 4.87 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
/* 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 {uglify} from 'rollup-plugin-uglify';
import {minify} from 'uglify-es';
import replace from 'rollup-plugin-re';
const {lstatSync, readdirSync} = require('fs');
const localeFiles = readdirSync('editor/locale');
const extensionFiles = readdirSync('editor/extensions');
const {join, basename} = require('path');
const isDirectory = (source) => {
return lstatSync(source).isDirectory();
};
const getDirectories = (source) => {
return readdirSync(source).map(name => join(source, name)).filter(isDirectory);
};
const extensionLocaleDirs = getDirectories('editor/extensions/ext-locale');
const extensionLocaleFiles = [];
extensionLocaleDirs.forEach((dir) => {
readdirSync(dir).forEach((file) => {
extensionLocaleFiles.push([dir, file]);
});
});
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(uglify(null, minify));
}
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'}),
// **/
...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/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;
}
return {
input: 'editor/locale/' + localeFile,
output: {
format: 'iife',
name: 'svgEditorLang_' + lang[1].replace(/-/g, '_'),
file: 'dist/locale/' + localeFile
},
plugins: [
babel() // Probably don't need here, but...
]
};
}),
...extensionFiles.map((extensionFile) => {
// ext-*.js
const extensionName = extensionFile.match(/^ext-(.+?)\.js$/);
if (!extensionName) {
return;
}
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((test) => {
return {
match: /editor\/extensions/,
test,
replace: ''
};
})
]
}),
babel({
plugins: ['transform-object-rest-spread']
})
]
};
})
].filter((exp) => exp);