forked from deriv-com/webtrader-charts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
136 lines (122 loc) · 3.3 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
import { readFileSync } from 'fs';
import { extname } from 'path';
import { createFilter } from 'rollup-pluginutils';
import postcss from 'rollup-plugin-postcss';
import cssnano from 'cssnano';
import sass from 'node-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 html from 'rollup-plugin-html';
import inliner from 'sass-inline-svg';
import uglify from 'rollup-plugin-uglify';
const preprocessor = (content, id) => new Promise((resolve, reject) => {
sass.render({
file: id,
functions: {
svg: inliner('./src', { }),
'inline-svg': inliner('./src', { })
}
}, (err, result) => {
if(err) { reject(err); return; }
resolve({
code: result.css.toString('utf-8'),
});
});
});
export default {
input: 'src/index.js',
output: {
file: './dist/webtrader-charts.js',
// file: './example/node_modules/webtrader-charts/dist/webtrader-charts.js',
// file: '../webtrader/node_modules/@binary-com/webtrader-charts/dist/webtrader-charts.js',
// file: '../binary-static/node_modules/@binary-com/webtrader-charts/dist/webtrader-charts.js',
format: 'umd',
name: 'WebtraderCharts',
},
plugins: [
image(),
postcss({
preprocessor,
extensions: ['.scss'],
plugins: [cssnano({ preset: [
'default',
{
mergeLonghand: false
}
]
})]
}),
json(),
html({
include: '**/*.html'
}),
babel({
exclude: 'node_modules/**',
presets: [ [ "es2015", { "modules": false } ] ],
plugins: [ "lodash" ],
externalHelpers: false,
babelrc: false
}),
nodeResolve({
jsnext: true,
main: true
}),
commonjs({
include: 'node_modules/**',
exclude: [],
sourceMap: false,
}),
uglify(),
],
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: '' } };
}
};
}