Importing assets with the url pipeline can cause issues because the JSRuntime doesn't check that when inserting the loader.
isAsync is false for an import inside Javascript). Not sure if this is currently a coincidence (https://github.com/parcel-bundler/parcel/issues/4202)url: pipeline should probably be moved to the top of the config and have "..." added so that url:./foo.js works somewhat as expected.import("./foo.js") is translated to jsLoader("<bundle url>").then(() => parcelRequire("<id>")in the global output format - currently the bundle is not even executed when import()ing.@Banou26 In which situations do you want to use a url: imported js script? navigator.serviceWorker.register('./script.js') could probably be done quite easily but dynamic imports are a different story.
My current situation is that my app needs to open sandboxed iframes running my code, which will then potentially import/run third party code.
So i'd just like to be able to refer to the html/js entry point in that iframe source/script tags.
Currently the way i do it is that i simply pass the iframe entry point as second entry point for my parcel serve:
parcel src/index.html src/iframe/index.html
and the /.parcel-cache/dist folder ends up like this
.parcel-cache/dist/
โโโ iframe/
โ โโโ index.html
โโโ iframe.hash.js
โโโ index.html
โโโ index.hash.js
Luckily entry points don't have a hash in their filename, so i can just end up doing:
const iframe = document.createElement('iframe')
iframe.sandbox = 'allow-scripts'
iframe.src = './iframe/index.html'
document.body.appendChild(iframe)
but with the url: import, this could simply be replaced by
import iframeUrl from 'url:../iframe/index.html'
const iframe = document.createElement('iframe')
iframe.sandbox = 'allow-scripts'
iframe.src = iframeUrl
document.body.appendChild(iframe)
And i could basically do the same with JS files by passing srcdoc to the iframe instead
import scriptUrl from 'url:../iframe/iframe.js'
const iframe = document.createElement('iframe')
iframe.sandbox = 'allow-scripts'
iframe.srcdoc = `
<!DOCTYPE html>
<script defer src="${scriptUrl}">
`
document.body.appendChild(iframe)
Is there a workaround for this? I'm using parcel 2 and trying to get a url for a JS file (working with a library that relies on dynamic imports).
Most helpful comment
My current situation is that my app needs to open sandboxed iframes running my code, which will then potentially import/run third party code.
So i'd just like to be able to refer to the html/js entry point in that iframe source/script tags.
Currently the way i do it is that i simply pass the iframe entry point as second entry point for my parcel serve:
parcel src/index.html src/iframe/index.htmland the
/.parcel-cache/distfolder ends up like thisLuckily entry points don't have a hash in their filename, so i can just end up doing:
but with the
url:import, this could simply be replaced byAnd i could basically do the same with JS files by passing
srcdocto the iframe instead