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

fix: 3rd-party imports during build #3097

Merged
merged 1 commit into from
Jan 2, 2025
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
3 changes: 2 additions & 1 deletion configuration/vite-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"type-fest": "^4.28.1",
"typescript": "^5.5.4",
"vite": "^5.4.11",
"vite-plugin-dts": "^4.3.0"
"vite-plugin-dts": "^4.3.0",
"vite-plugin-externalize-deps": "^0.8.0"
}
}
20 changes: 9 additions & 11 deletions configuration/vite-config/src/definePackageConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
type UserConfig as ViteConfig,
} from 'vite';
import dts from 'vite-plugin-dts';
import { externalizeDeps } from 'vite-plugin-externalize-deps';
import { copyProtectedPackagesPlugin } from './copyPlugin';
import { getShortName } from './package';
import { readPackageJson } from './packageJson';
Expand Down Expand Up @@ -41,8 +42,6 @@ export function definePackageConfig(
): ViteConfig {
const packageJson = readPackageJson(resolve(dirname, './package.json'));

const allPackages = listRegisteredPackages();

const packageAliases = listRegisteredPackages({
filter: { scope: 'protected' },
}).reduce<ViteAliasOptions>((acc, protectedPackage) => {
Expand Down Expand Up @@ -141,19 +140,18 @@ export function definePackageConfig(
entryFileNames: '[name].cjs.js',
},
],
external: [
// Prevent node_modules from being compiled and included in the
// the package's dist.
/node_modules/,

// Prevent the package from compiling the source code of aliased
// protected packages.
...allPackages.map(({ name }) => name),
],
},
},

plugins: [
// Prevent the package from compiling dependencies and changing their
// imports.
externalizeDeps({
deps: true,
devDeps: true,
peerDeps: true,
useFile: resolve(dirname, './package.json'),
}),
// Vite doesn't generate declaration files automatically and does not
// care about what's defined in the package.json. we need to use a
// plugin to generate the types.
Expand Down
Loading
Loading