Skip to content

Commit

Permalink
chore(rollup): 🤖 add mjs and cjs extensions & rename directories
Browse files Browse the repository at this point in the history
  • Loading branch information
apttx committed Jan 31, 2022
1 parent 450b2ff commit b2519e5
Showing 1 changed file with 31 additions and 33 deletions.
64 changes: 31 additions & 33 deletions rollup.config.mjs
Original file line number Diff line number Diff line change
@@ -1,37 +1,35 @@
import path from 'path'
import { babel } from '@rollup/plugin-babel'

const outputDir = 'dist'
const buildDir = 'dist'

export default {
external: [
'node-fetch',
'isomorphic-fetch',
'koa',
'koa-bodyparser',
'crypto',
'fs',
'path',
'os',
],
input: [
'src/lib/server.mjs',
'src/lib/swetch.mjs',
'src/lib/axiosInterceptor.mjs',
],
output: [
{
dir: 'esmodules',
format: 'esm',
},
{
dir: 'commonjs',
format: 'cjs',
const modules = ['server', 'swetch', 'axiosInterceptor']
const formats = [{ format: 'esm', extension: 'mjs' }, { format: 'cjs' }]

const config = formats.flatMap(({ format, extension = format }) =>
modules.map(moduleName => ({
external: [
'node-fetch',
'isomorphic-fetch',
'koa',
'koa-bodyparser',
'crypto',
'fs',
'path',
'os',
],
plugins: [
babel({
babelHelpers: 'bundled',
presets: ['@babel/preset-env'],
}),
],
input: `src/lib/${moduleName}.mjs`,
output: {
file: `${buildDir}/${format}/${moduleName}.${extension}`,
format,
exports: 'named',
},
].map(({ dir, ...output }) => ({
...output,
exports: 'named',
dir: path.join(outputDir, dir),
})),
plugins: [babel({ babelHelpers: 'bundled', presets: ['@babel/preset-env'] })],
}
}))
)

export default config

0 comments on commit b2519e5

Please sign in to comment.