-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrollup.config.js
87 lines (77 loc) · 2.65 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
import svelte from 'rollup-plugin-svelte';
import resolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';
//import livereload from 'rollup-plugin-livereload';
import { terser } from 'rollup-plugin-terser';
import json from 'rollup-plugin-json';
//import localResolve from 'rollup-plugin-local-resolve';
import filesize from 'rollup-plugin-filesize';
const path = require('path');
const fs = require('fs');
const production = !process.env.ROLLUP_WATCH;
function createPluginsArray(modulename, make_custom_component, use_commonjs) {
return [
svelte({
dev: !production,
// css: css => {
// css.write('./static/css/svelte.css');
// },
customElement: make_custom_component,
//tag: "ui-" + modulename
}),
resolve({
modulesOnly: false,
mainFields: ["module", "main", "browser"],
dedupe: importee => importee === 'svelte' || importee.startsWith('svelte/') ||
importee === 'firebase' || importee.startsWith('firebase/') ||
importee === '@firebase' || importee.startsWith('@firebase/') ||
importee === 'firebaseui' || importee.startsWith('firebaseui/')
}),
json({
preferConst: true,
compact: true,
namedExports: false
}),
use_commonjs && commonjs(),
//terser({module:true,ecma:8}),
filesize()
];
}
function createConfig(modulename, inputfile, make_custom_component = false, use_commonjs = false) {
return {
input: `${inputfile}`,
output: [
{
file: `./static/js/cmp/${modulename}.js`,
format: 'esm',
sourcemap: true,
},
],
external: [
'/js/cmp/userdata.js', '/js/cmp/ui-firebaseui.js', '/js/fuse.min.js'
],
watch: {
clearScreen: false,
exclude: 'node_modules/**|*.map'
},
plugins: createPluginsArray(modulename, make_custom_component, use_commonjs),
};
};
const directoryPath = path.join(__dirname, 'assets/js');
const configs = fs.readdirSync(directoryPath).reduce(function (list, filename) {
const absFilepath = path.join(directoryPath, filename);
const isDir = fs.statSync(absFilepath).isDirectory();
const indexFile = path.join(absFilepath, "index.js");
const use_commonjs = fs.existsSync(path.join(absFilepath, "pre_module_transpile"));
if (use_commonjs) console.log("Using Commonjs for ", path);
if (isDir && fs.existsSync(indexFile)) {
return list.concat(createConfig(filename, indexFile, false, use_commonjs));
}
const svelteFile = path.join(absFilepath, "index.svelte");
if (isDir && fs.existsSync(svelteFile)) {
const make_custom_component = fs.existsSync(path.join(absFilepath, "custom_component"));
return list.concat(createConfig(filename, svelteFile, make_custom_component, use_commonjs));
}
return list;
}, []);
export default configs;