-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Feature request: Serving arbitrary content #945
Comments
I'm not really sure what bug #371 is asking, but it's possible that this is related. |
You should never manually modify the |
Normally parcel should catch iframe tags, however this is JSX I suppose? the correct code would be this: function MyComponent () {
const src = require('./assets/index.html');
return <iframe src={src} />
} Or this if u like it shorter function MyComponent () {
return <iframe src={require('./assets/index.html')} />
} |
@DeMoorJasper Parcel would still resolve |
@davidnagli Ow didn't see that structure, well now i'm kinda confused at why this would even be a feature, this seems like an extremely narrow use-case? Unless it makes sense to move the assets folder to the src folder than it would make sense again to bundle it up with everything else. |
I see. In that case, is it a bug that asking for any HTML file always returns a copy of index.html, regardless of the path? I would expect a 404 error when asking for something like
Ok, so I went ahead and tried your suggestion in a fresh directory: package.json: {
"private": true,
"scripts": {
"start": "parcel index.html"
},
"dependencies": {
"preact": "^8.2.7"
},
"devDependencies": {
"parcel-bundler": "^1.6.2"
}
} index.html: <html>
<body>
<script src="./index.js"></script>
</body>
</html> index.js: import { h, render } from "preact";
import frameHtml from "./frame.html";
render(h("iframe", { src: frameHtml }), document.body); frame.html: <html>
<body>
<p>Hello world!</p>
</body>
</html> However, the
Other variations I tried:
So, importing HTML from within JS doesn't seem to work in Parcel the moment. |
@swansontec Hoped it would work, although html imports would be weird in a sense, as some people might want to use the actual html in their js and some people would want the link to the actual file, I guess this could spark a discussion to add something like this: Html assets imported from Javascript, might than look something like this exports.html = '<html><!-- some html code --></html>';
exports.uri = '/dist/aa4ez65e4aze4a654ze.html'; |
I see. Given this situation, it looks like the only way to have a JS-managed iframe using current Parcel is to host the iframe contents on some sort of CMS. Then Javascript can just do something like For now, putting the iframe content into the I'm not sure the third-party code will survive a trip through Parcel, since it has already been bundled using Webpack or whatever those guys are using. If it does survive, though, the first option sounds reasonable to me too. Maybe the solution is a plugin that simply adds files to the bundle without transforming them in any way. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 30 days if no further activity occurs. Thank you for your contributions. |
This is a 🙋 feature request.
🔦 Context
I am developing an application which makes use of an iframe component. The iframe content comes from a third party, so I don't want to bundle / process it in any way. When I use the Parcel dev server, I would still like to serve these assets to the browser, though.
💻 Code Sample
My original idea was to place the iframe assets into their own directory under
dist
:Given this folder layout, I would like to do something like this in my code:
However, the parcel dev server (started by
parcel src/index.html
) doesn't seem to be serving theassets
folder, so when I place that component on my page, I don't actually get the iframe contents (In fact, accessing http://localhost:1234/assets/index.html just returns the outer, bundled index.html, so I get an infinite recursion of frames inside of frames. Cool, but not what I wanted. 🤷♂️).Would it make sense for parcel to serve random files manually copied into the dist folder? Is there a better way to accomplish this? Thanks.
The text was updated successfully, but these errors were encountered: