Parcel: Explicit query param imports for non-JS/CSS assets

Created on 20 Nov 2018  路  3Comments  路  Source: parcel-bundler/parcel

馃挰 RFC

// Load as url by parcel-plugin.url
import logoUrl from './logo.svg?type=url';  
// Load as react-component by parcel-plugin-svg.react-component
import Icon from './icon.svg?type=react-component';

// Load as html string by parcel-plugin-md.html
import docHtml from './doc.md?type=html'; 
// Load as raw string by parcel-plugin.raw
import docText from './doc.md?type=raw';  
// Load as ast tree object  by parcel-plugin-md.ast
import docAst from './doc.md?type=ast';   

parcel-plugin.loadtype can load for any filetype
parcel-plugin-filetype.loadtype can load loadtype from special filetype

馃敠 Context

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

also 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.

RFC

Most helpful comment

This would actually be useful for JS as well. The tabs.executeScript WebExtension API takes an URL or the literal content of the file, rather like Worker does. If there was a way to load a JS file as a URL (while also applying all the Babel transforms, etc), that would both serve this somewhat niche, presently-awkward use-case and provide an alternative way to load workers if you want to do it in a way that defeats Parcel's current detection logic.

All 3 comments

The query string modifiers would be pretty nice.

This would actually be useful for JS as well. The tabs.executeScript WebExtension API takes an URL or the literal content of the file, rather like Worker does. If there was a way to load a JS file as a URL (while also applying all the Babel transforms, etc), that would both serve this somewhat niche, presently-awkward use-case and provide an alternative way to load workers if you want to do it in a way that defeats Parcel's current detection logic.

Was this page helpful?
0 / 5 - 0 ratings