Skip to content

Commit

Permalink
Simplify external generation in rollup config
Browse files Browse the repository at this point in the history
  • Loading branch information
xty committed Mar 11, 2022
1 parent 7de767e commit ff328f3
Showing 1 changed file with 6 additions and 15 deletions.
21 changes: 6 additions & 15 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,17 @@ const babelRuntimeVersion = pkg.dependencies['@babel/runtime'].replace(
''
)

const makeExternalPredicate = externalArr => {
if (externalArr.length === 0) {
return () => false
}
const pattern = new RegExp(`^(${externalArr.join('|')})($|/)`)
return id => pattern.test(id)
}
const external = [
...Object.keys(pkg.dependencies || {}),
...Object.keys(pkg.peerDependencies || {})
].map(name => RegExp(`^${name}($|/)`))

export default defineConfig([
// CommonJS
{
input: 'src/index.ts',
output: { file: 'lib/redux.js', format: 'cjs', indent: false },
external: makeExternalPredicate([
...Object.keys(pkg.dependencies || {}),
...Object.keys(pkg.peerDependencies || {})
]),
external,
plugins: [
nodeResolve({
extensions
Expand All @@ -52,10 +46,7 @@ export default defineConfig([
{
input: 'src/index.ts',
output: { file: 'es/redux.js', format: 'es', indent: false },
external: makeExternalPredicate([
...Object.keys(pkg.dependencies || {}),
...Object.keys(pkg.peerDependencies || {})
]),
external,
plugins: [
nodeResolve({
extensions
Expand Down

0 comments on commit ff328f3

Please sign in to comment.