|
| 1 | +import json from '@rollup/plugin-json'; |
| 2 | +import babel from '@rollup/plugin-babel'; |
| 3 | +import nodePolyfills from 'rollup-plugin-polyfill-node'; |
| 4 | +import pkg from './package.json'; |
| 5 | + |
| 6 | +const cjs = { |
| 7 | + exports: 'named', |
| 8 | + format: 'cjs', |
| 9 | +}; |
| 10 | + |
| 11 | +const esm = { |
| 12 | + format: 'es', |
| 13 | +}; |
| 14 | + |
| 15 | +const getCJS = override => Object.assign({}, cjs, override); |
| 16 | +const getESM = override => Object.assign({}, esm, override); |
| 17 | + |
| 18 | +const input = 'index.js'; |
| 19 | + |
| 20 | +const babelConfig = ({ browser }) => ({ |
| 21 | + babelrc: false, |
| 22 | + babelHelpers: 'runtime', |
| 23 | + exclude: 'node_modules/**', |
| 24 | + presets: [ |
| 25 | + [ |
| 26 | + '@babel/preset-env', |
| 27 | + { |
| 28 | + loose: true, |
| 29 | + modules: false, |
| 30 | + targets: { node: '12', browsers: 'last 2 versions' }, |
| 31 | + }, |
| 32 | + ], |
| 33 | + ], |
| 34 | + plugins: [['@babel/plugin-transform-runtime', { version: '^7.16.4' }]], |
| 35 | +}); |
| 36 | + |
| 37 | +const getExternal = () => [ |
| 38 | + ...(Object.keys(pkg.dependencies)), |
| 39 | +]; |
| 40 | + |
| 41 | +const getPlugins = ({ browser }) => [ |
| 42 | + json(), |
| 43 | + babel(babelConfig({ browser })), |
| 44 | + ...(browser ? [ nodePolyfills({ include: [ /unicode-properties\/index\.js/, /polyfill/ ] }) ] : []), |
| 45 | +]; |
| 46 | + |
| 47 | +const serverConfig = { |
| 48 | + input, |
| 49 | + output: [ |
| 50 | + getESM({ file: 'lib/unicode-properties.es.js' }), |
| 51 | + getCJS({ file: 'lib/unicode-properties.cjs.js' }), |
| 52 | + ], |
| 53 | + external: getExternal(), |
| 54 | + plugins: getPlugins({ browser: false }), |
| 55 | +}; |
| 56 | + |
| 57 | +const browserConfig = { |
| 58 | + input, |
| 59 | + output: [ |
| 60 | + getESM({ file: 'lib/unicode-properties.browser.es.js' }), |
| 61 | + getCJS({ file: 'lib/unicode-properties.browser.cjs.js' }), |
| 62 | + ], |
| 63 | + external: getExternal(), |
| 64 | + plugins: getPlugins({ browser: true }), |
| 65 | +}; |
| 66 | + |
| 67 | +export default [serverConfig, browserConfig]; |
0 commit comments