@@ -4,6 +4,7 @@ import nodeResolve from 'rollup-plugin-node-resolve';
4
4
import json from 'rollup-plugin-json' ;
5
5
import commonjs from 'rollup-plugin-commonjs' ;
6
6
import babel from 'rollup-plugin-babel' ;
7
+ import minify from 'rollup-plugin-babel-minify' ;
7
8
8
9
import pkg from '../package.json' ;
9
10
@@ -27,7 +28,7 @@ const external = Object.keys(pkg.peerDependencies) || [];
27
28
/**
28
29
* @type {Plugin[] }
29
30
*/
30
- const plugins = /** @type {Plugin[] } */ ( [
31
+ const defaultPlugins = /** @type {Plugin[] } */ ( [
31
32
json ( ) ,
32
33
commonjs ( ) ,
33
34
// Allow node_modules resolution. Use 'external' to control
@@ -42,30 +43,64 @@ const plugins = /** @type {Plugin[]} */ ([
42
43
{
43
44
// Transformation of ES6 module syntax to another module type
44
45
modules : false ,
46
+ // How to handle polyfills, 'usage' analyses each file and places the
47
+ // required imports on each one, rollup ensures single imports
48
+ useBuiltIns : 'usage' ,
45
49
targets : {
46
- ie : '10' ,
50
+ // To check what's covered: https://browserl.ist
51
+ browsers : [
52
+ '>0.1%' ,
53
+ 'ie>=10' ,
54
+ 'not ie<10' ,
55
+ 'not ios_saf<9' ,
56
+ 'not android<5' ,
57
+ ] ,
47
58
} ,
48
59
} ,
49
60
] ,
50
61
] ,
62
+ // To avoiding circular dependencies with useBuiltIns: 'usage' these two
63
+ // settings are needed, which avoids core-js importing itself
64
+ sourceType : 'unambiguous' ,
65
+ ignore : [ / \/ c o r e - j s / ] ,
51
66
} ) ,
52
67
] ) ;
53
68
54
69
/**
55
- * @type { Config }
70
+ * @param { {outputFile: string, extraPlugins?: Plugin[]} } options
56
71
*/
57
- const umdConfig = {
72
+ const createUmdConfig = ( { outputFile , extraPlugins } ) => ( {
58
73
inlineDynamicImports : true ,
59
74
external,
60
75
// Start with esm5 (es5 with import/export)
61
76
input : resolve ( dist , 'esm5' , 'index.js' ) ,
62
77
output : {
63
- file : pkg . main ,
78
+ file : outputFile ,
64
79
format : 'umd' ,
65
80
name : pkg . config . umdName ,
66
81
sourcemap : true ,
67
82
} ,
68
- plugins,
69
- } ;
83
+ plugins : [ ... defaultPlugins , ... ( extraPlugins || [ ] ) ] ,
84
+ } ) ;
70
85
71
- export default [ umdConfig ] ;
86
+ /**
87
+ * @type object
88
+ */
89
+ const umdConfig = createUmdConfig ( {
90
+ outputFile : pkg . main ,
91
+ } ) ;
92
+
93
+ /**
94
+ * @type object
95
+ */
96
+ const umdConfigMin = createUmdConfig ( {
97
+ outputFile : pkg . mainMin ,
98
+ extraPlugins : [
99
+ minify ( {
100
+ comments : false ,
101
+ sourceMap : true ,
102
+ } ) ,
103
+ ] ,
104
+ } ) ;
105
+
106
+ export default [ umdConfig , umdConfigMin ] ;
0 commit comments