Parcel 2 does not return transformed URLs when importing raw files specified using a glob pattern from JavaScript with any of
import asset from 'url:/assets/**/*';
import asset from 'url:/assets/*';
import asset from 'url:/assets/*.ext';
package.json
{
"name": "test",
"dependencies": {
"parcel": "next"
},
"devDependencies": {
"@babel/core": "^7.0.0"
}
}
From what I understand from the old Parcel docs, an object containing a mapping of files to transformed URLs should be returned, such as the following:
{
'file-1': '/file-1.8e73c985.png',
'file-2': '/file-1.8e73c985.png'
}
Parcel fails during bundling with the following error:
$ yarn parcel index.html
โน Server running at http://localhost:1234
Building index.html...
ร Build failed.
@parcel/core: Failed to resolve 'url:/assets/*' from './index.html'
C:\Users\User\Workspace\test\index.html:1:20
> 1 | <html>
> | ^
2 | <head>
3 | <script>
@parcel/resolver-default: Cannot load file './assets/*' in './'.
Did you mean ./assets?
Related:
I am writing a game using three.js and was trying to import my images so that I can load them as textures.
Folder Structure
/root
|-- /assets
| |-- test.png
|-- index.html
|-- package.json
index.html
<html>
<head>
<script>
import assets from 'url:/assets/*';
console.log(assets);
</script>
</head>
</body>
| Software | Version(s) |
| ---------------- | ---------- |
| Parcel | 2.0.0-alpha.3.2 (also reproducible on 2.0.0-nightly.277+149c00b7) |
| Node | v12.17.0 |
| npm/Yarn | yarn 2.0.0-rc.33 |
| Operating System | Windows 10 1909 |
Parcel 2 doesn't support globs (yet).
Parcel 2 doesn't support globs (yet).
Is there workaround to import multiple files for the time being? I need to access the generated file names dynamically. Is this also about the resolver, I mean can I simply add this functionality by creating my own resolver?
Something like https://www.npmjs.com/package/babel-plugin-transform-glob-import (the only downside: you need to manually clear the cache when changing one of the imported file)
Is this also about the resolver?
No, at the moment a resolver plugin can only return a single result, so this would need further further in core.
No, at the moment a resolver plugin can only return a single result, so this would need further further in core.
Correction: the problem at the moment is that the resolver couldn't add the directory to the watcher.
Are there any plans to support this behaviour some time soon? This was one of the things I liked about parcel. I would keep using v1 since it's a lot easier, but it seems it's not very well supported (but neither is v2 it seems)