Skip to content

Commit 7be7f10

Browse files
package: Add polyfill and minification (#11)
1 parent ef0403e commit 7be7f10

File tree

4 files changed

+349
-9
lines changed

4 files changed

+349
-9
lines changed

config/global.d.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,17 @@ declare module 'rollup-plugin-terser' {
5353
declare module 'rollup-plugin-babel' {
5454
export interface Options {
5555
presets?: string | (string | object)[][];
56+
sourceType?: string;
57+
ignore?: RegExp[];
5658
}
5759
const plugin: RollupPluginImpl<Options>;
5860
export default plugin;
5961
}
62+
declare module 'rollup-plugin-babel-minify' {
63+
export interface Options {}
64+
const plugin: RollupPluginImpl<Options>;
65+
export default plugin;
66+
}
6067

6168
// =====================∫
6269
// missing library types

config/rollup.config.js

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import nodeResolve from 'rollup-plugin-node-resolve';
44
import json from 'rollup-plugin-json';
55
import commonjs from 'rollup-plugin-commonjs';
66
import babel from 'rollup-plugin-babel';
7+
import minify from 'rollup-plugin-babel-minify';
78

89
import pkg from '../package.json';
910

@@ -27,7 +28,7 @@ const external = Object.keys(pkg.peerDependencies) || [];
2728
/**
2829
* @type {Plugin[]}
2930
*/
30-
const plugins = /** @type {Plugin[]} */ ([
31+
const defaultPlugins = /** @type {Plugin[]} */ ([
3132
json(),
3233
commonjs(),
3334
// Allow node_modules resolution. Use 'external' to control
@@ -42,30 +43,64 @@ const plugins = /** @type {Plugin[]} */ ([
4243
{
4344
// Transformation of ES6 module syntax to another module type
4445
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',
4549
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+
],
4758
},
4859
},
4960
],
5061
],
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: [/\/core-js/],
5166
}),
5267
]);
5368

5469
/**
55-
* @type {Config}
70+
* @param {{outputFile: string, extraPlugins?: Plugin[]}} options
5671
*/
57-
const umdConfig = {
72+
const createUmdConfig = ({ outputFile, extraPlugins }) => ({
5873
inlineDynamicImports: true,
5974
external,
6075
// Start with esm5 (es5 with import/export)
6176
input: resolve(dist, 'esm5', 'index.js'),
6277
output: {
63-
file: pkg.main,
78+
file: outputFile,
6479
format: 'umd',
6580
name: pkg.config.umdName,
6681
sourcemap: true,
6782
},
68-
plugins,
69-
};
83+
plugins: [...defaultPlugins, ...(extraPlugins || [])],
84+
});
7085

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

Comments
 (0)