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

Don't read internal files from postcss #980

Closed
RyanZim opened this issue Feb 3, 2018 · 7 comments
Closed

Don't read internal files from postcss #980

RyanZim opened this issue Feb 3, 2018 · 7 comments

Comments

@RyanZim
Copy link
Contributor

RyanZim commented Feb 3, 2018

Currently autoprefixer does things like const list = require('postcss/lib/list');
instead of const list = require('postcss').list;

This makes bundling autoprefixer, postcss, and other postcss plugins with bundle splitting very difficult to do without duplicating parts of postcss.

Additionally, it could be argued this is breaking point 2.4 the plugin guidelines, since the paths aren't documented in the API docs. This prevents postcss from changing its internal directory structure.

Would you be open to changing this?

@ai
Copy link
Member

ai commented Feb 3, 2018

Why it makes it difficult to split bundle?

Anyway we have postcss.list = require ("postcss/list")

@RyanZim
Copy link
Contributor Author

RyanZim commented Feb 3, 2018

Why it makes it difficult to split bundle?

Not sure about all bundlers, but some (like browserify) treat each file as its own module. So if you specify that postcss should be split to a different bundle file, postcss/lib/list won't be split out. The end result is that the list code is included in both bundle files.

Anyway we have postcss.list = require ("postcss/list")

Not sure I understand?

@ai
Copy link
Member

ai commented Feb 3, 2018

There is no 1 postcss bundle in PostCSS npm package. I don't use Rollup or webpack during npm publish. So PostCSS will be a bunch of small files in the bundle.

Just open node_modules/postcss/.

So anyway your bundle will have separated file for postcss/list. What all be a difference if I will use postcss.list in Autoprefixer?

@RyanZim
Copy link
Contributor Author

RyanZim commented Feb 3, 2018

I know it isn't one big file. However, if you only require postcss directly, bundlers are able to figure out what you're doing and be smarter about code splitting.

i.e. if bundle A contains postcss, and bundle B contains autoprefixer, the bundler can see that autoprefixer can use postcss from bundle A. However, it doesn't know that postcss/lib/list can be obtained from postcss.list as well, so it it includes the list code in bundle B as well, when it's already included in bundle A.

@RyanZim
Copy link
Contributor Author

RyanZim commented Feb 3, 2018

TL;DR it makes my life a lot easier. Is there a specific reason we can't do const list = require('postcss').list;?

@ai
Copy link
Member

ai commented Feb 3, 2018

Yeap, it is not big deal, I can replace it. Do you want to send PR?

@RyanZim
Copy link
Contributor Author

RyanZim commented Feb 3, 2018

Sure, I can do that.

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