Skip to content

Commit

Permalink
Fix relative import path of assets for non-entrypoint modules
Browse files Browse the repository at this point in the history
When modules reference static assets added to the build via the `keepAssets` rollup plugin, and those modules are not entrypoints and as such moved into a bundle at a different location, the relative path to that asset would not get rewritten, leading to broken references.

Fixes embroider-build/addon-blueprint#192
  • Loading branch information
simonihmig committed Sep 13, 2023
1 parent 17cf74c commit 69978f5
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions packages/addon-dev/src/rollup-keep-assets.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import walkSync from 'walk-sync';
import type { Plugin } from 'rollup';
import { readFileSync } from 'fs';
import { join } from 'path';
import { dirname, join, resolve } from 'path';
import minimatch from 'minimatch';

export default function keepAssets({
Expand All @@ -23,9 +23,10 @@ export default function keepAssets({
});
if (
resolution &&
importer &&
include.some((pattern) => minimatch(resolution.id, pattern))
) {
return { id: source, external: true };
return { id: resolve(dirname(importer), source), external: 'relative' };
}
return resolution;
},
Expand Down

0 comments on commit 69978f5

Please sign in to comment.