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

Make two files instead of three #80

Open
callumacrae opened this issue Jan 13, 2016 · 2 comments
Open

Make two files instead of three #80

callumacrae opened this issue Jan 13, 2016 · 2 comments

Comments

@callumacrae
Copy link

Hey!

I effectively want to split out part of a file, instead of splitting out the common parts of two files.

Currently I have bundle.js, which contains everything used on the site. There is some checkout specific logic there that I only want on the checkout, so I want to split that stuff out into bundle-checkout.js, but then run both bundle.js and bundle-checkout.js in the checkout.

With factor-bundle by default, I would be running these files on the main site:

  • bundle-common.js
  • bundle.js

And these on the checkout:

  • bundle-common.js
  • bundle.js
  • bundle-checkout.js

It's pointless for me to have both bundle-common.js and bundle.js!

The best solution I've found so far is to add require('./main') to the top of the input bundle-checkout.js, which would mean that bundle.js is effectively an empty file and I can include bundle-common.js by itself, but then that generates a junk file.


lib.js:

module.exports = 'lib';

main.js:

var lib = require('./lib');
console.log(lib);

checkout.js:

require('./main');
console.log('special checkout logic');

And then the command:

browserify main.js checkout.js -p [ factor-bundle -o junk.js -o bundle-checkout.js ] -o bundle.js

Is there any way to do this without the require('./main') and the useless junk.js file?

Thanks, and sorry for the long question! I'll turn this into an article once it's been figured out so that nobody asks it again :)

@terinjokes
Copy link
Contributor

factor-bundle is currently optimized for splitting out the common files from the rest of a bundle. Your use case isn't wrong, but I'll need to think a bit about how to support it.

@callumacrae
Copy link
Author

Awesome 🎉

Let me know if there's anything I can do to help :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants