-
Notifications
You must be signed in to change notification settings - Fork 65
Expand file tree
/
Copy pathrollup.config.js
More file actions
102 lines (99 loc) · 3.22 KB
/
rollup.config.js
File metadata and controls
102 lines (99 loc) · 3.22 KB
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
const typescript = require("@rollup/plugin-typescript");
const nodeResolve = require("@rollup/plugin-node-resolve");
const commonjs = require("@rollup/plugin-commonjs");
const replace = require("@rollup/plugin-replace");
const bannerPlugin = require("rollup-plugin-license");
const path = require("path");
const svgLoader = require("svg-inline-loader");
const fg = require("fast-glob");
const readFile = require("fs").readFileSync;
const VERSION = require("./package.json").version;
const banner = [
"surveyjs - SurveyJS Dashboard library v" + VERSION,
"Copyright (c) 2015-" + new Date().getFullYear() + " Devsoft Baltic OÜ - http://surveyjs.io/",
"License: MIT (http://www.opensource.org/licenses/mit-license.php)",
].join("\n");
const input = {
"survey.analytics": path.resolve(__dirname, "./src/entries/summary.ts"),
"survey.analytics.core": path.resolve(__dirname, "./src/entries/summary.core.ts"),
"survey.analytics.mongo": path.resolve(__dirname, "./src/entries/mongo.ts"),
"survey.analytics.tabulator": path.resolve(__dirname, "./src/entries/tabulator-es.ts"),
};
module.exports = (options) => {
options = options ?? {};
if(!options.tsconfig) {
options.tsconfig = path.resolve(__dirname, "./tsconfig.fesm.json");
}
if(!options.dir) {
options.dir = path.resolve(__dirname, "./build/fesm");
}
return {
input,
context: "this",
plugins: [
{
name: "icons",
resolveId: (id) => {
if (id === "icons") {
return id;
}
},
load: async (id) => {
if (id === "icons") {
const icons = {};
for (const iconPath of await fg.glob(fg.convertPathToPattern(path.resolve(__dirname, "./src/images")) + "/*.svg")) {
icons[path.basename(iconPath).replace(/\.svg$/, "").toLocaleLowerCase()] = svgLoader.getExtractedSVG(readFile(iconPath).toString());
}
return `export default ${JSON.stringify(icons, undefined, "\t")}`;
}
}
},
{
name: "remove-scss-imports",
load: (id) => {
if(id.match(/\.scss$/)) return "";
}
},
nodeResolve(),
commonjs(),
typescript({ inlineSources: true, sourceMap: true, tsconfig: options.tsconfig, compilerOptions: {
declaration: false,
declarationDir: null
} }),
replace({
preventAssignment: false,
values: {
"process.env.RELEASE_DATE": JSON.stringify(new Date().toISOString().slice(0, 10)),
"process.env.VERSION": JSON.stringify(VERSION),
}
}),
bannerPlugin({
banner: {
content: banner,
commentStyle: "ignored",
}
})
],
external: [
"survey-core",
"plotly.js-dist-min",
"tabulator-tables",
"mongodb"
],
output: [
{
preserveModules: false,
dir: options.dir,
entryFileNames: "[name].mjs",
chunkFileNames: (chunkInfo) => {
if(!chunkInfo.isEntry) {
return "shared.mjs"
}
},
format: "esm",
exports: "named",
sourcemap: true,
},
],
};
};