forked from windycom/windy-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup.js
46 lines (41 loc) · 1.63 KB
/
rollup.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
import path from 'node:path';
import { rollup } from 'rollup';
import rollupNodeResolve from '@rollup/plugin-node-resolve';
import rollupCommonjs from '@rollup/plugin-commonjs';
import rollupTerser from '@rollup/plugin-terser';
import rollupCleanup from 'rollup-plugin-cleanup';
import { getBabelOutputPlugin as rollupBabel } from '@rollup/plugin-babel';
import { buildPluginsHtml, buildPluginsCss, transformToPlugin } from './rollup-plugins.js';
export const builder = async function (id, srcDir, meta) {
const bundle = await rollup({
input: path.join(srcDir, 'plugin.js'),
output: { format: 'es', name: id },
external: moduleId => moduleId.startsWith('@windy/') || moduleId.startsWith('@plugins/'),
plugins: [
buildPluginsHtml(),
buildPluginsCss(),
rollupNodeResolve({
mainFields: ['module', 'jsnext:main', 'main'],
browser: true,
preferBuiltins: false,
}),
rollupCommonjs(),
rollupCleanup({ comments: 'none' }),
rollupBabel({
presets: [['@babel/preset-env', { targets: 'defaults', modules: false }]],
allowAllFormats: true,
compact: false,
}),
transformToPlugin(meta),
rollupTerser({
mangle: true,
ecma: 5,
compress: { ecma: 5 },
}),
],
});
const { output } = await bundle.generate({ format: 'es', name: id });
const code = output[0].code;
const map = output[0].map;
return { code, map, watchFiles: bundle.watchFiles };
};