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

Mark import as external #880

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

sapphi-red
Copy link

This PR adds a way to mark an import as external with resolver.

closes #479
closes #555

resolver: {
resolve(specifier, originatingFile) {
if (specifier === './does_not_exist.css' || specifier.startsWith('https:')) {
return true;
Copy link
Author

Choose a reason for hiding this comment

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

For now, I made resolve to accept string | true to focus on the rough design. I think string | { specifier: string, external?: boolean } would be nice here. What do you think?

Comment on lines +1 to +3
@import url('https://fonts.googleapis.com/css2?family=Roboto&display=swap');
@import './does_not_exist.css';
@import './b.css';
Copy link
Author

Choose a reason for hiding this comment

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

This case can be bundled without any semantics change, but for the following case, it's difficult to keep the semantics.

@import './b.css'; // bundled
@import "https://fonts.googleapis.com/css2?family=Roboto&display=swap"; // externalized

related: postcss/postcss-import#536, parcel-bundler/parcel#5840 (comment), evanw/esbuild#465 (comment)

Maybe it's fine to simply change the semantics in this case? (both postcss-import and esbuild seems to do that)

@@ -102,7 +123,7 @@ pub trait SourceProvider: Send + Sync {

/// Resolves the given import specifier to a file path given the file
/// which the import originated from.
fn resolve(&self, specifier: &str, originating_file: &Path) -> Result<PathBuf, Self::Error>;
fn resolve(&self, specifier: &str, originating_file: &Path) -> Result<ResolveResult, Self::Error>;
Copy link
Author

@sapphi-red sapphi-red Dec 27, 2024

Choose a reason for hiding this comment

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

I'm not familiar with the rust libraries' semver compat, but I guess changing the return value of a public trait is a breaking change. Is it fine to introduce a breaking change? If not, I'll try to add resolve_advanced method with a default implementation so that it won't be a breaking change.
(On the JS side, it's not a breaking change)

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.

Resolver can't import stylesheets from URLs Mark import as external
1 participant