Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deps: use rollup-plugin-node-externals #83

Merged
merged 1 commit into from
Jun 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
141 changes: 141 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
"react": "^17.0.2",
"react-dom": "^17.0.2",
"rollup": "^2.70.2",
"rollup-plugin-node-externals": "^4.0.0",
"rollup-plugin-terser": "^7.0.2",
"rollup-plugin-typescript2": "^0.31.2",
"ts-node": "^10.7.0",
Expand Down
23 changes: 3 additions & 20 deletions rollup.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { IPackageJson } from 'package-json-type'
import type { IsExternal, RollupOptions, OutputOptions } from 'rollup'
import type { RollupOptions, OutputOptions } from 'rollup'
import { externals } from 'rollup-plugin-node-externals'
import { nodeResolve } from '@rollup/plugin-node-resolve'
import commonjs from '@rollup/plugin-commonjs'
import { babel } from '@rollup/plugin-babel'
Expand All @@ -10,24 +11,6 @@ import packageJson from './package.json'

const pkgJson = packageJson as IPackageJson // coerce to the right type

// treat deps and peerDeps as externals -- don't bundle them
const depsList = [
...Object.keys(pkgJson.dependencies ?? []),
...Object.keys(pkgJson.peerDependencies ?? [])
]

// TODO: split this into a rollup plugin? submodule match is often missing
const isExternal: IsExternal = (id) => {
// simple case: exact match (ex: '@babel/runtime')
if (depsList.includes(id)) return true
// submodule match (ex: '@babel/runtime/helpers/get')
for (const dep of depsList) {
if (id.startsWith(dep)) return true
}
// otherwise false
return false
}

const outputDefaults: OutputOptions = {
// always provide a sourcemap for better debugging for consumers
sourcemap: true,
Expand Down Expand Up @@ -56,8 +39,8 @@ const configs: RollupOptions[] = [{
})],
...outputDefaults
}],
external: isExternal,
plugins: [
externals(), // https://github.com/Septh/rollup-plugin-node-externals#3-order-matters
nodeResolve(),
commonjs(),
babel({
Expand Down