Skip to content
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

Suppress child bundle when using multiple bundlers #2212

Closed
blujedis opened this issue Oct 28, 2018 · 3 comments
Closed

Suppress child bundle when using multiple bundlers #2212

blujedis opened this issue Oct 28, 2018 · 3 comments
Labels

Comments

@blujedis
Copy link

blujedis commented Oct 28, 2018

❔ Question

Is there a way via API to limit output of child bundles when building multiple bundles concurrently?

πŸ”¦ Context

Server side React environment requires building both server and client bundles. Now I've noticed a bug that has been currently tagged here #1903 which I also ran into.

What I'm noticing is, in my case when importing my "App" component for the server.tsx file is that I also get the corresponding .css file. This is because "App.tsx" imports a stylesheet.

This is NOT desirable as client.tsx has already bundled those assets.

So again the question is, is there a way to suppress this behavior?

πŸ’» Code Sample

Here's how I'm iterating the multiple bundlers.

async function asyncForEach(array, cb) {
  for (let index = 0; index < array.length; index++) {
    await cb(array[index], index, array);
  }
}

// NOTE: "this.bundlers" is simply a map that's storing bundlers by name.

async run(watch: boolean = true) {

    await asyncForEach(['server', 'client'], async (k) => {
      const bundler = this.bundlers[k];
      bundler.options.watch = watch;
      await bundler.bundle();
    });

}

🌍 Your Environment

Software Version(s)
Parcel 1.10.3
Node 8.11.4
npm/Yarn 6.4.1
OS Mac OS 10.14
@peanutbother
Copy link
Contributor

I think it could be possible by using code splitting.
For your server side you would reference css dependencies to an empty module or file while on client side code you would use the regular source codes.

in your package.json you would put something like this

"browser": {
    "./src/shared/resourceStub": "./src/shared/actualResource"
  },

You can find more information about code splitting here

@blujedis
Copy link
Author

@peanutbother not using package.json I'm bundling via Parcel's API.

Yes I could use a dynamic import but seems to me there should be a way in the API to filter child bundles/assets.

Well at least that's my opinion, but yes I could use a dynamic import makes sense.

@github-actions
Copy link

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs.

@github-actions github-actions bot added the Stale Inactive issues label Jan 17, 2020
@github-actions github-actions bot closed this as completed Feb 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants