I chatted with @CompuIves (author of Code Sandbox) at React Amsterdam about potentially running Parcel fully inside the browser. They do this in Code Sandbox using their own bundler currently, but it would be cool if we could enable them to use more pieces of Parcel.
In addition, it would be super cool to have an online demo showing how Parcel works, similar to the one Rollup has. Maybe we could even just use Code Sandbox for that. ๐
There are a few things that we currently depend on Node for that won't work in the browser.
These should all be solvable if we make Parcel sufficiently pluggable so that these pieces could be replaced with alternative implementations, even if they aren't all provided by Parcel itself. For example, there might be many implementations of a filesystem, not just a single browser one that we provide. We'd want to allow e.g. Code Sandbox to implement their own and plug it into Parcel easily.
This is kind of a meta issue to discuss the above items. We can break out into separate issues to discuss each one as we get closer to implementation. For now, let me know your thoughts!
This sounds great, I'd love to help wherever I can!
I agree with the given points. The solution to some native modules would be to create browser specific transpilers (eg. Sass.js instead of node-sass), that wouldn't be too hard to implement I reckon.
I'm looking forward to more discussion on this, I'd really love to have Parcel working inside CodeSandbox ๐
Awesome idea!
Filesystem : Ping @DeMoorJasper. We've discussed a bit about implementing a virtual fs in Parcel, perhaps this may help in this issue? IIRC CodeSandbox already has its vfs.
Server/HMR - As we only serve static files we could totally polyfill this only using Object URLs (URL.createObjectURL
) and use a internal messaging system instead of WebSockets.
A concrete index.html
example :
<!DOCTYPE html>
<html>
<head>
<title>Code Sandbox + Parcel</title>
<link
rel="stylesheet"
href="blob:https://github.com/9defa61c-87c6-49b4-a3a8-2d9616941f33"
/>
</head>
<body>
<script
src="blob:https://github.com/8defa61c-87c6-49b4-a3a8-2d9616941f33"
></script>
</body>
</html>
Awesome!
Let me know if there's progress here, I'd love to be involved ๐
I've taken a go at this (the Rollup-inspired REPL, not a Codesandbox-like IDE; though there is a preview iframe) by make Parcel self-hosting, if someone wants to try it
https://parcel-repl.now.sh/
code in the repl branch
some details on the process
Actual code changes to Parcel were pretty minimal, so I hope this will be comparatively easy to port to Parcel 2.
Hi, I've been down a few rabbit holes trying to replicate similar functionality. Just stumbled on this thread and I'm wondering how far off these features are?
Are there any work arounds that I could use in the meantime? My app is very much in an alpha stage so keen to test things out early!?
Please give extra info if possible. I've not used Parcel before, and find the bundler world a bit ๐คฏ
Thanks in advance and great work so far!
Same here. We're creating a web-based IDE and need a bundler that can work with a virtual file system. I'm keen to learn whether this will be possible with Parcel any time soon.
Technically, Parcel 2 can already run in the browser.
A REPL (similar to the Rollup one): https://parcel2-repl.now.sh
Code for that: https://github.com/parcel-bundler/parcel/tree/repl-v2/packages/dev/repl
(That build/branch is slightly outdated compared to the "normal" Parcel)
Current bugs of the REPL:
@babel/core
excludes that logic in a browser buildnode_modules
via fs
and in the browser, these files don't exist)Changes made for the REPL (and not to make Parcel work) that cannot be directly upstreamed:
packages/core/package-manager/src/NodePackageManager.js
(unless you want to create a build for some specific asset types only)globalThis.PARCEL_...()
callback in the json reporter & sourcemap visualizer are very hackyThank you for the update! It's good to know that it's possible to tweak Parcel to work in a browser. For us, however, Parcel would be only one ingredient among others. We don't have the resources to maintain our own fork of Parcel. What we need is an existing, maintained version of Parcel that works in the browser.
Hey guys, just wondering how this is progressing? Is this https://github.com/parcel-bundler/parcel/projects/5 the best place to keep an eye on for updates?
I haven't worked on this since my last comment.
We don't use Github Projects (which is also why I closed that project you linked).
Is there anything we can do to help?
@mischnic How could I consume this alpha version in the meantime (repl-v2)?
NPM won't let you import from a subfolder of a branch so forking it is also not really an option ๐
Most helpful comment
I've taken a go at this (the Rollup-inspired REPL, not a Codesandbox-like IDE; though there is a preview iframe) by make Parcel self-hosting, if someone wants to try it
https://parcel-repl.now.sh/
code in the repl branch
some details on the process
Actual code changes to Parcel were pretty minimal, so I hope this will be comparatively easy to port to Parcel 2.