Skip to content

Commit

Permalink
refactor: ♻️ simplify rollup config
Browse files Browse the repository at this point in the history
  • Loading branch information
gingerbenw committed Oct 16, 2024
1 parent c95a023 commit 92fb17c
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 70 deletions.
25 changes: 18 additions & 7 deletions .rollup/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,30 @@ const defaultOptions = () => ({
output: undefined
})

const sharedOutput = {
dir: 'dist',
entryFileNames: '[name].js',
preserveModules: true,
generatedCode: {
preset: 'es2015',
}
}

function createRollupConfig (options = defaultOptions()) {
const packageJson = JSON.parse(fs.readFileSync(`${process.cwd()}/package.json`))

return {
input: options.input || 'src/index.ts',
output: options.output || {
dir: 'dist',
format: 'esm',
preserveModules: true,
generatedCode: {
preset: 'es2015',
output: options.output || [
{
...sharedOutput,
format: 'cjs'
},
{
...sharedOutput,
format: 'esm'
}
},
],
external: ['@bugsnag/core'].concat(options.external),
plugins: [
replace({
Expand Down
22 changes: 1 addition & 21 deletions packages/plugin-app-duration/rollup.config.npm.mjs
Original file line number Diff line number Diff line change
@@ -1,25 +1,5 @@
import createRollupConfig from '../../.rollup/index.mjs'

export default createRollupConfig({
input: 'src/app-duration.ts',
output: [
{
dir: `dist`,
entryFileNames: '[name].js',
format: 'cjs',
preserveModules: true,
generatedCode: {
preset: 'es2015',
}
},
{
dir: `dist`,
entryFileNames: '[name].mjs',
format: 'esm',
preserveModules: true,
generatedCode: {
preset: 'es2015',
}
}
]
input: 'src/app-duration.ts'
})
22 changes: 1 addition & 21 deletions packages/plugin-window-onerror/rollup.config.npm.mjs
Original file line number Diff line number Diff line change
@@ -1,25 +1,5 @@
import createRollupConfig from '../../.rollup/index.mjs'

export default createRollupConfig({
input: 'src/onerror.ts',
output: [
{
dir: `dist`,
entryFileNames: '[name].js',
format: 'cjs',
preserveModules: true,
generatedCode: {
preset: 'es2015',
}
},
{
dir: `dist`,
entryFileNames: '[name].mjs',
format: 'esm',
preserveModules: true,
generatedCode: {
preset: 'es2015',
}
}
]
input: 'src/onerror.ts'
})
22 changes: 1 addition & 21 deletions packages/plugin-window-unhandled-rejection/rollup.config.npm.mjs
Original file line number Diff line number Diff line change
@@ -1,25 +1,5 @@
import createRollupConfig from '../../.rollup/index.mjs'

export default createRollupConfig({
input: 'src/unhandled-rejection.ts',
output: [
{
dir: `dist`,
entryFileNames: '[name].js',
format: 'cjs',
preserveModules: true,
generatedCode: {
preset: 'es2015',
}
},
{
dir: `dist`,
entryFileNames: '[name].mjs',
format: 'esm',
preserveModules: true,
generatedCode: {
preset: 'es2015',
}
}
]
input: 'src/unhandled-rejection.ts'
})

0 comments on commit 92fb17c

Please sign in to comment.