Skip to content

Commit

Permalink
fix: 3rd-party imports during build
Browse files Browse the repository at this point in the history
  • Loading branch information
tracy-french committed Jan 2, 2025
1 parent ee8f6fc commit 32882b5
Show file tree
Hide file tree
Showing 7 changed files with 193 additions and 15 deletions.
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

0 comments on commit 32882b5

Please sign in to comment.