Skip to content

Commit

Permalink
build: don't mark CSS files as external
Browse files Browse the repository at this point in the history
When a file marked as external is imported, it's not included in
the JS library bundle: the JS import is left as-is. This is desirable
for regular JS dependencies such as react and maplibre-gl, but is
undesirable for non-standard imports such as CSS files.

Indeed, CSS imports from our JS library bundle cause pain for
downstream users, because they are forced to configure their build
system to support CSS imports (these aren't standard JS, e.g. webpack
doesn't support this by default). Moreover, this makes it impossible
to use the library without a build system (e.g. importing it directly
from pure HTML/JS files).

Make users responsible for including the CSS one way or another. Our
stories do this using CSS imports already, but other downstream
consumers might prefer to use a <link> or similar.

Signed-off-by: Simon Ser <[email protected]>
Fixes: 6dd85a7 ("build: fix unresolved dependencies")
  • Loading branch information
emersion committed Jan 23, 2025
1 parent 692c54f commit e846a65
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions rollup-base.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const generateRollupBaseConfig = () => ({
],
external: (id, parent, isResolved) => {
if (!isResolved) return false;
if (id.endsWith('.css')) return false;
const rel = path.relative(rootDir, id);
const filenames = rel.split(path.sep);
return filenames[0] === 'node_modules' || filenames[1] === 'dist';
Expand Down

0 comments on commit e846a65

Please sign in to comment.