-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathrollup.config.mjs
144 lines (131 loc) · 3.63 KB
/
rollup.config.mjs
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
import { readFileSync } from "fs";
import { extname } from "path";
import { createFilter } from "rollup-pluginutils";
import postcss from "rollup-plugin-postcss";
import cssnano from "cssnano";
import * as sass from "sass";
import json from "@rollup/plugin-json";
import babel from "@rollup/plugin-babel";
import commonjs from "@rollup/plugin-commonjs";
import nodeResolve from "@rollup/plugin-node-resolve";
import string from "@bkuri/rollup-plugin-string";
import svg from "sass-svg-inline";
import terser from "@rollup/plugin-terser";
import pluginImage from "@rollup/plugin-image";
export default {
input: "src/index.js",
output: {
file: "./dist/webtrader-charts.js",
// file: './example/node_modules/@deriv-com/webtrader-charts/dist/webtrader-charts.js',
// file: '../webtrader/node_modules/@deriv-com/webtrader-charts/dist/webtrader-charts.js',
// file: '../binary-static/node_modules/@deriv-com/webtrader-charts/dist/webtrader-charts.js',
format: "umd",
name: "WebtraderCharts",
},
plugins: [
pluginImage(),
image(),
postcss({
extensions: [".scss"],
plugins: [
cssnano({
preset: [
"default",
{
mergeLonghand: false,
},
],
}),
],
}),
scssProcessor(),
json(),
string({
include: ["**/*.html"],
}),
babel({
exclude: "node_modules/**",
presets: ["@babel/preset-env"],
babelrc: false,
babelHelpers: "bundled",
}),
nodeResolve({
jsnext: true,
main: true,
}),
commonjs({
include: "node_modules/**",
exclude: [],
sourceMap: false,
}),
terser(),
],
watch: {
include: "src/**",
},
external: [
"highstock-release/highstock",
"highstock-release/highcharts-more",
"highstock-release/modules/exporting",
"highstock-release/modules/offline-exporting",
"jquery",
"moment",
],
globals: {
"highstock-release/highstock": "Highcharts",
"highstock-release/highcharts-more": "HighchartsMore",
"highstock-release/modules/exporting": "HighchartsExporting",
"highstock-release/modules/offline-exporting": "HighcartsOfflineExporting",
jquery: "jQuery",
moment: "moment",
},
};
function image(options) {
options = options || {};
const mimeTypes = {
".jpg": "image/jpeg",
".jpeg": "image/jpeg",
".png": "image/png",
".gif": "image/gif",
".svg": "image/svg+xml",
};
const filter = createFilter(options.include, options.exclude);
return {
name: "image",
load(id) {
if (!filter(id)) return null;
const mime = mimeTypes[extname(id)];
if (!mime) return null; // not an image
const data = readFileSync(id, "base64");
// const code = `var img = new Image(); img.src = 'data:${mime};base64,${data}'; export default img;`;
const code = `var img = 'data:${mime};base64,${data}'; export default img;`;
const ast = {
type: "Program",
sourceType: "module",
start: 0,
end: null,
body: [],
};
return { ast, code, map: { mappings: "" } };
},
};
}
function scssProcessor(options) {
options = options || {};
const filter = createFilter(options.include, options.exclude);
return {
name: "scss",
load(id) {
if (!filter(id)) return null;
if (!id.endsWith(".scss")) return null;
let result = sass.renderSync({
file: id,
functions: {
"svg($path)": svg.setDir("./src"),
"inline-svg($path)": svg.setDir("./src"),
},
});
return { code: result.css.toString("utf-8"), map: { mappings: "" } };
},
};
}