| 1 |
import babel from 'rollup-plugin-babel' |
| 2 |
import * as pkg from '../package.json' |
| 3 |
import filesize from 'rollup-plugin-filesize' |
| 4 |
// import { terser } from 'rollup-plugin-terser' |
| 5 |
import resolve from 'rollup-plugin-node-resolve' |
| 6 |
import commonjs from 'rollup-plugin-commonjs' |
| 7 |
import { uglify } from 'rollup-plugin-uglify' |
| 8 |
|
| 9 |
const buildDate = Date() |
| 10 |
|
| 11 |
const headerLong = `/*! |
| 12 |
* ${pkg.name} - ${pkg.description} |
| 13 |
* @version ${pkg.version} |
| 14 |
* ${pkg.homepage} |
| 15 |
* |
| 16 |
* @copyright ${pkg.author.name} |
| 17 |
* @license ${pkg.license} |
| 18 |
* |
| 19 |
* BUILT: ${buildDate} |
| 20 |
*/;` |
| 21 |
|
| 22 |
const headerShort = `/*! ${pkg.name} v${pkg.version} ${pkg.license}*/;` |
| 23 |
|
| 24 |
const getBabelConfig = (targets, corejs = false) => |
| 25 |
babel({ |
| 26 |
include: 'src/**', |
| 27 |
runtimeHelpers: true, |
| 28 |
babelrc: false, |
| 29 |
presets: [ |
| 30 |
[ |
| 31 |
'@babel/preset-env', |
| 32 |
{ |
| 33 |
modules: false, |
| 34 |
targets: targets || pkg.browserslist |
| 35 |
// useBuiltIns: 'usage' |
| 36 |
// corejs: 3 |
| 37 |
} |
| 38 |
] |
| 39 |
], |
| 40 |
plugins: [ |
| 41 |
['@babel/plugin-proposal-optional-chaining'], |
| 42 |
[ |
| 43 |
'@babel/plugin-proposal-nullish-coalescing-operator', |
| 44 |
{ |
| 45 |
loose: true |
| 46 |
} |
| 47 |
], |
| 48 |
[ |
| 49 |
'@babel/plugin-transform-runtime', |
| 50 |
{ |
| 51 |
corejs: corejs, |
| 52 |
helpers: true, |
| 53 |
useESModules: true |
| 54 |
} |
| 55 |
] |
| 56 |
] |
| 57 |
}) |
| 58 |
|
| 59 |
// When few of these get mangled nothing works anymore |
| 60 |
// We loose literally nothing by let these unmangled |
| 61 |
const classes = [] |
| 62 |
|
| 63 |
const config = (node, min, esm = false) => ({ |
| 64 |
external: ['@svgdotjs/svg.js'], |
| 65 |
input: 'src/svg.panzoom.js', |
| 66 |
output: { |
| 67 |
file: esm |
| 68 |
? './dist/svg.panzoom.esm.js' |
| 69 |
: node |
| 70 |
? './dist/svg.panzoom.node.js' |
| 71 |
: min |
| 72 |
? './dist/svg.panzoom.min.js' |
| 73 |
: './dist/svg.panzoom.js', |
| 74 |
format: esm ? 'esm' : node ? 'cjs' : 'iife', |
| 75 |
sourcemap: true, |
| 76 |
banner: headerLong, |
| 77 |
// remove Object.freeze |
| 78 |
freeze: false, |
| 79 |
globals: { |
| 80 |
'@svgdotjs/svg.js': 'SVG' |
| 81 |
} |
| 82 |
}, |
| 83 |
treeshake: { |
| 84 |
// property getter have no sideeffects |
| 85 |
propertyReadSideEffects: false |
| 86 |
}, |
| 87 |
plugins: [ |
| 88 |
resolve(), |
| 89 |
getBabelConfig(node && 'maintained node versions'), |
| 90 |
commonjs(), |
| 91 |
filesize(), |
| 92 |
!min |
| 93 |
? {} |
| 94 |
: uglify({ |
| 95 |
mangle: { |
| 96 |
reserved: classes |
| 97 |
}, |
| 98 |
output: { |
| 99 |
preamble: headerShort |
| 100 |
} |
| 101 |
}) |
| 102 |
] |
| 103 |
}) |
| 104 |
|
| 105 |
// [node, minified] |
| 106 |
const modes = [[false], [false, true], [false, false, true]] |
| 107 |
|
| 108 |
export default modes.map(m => config(...m)) |