Skip to content

Externalized 3rd-party dependencies #192

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

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

oleksandr-danylchenko
Copy link
Contributor

@oleksandr-danylchenko oleksandr-danylchenko commented Feb 20, 2025

Issue

See - #191

⚠ When the text-annotator-react is being bundled, it doesn't exclude the external dependencies from the bundle ⚠

Changes Made

  1. Added vite-plugin-externalize-deps plugin that helps to prevent bundling 3rd-party dependencies. Instead, the consumer should provide them for the packages, so the latter can simply import them.
  2. Bumped dependencies

Comparison

  • @recogito/text-annotator
Before After
image image
  • @recogito/react-text-annotator
Before After
image image
(Soomo Staged)

output: {
preserveModules: true,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe that this property is redundant here. Unfortunately, the preserveModules: true doesn't preserve the original file structure of the package in the output, but simply splits it into quite a few chunks. To actually preserve it a more complex config is required, for example:

...
rollupOptions: {
	/**
	 * If you want to convert a set of files to another format while maintaining the file structure
	 * and export signatures, the recommended way—instead of using output.preserveModules that
	 * may tree-shake exports as well as emit virtual files created by plugins—is to
	 * turn every file into an entry point.
	 * @see https://rollupjs.org/configuration-options/#input
	 */
	input: Object.fromEntries(
		globSync('src/**/*.{ts,tsx}', {
			ignore: ['src/**/*.d.ts', 'src/**/*.stories.tsx', 'src/storybook/**/*']
		}).map((file) => [
			// 1. The name of the entry point
			// lib/nested/foo.js becomes nested/foo
			relative('src', file.slice(0, file.length - extname(file).length)),
			// 2. The absolute path to the entry file
			// lib/nested/foo.ts becomes /project/lib/nested/foo.ts
			fileURLToPath(new URL(file, import.meta.url))
		])
	),
	...

However, I believe it's an overkill for the package, as it still has only a single entry point. Also having the sourcemaps will help the browser to navigate through the original structure.

Comment on lines +25 to +32
globals: {
'colord': 'Colord',
'uuid': 'UUID',
'dequal/lite': 'DequalLite',
'@annotorious/core': 'AnnotoriousCore',
'rbush': "RBush",
'hotkeys-js': 'HotkeysJs',
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The globals are needed to bundle the UMD package using predictable names for the external packages. Otherwise, they will be guessed by Vite:
image

@oleksandr-danylchenko
Copy link
Contributor Author

I also verified that it doesn't break the existing consumers on our side ✅

# Conflicts:
#	package-lock.json
#	packages/text-annotator-react/package.json
#	packages/text-annotator/package.json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant