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

Proposal: explicit query param imports for non-JS/CSS assets #5842

Closed
xiaoxiangmoe opened this issue Nov 17, 2018 · 8 comments
Closed

Proposal: explicit query param imports for non-JS/CSS assets #5842

xiaoxiangmoe opened this issue Nov 17, 2018 · 8 comments
Labels

Comments

@xiaoxiangmoe
Copy link
Contributor

xiaoxiangmoe commented Nov 17, 2018

Previous Proposal

see @gaearon 's Proposal: explicit named imports for non-JS/CSS assets #3722

Proposal

import logoUrl from './logo.svg?type=url';
import docHtml from './doc.md?type=html'; // Load as html string
import docText from './doc.md?type=raw';  // Load as raw string
import docAst from './doc.md?type=ast';   // Load as ast tree object
import Icon from './icon.svg?type=ReactComponent';

see ECMAScript Modules - Node.js | URL based paths:

Modules will be loaded multiple times if the import specifier used to resolve them have a different query or fragment.

docHtml and docHtmlText will load as different type by different webpack loader.

Concerns

  • TypeScript support for query params and fragment in ModuleSpecifier. @ahejlsberg
@iansu
Copy link
Contributor

iansu commented Nov 17, 2018

We've already implemented this feature (in a slightly different way) for SVGs: https://facebook.github.io/create-react-app/docs/adding-images-fonts-and-files#adding-svgs

@xiaoxiangmoe
Copy link
Contributor Author

xiaoxiangmoe commented Nov 17, 2018

@iansu but this proposal seems to be more browser compatible. (like uri)

@miraage
Copy link

miraage commented Nov 20, 2018

@xiaoxiangmoe how will other users migrate if they load multiple types in one import statement?

@xiaoxiangmoe
Copy link
Contributor Author

@miraage load multiple types in one import statement will also work without query params

@gaearon
Copy link
Contributor

gaearon commented Nov 23, 2018

@xiaoxiangmoe Just because you use URLs doesn't make it any more "browser compatible". :-)

@gaearon
Copy link
Contributor

gaearon commented Nov 23, 2018

@xiaoxiangmoe
Copy link
Contributor Author

@gaearon see: parcel-bundler/parcel#2306

I want it could be zero configuration.

@stale
Copy link

stale bot commented Dec 24, 2018

This issue has been automatically marked as stale because it has not had any recent activity. It will be closed in 5 days if no further activity occurs.

@stale stale bot added the stale label Dec 24, 2018
@lock lock bot locked and limited conversation to collaborators Jan 8, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants