Skip to content

Commit

Permalink
fix: rollup config
Browse files Browse the repository at this point in the history
  • Loading branch information
pablo1v committed Mar 7, 2021
1 parent 3aacbcb commit edab9aa
Showing 1 changed file with 47 additions and 24 deletions.
71 changes: 47 additions & 24 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,63 @@ import typescript from '@rollup/plugin-typescript';

import pkg from './package.json';

/**
* @type {import('rollup').Plugin[]}
*/
const basePlugins = [
nodeResolve(),
commonjs(),
babel({ babelHelpers: 'bundled' }),
];

/**
* @type {import('rollup').RollupOptions}
*/
const config = {
input: ['src/index.ts', 'src/Provider.tsx'],
const baseOptions = {
external: getExternal(),
output: [
{
plugins: [makeTypeScriptPlugin(), ...basePlugins],
};

/**
* @type {import('rollup').RollupOptions[]}
*/
const config = [
{
input: 'src/index.ts',
output: {
format: 'cjs',
dir: 'dist',
file: 'dist/index.js',
sourcemap: true,
},
{
format: 'esm',
dir: 'dist',
sourcemap: true,
entryFileNames: makeEntryFileNames('esm'),
},
],
plugins: [
typescript({
rootDir: 'src',
include: ['**/*'],
}),
nodeResolve(),
commonjs(),
babel({ babelHelpers: 'bundled' }),
],
};
},
{
input: 'src/Provider.tsx',
plugins: [makeTypeScriptPlugin({ outDir: 'provider' }), basePlugins],
output: [
{
format: 'cjs',
file: 'provider/index.js',
sourcemap: true,
},
{
format: 'esm',
file: 'provider/index.esm.js',
sourcemap: true,
},
],
},
].map(cfg => ({ ...baseOptions, ...cfg }));

function makeEntryFileNames(extension) {
return info => `${info.name}.${extension}.js`;
/**
* @param {import('@rollup/plugin-typescript').RollupTypescriptOptions} options
* @return {import('rollup').Plugin}
*/
function makeTypeScriptPlugin(options = {}) {
return typescript({ rootDir: 'src', include: ['**/*'], ...options });
}

//

function makeExternalPredicate(externalArray) {
if (!externalArray.length) return () => false;

Expand Down

0 comments on commit edab9aa

Please sign in to comment.