website
website copied to clipboard
Improve Parcel API example?
Might be a bit outdated now:
https://github.com/parcel-bundler/parcel/issues/6064#issuecomment-811977238
cc @asprich
I am interested in using the Parcel API to run the dev server. However the example doesn't seem to be available and the referenced comment seems out of date.
My experience so far is that the watch routine seems to return prematurely unless i install additionalReporters (as noted in the comment above). When I add the reporters I can't seem to find where the server is being hosted. My serveOptions (defined here: https://v2.parceljs.org/plugin-system/api/#InitialServerOptions) seem to be ignored?
I've opened a PR to add the server back to the default config: https://github.com/parcel-bundler/parcel/pull/6195
Thanks - but i looked at the PR and made similar change to my parcelrc but I'm sure how that makes the server open.
With addition of the reporter - my server no longer prematurely returns. However I can't seem to find the dev server - the port does not seem to be used. Here is my use of the parcel api
import { Observable, from } from 'rxjs';
import { BuilderOutput } from '@angular-devkit/architect';
import Parcel from '@parcel/core';
export function runParcel(
config: string,
entries: string[],
port: number
): Observable<BuilderOutput> {
return from(
new Promise<BuilderOutput>((resolve, reject) => {
const bundler = new Parcel({
entries,
config,
defaultTargetOptions: {
engines: {
browsers: ['last 1 Chrome version'],
node: '14',
},
sourceMaps: true,
},
shouldDisableCache: true,
logLevel: 'verbose',
serveOptions: { port: port },
mode: 'development',
additionalReporters: [
{ packageName: '@parcel/reporter-cli', resolveFrom: __filename },
{ packageName: '@parcel/reporter-dev-server', resolveFrom: __filename },
],
});
return bundler.watch((err) => {
resolve({ success: true });
if (err) {
console.log(err);
reject(err);
}
});
})
);
}
I'd happily just spawn the parcel cli from my js except that I can't figure out how to point to the .parcelrc. I am in a mono repo and the shell only works when I am in the directory of the project. (When I use the JS api I can work in a monorepo for build - but not for dev server)
Also note that the --config
option on the command line seems ambiguos. Since it seems to imply package.json but does not pick up the .parcelrc