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

feat: reference script modules as URL assets #4011

Merged
merged 5 commits into from
Nov 19, 2024
Merged

Conversation

chenjiahan
Copy link
Member

@chenjiahan chenjiahan commented Nov 19, 2024

Summary

If we use new URL() to reference .js or .ts files, they will be treated as URL assets and will not be processed by Rsbuild's built-in swc-loader.

// foo.ts will remain the original content and be output to the dist directory
const fooTs = new URL('./foo.ts', import.meta.url).href;

console.log(fooTs); // "/static/foo.[hash].ts"

Related Links

see #3953

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

Copy link

netlify bot commented Nov 19, 2024

Deploy Preview for rsbuild ready!

Name Link
🔨 Latest commit cc3453f
🔍 Latest deploy log https://app.netlify.com/sites/rsbuild/deploys/673c239c68891500089767cc
😎 Deploy Preview https://deploy-preview-4011--rsbuild.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 71 (no change from production)
Accessibility: 97 (no change from production)
Best Practices: 100 (no change from production)
SEO: 100 (no change from production)
PWA: 60 (no change from production)
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify site configuration.

@chenjiahan chenjiahan requested a review from 9aoy November 19, 2024 07:12
export default = () => <img src={logo} />;
```

If you use `new URL()` to reference `.js` or `.ts` files, they will be treated as URL assets and will not be processed by Rsbuild's built-in `swc-loader`.

Copy link
Contributor

Choose a reason for hiding this comment

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

Shall we need to add a guide on how to treat it as a URL asset and have it processed by the built-in swc-loader in Rsbuild?

Copy link
Member Author

Choose a reason for hiding this comment

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

I have no idea how to support it, do you have any suggestions?

Copy link
Contributor

Choose a reason for hiding this comment

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

no idea +1 😢

Copy link
Member Author

Choose a reason for hiding this comment

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

We can find a solution and include a guide in another PR.

@chenjiahan chenjiahan merged commit a5a7361 into main Nov 19, 2024
8 checks passed
@chenjiahan chenjiahan deleted the script_module_1119 branch November 19, 2024 09:24
@9aoy 9aoy mentioned this pull request Nov 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants