Replies: 8 comments 5 replies
-
@samanime there's no more middleware in parcel 2 We moved away from it to streamline our plugin ecosystem and have a plugin type named reporter that could be used to create your own server if you'd really want to have that. Or you could simply run parcel in watch mode and run your own server on the dist directory. |
Beta Was this translation helpful? Give feedback.
-
This sounds like a pretty big cognitive shift from the middleware approach. The Reporter docs are also quite bare right now: https://parcel2-docs.now.sh/plugin-system/reporter/ Will there be an example of how to migrate from the old Express middleware approach? |
Beta Was this translation helpful? Give feedback.
-
Regarding the programmatic API, @mischnic posted some examples from the new docs. It's good to see these examples, but I still can't wrap my head around how to migrate from v1 to v2. I suggest that we put out a "Migration Guide" for those who are using the previous API with the Express middleware, illustrating exactly how to replicate the same behavour in a "before and after" manner. For example, this is what I currently have but I can't figure out how to do the same in v2: const Bundler = require("parcel-bundler");
const entryFiles = [path.join(__dirname, "./app/index.html")];
const bundler = new Bundler(entryFiles, { logLevel: 1 });
const app = express();
app.use("/", bundler.middleware()); I shouldn't need to learn about the plugin ecosystem and the reporter to make this work. Ideally there should be an equivalent code block example so that we can easily migrate to v2. |
Beta Was this translation helpful? Give feedback.
-
You don't need to use the middleware with the new proxying feature. If you want to emulate your above code: In const app = express();
app.get('/hello-world', (req, res) => {
res.send("Hello world!");
});
app.listen(54321); In {
"/api": {
"target": "http://localhost:54321",
"pathRewrite": {
"^/api": ""
}
}
} That proxy config will make Parcel reroute all requests from |
Beta Was this translation helpful? Give feedback.
-
I was doing something like this in Parcel 1, in order to serve some other static files from another directory:
Does removing middleware means I must separate them into two scripts (one for Express server, and another for Parcel)? Using proxy feature also sounds like I need to modify (And there's no description about options in v2's document, mappings between API options and CLI options, as well as mappings between v1 and v2., type information only doesn't help at all and I'm still figuring out.) |
Beta Was this translation helpful? Give feedback.
-
@pykenny you can also use javascript in the proxy config, so you can actually start your express server in that script if you want the same-ish behavior as before. |
Beta Was this translation helpful? Give feedback.
-
I just found that Below is my initial attempt to run both servers described above in the same script (assume it's placed in project root):
So the expected behavior is:
Currently 1. works but 2. doesn't. A message saying Console outputs:
I'm also looking up CLI options to figure out the correct settings. |
Beta Was this translation helpful? Give feedback.
-
Vite has a middleware mode. |
Beta Was this translation helpful? Give feedback.
-
Is there any kind of middleware for Express built into Parcel 2 yet?
I pulled the repo and the only references seem to be in the (now private) parcel-bundler package.
I also couldn't find any documentation that would seem to indicate it, other than talking about the more programmatic interface, but that still seemed to be pretty self-contained and couldn't be wired with Express directly.
Am I missing something? Any code or samples?
Beta Was this translation helpful? Give feedback.
All reactions