-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrollup.config.js
220 lines (206 loc) · 5.09 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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
import resolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';
import built_ins from 'rollup-plugin-node-builtins';
import globals from 'rollup-plugin-node-globals';
import babel from 'rollup-plugin-babel';
import json from 'rollup-plugin-json';
import rollup_sass from 'rollup-plugin-sass';
import replace from 'rollup-plugin-replace';
import autoprefixer from 'autoprefixer';
import inline_svg from 'postcss-inline-svg';
import postcss from 'postcss';
import dbgFunc from 'debug';
/**
* debug function
*/
const dbg = dbgFunc('chunk-upload:rollup');
/**
* This is the function to run post css from the
* sass plug-in
* @param {*} css
* @param {*} id
*/
function run_postcss(css, id)
{
const options = {
from : id
};
const processor = postcss([autoprefixer, inline_svg()]);
return new Promise((resolve, reject) =>{
const lazy = processor.process(css, options);
lazy.then( (result) => {
//debugger;
resolve(result.css);
}).catch(error => { reject(error); });
});
}
/**
* This is the default sass configuration
* for inserting the css in the js bundle
*/
const sass_plugin = rollup_sass({
processor: run_postcss
, insert: true
//sass options
, options: {
functions: {
//'svg-load($value1)' : svg_inline
}
}
});
/**
* This is the configuration for outputting a processed
* css for who want to process the js himself but not the css
*/
const sass_plugin_css = rollup_sass({
processor : run_postcss
, insert : false
, output: 'lib/chunk-uploader.css'
, options: { indentWidth : 4 }
});
/**
* This is the plug-in to do some replace for
* better targeting the browser
*/
const resolve_plugin = replace ({
include: '**/httprequest.js'
, delimiters: ['', '']
, values : {
'const rq = require;' : 'const rq = undefined;'
, 'require(\'superagent-proxy\')(request);' : ''
}
});
/**
* Common Plugins
*/
const g_plugins = [
resolve({
preferBuiltins: true
, browser: true
})
, commonjs(
{
exclude: [ 'node_modules/superagent-proxy/**' ]
, ignore: ['superagent-proxy']
}
)
, built_ins()
, globals()
, json()
, babel({
include : ['src/**', 'node_modules/superagent/**']
//exclude: 'node_modules/**'
, babelrc: false
, presets: [['@babel/env', {
modules: false
, 'targets': {
'chrome': '58'
,'ie': '11'
}
, forceAllTransforms: true
, useBuiltIns: 'usage'
}]]
, plugins: ['@babel/plugin-transform-object-assign']
, env: {
test: {
plugins: [ 'istanbul' ]
}
}
//, externalHelpers: true
})
];
/**
* UI plugin
*/
let ui_plugins = [resolve_plugin, sass_plugin];
ui_plugins = ui_plugins.concat(g_plugins);
dbg('ui_plugins', ui_plugins.length);
/**
* The server side processing plugin
*/
const g_plugins_server = [
resolve_plugin
, commonjs()
, json()
, babel({
exclude: 'node_modules/**'
, babelrc: false
, presets: [['@babel/env', { modules: false }]]
, plugins: ['@babel/plugin-transform-object-assign']
})
];
const g_server_external = ['events', 'superagent', 'superagent-proxy'];
export default [
/**
* The client side browser module without UI
*/
{
external: []
, input: 'src/client.js'
, output:
{
file: 'lib/chunk-uploader.js'
, sourcemap: true
, format: 'iife'
, name: 'chunkupload'
, exports: 'named'
, globals: []
}
, plugins: g_plugins
}
/**
* The client side browser module with UI
*/
, {
external: []
, input: 'src/UI/index.js'
, output:
{
file: 'lib/chunk-uploader-ui.js'
, sourcemap: true
, format: 'iife'
, name: 'chunkuploadui'
, exports: 'named'
, globals: []
}
, plugins: ui_plugins
}
/**
* Transpiled version for node usage
*/
, {
external: g_server_external
, input: 'src/client.js'
, output:
{
file: 'lib/index.js'
, sourcemap: true
, format: 'cjs'
, exports: 'named'
, globals: []
}
, plugins: g_plugins_server
}
/**
* Transpiled version for node usage with UI
*/
,{
external: g_server_external
, input: 'src/UI/uploader.js'
, output:
{
file: 'lib/ui.js'
, sourcemap: true
, format: 'cjs'
, exports: 'named'
, globals: []
}
, plugins: g_plugins_server
}
,{
input: 'src/UI/style.js'
, plugins: [sass_plugin_css]
, output : {format: 'iife', name: 'style', file: 'lib/empty.js'}
}
,]
;