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

Unnecessary Buffer polyfill when source maps are disabled #454

Closed
ArgonAlex opened this issue Mar 14, 2017 · 7 comments
Closed

Unnecessary Buffer polyfill when source maps are disabled #454

ArgonAlex opened this issue Mar 14, 2017 · 7 comments
Assignees

Comments

@ArgonAlex
Copy link

ArgonAlex commented Mar 14, 2017

Do you want to request a feature or report a bug?
Bug

What is the current behavior?
After upgrading from css-loader 0.26.4 to 0.27.3 webpack is including a polyfill for Buffer in the bundle when source maps are not enabled. This is resulting in an increased bundle size, even though the polyfill is never actually used.

If the current behavior is a bug, please provide the steps to reproduce.
Install css-loader 0.23.7, run a webpack build, and check the resulting bundle.

What is the expected behavior?
If source maps are not enabled, then there is no need to output the toComment function in lib/css-base.js, which uses Buffer. The loader should only output this function if source maps are enabled.

Please mention other relevant information such as your webpack version, Node.js version and Operating System.
Windows 8.1
Node 6.9.5
Webpack 2.2.1

My current workaround is just adding

node: {
  Buffer: false
}

to the webpack config, but I think it would be better if the loader could handle this.

@michael-ciniawsky
Copy link
Member

@alexwalter88 https://github.com/webpack-contrib/css-loader/blob/master/lib/loader.js#L113 Normally it should exaclty do that, but guessing the toComment function needs to be moved into the if (useSourceMap) statement to avoid including the Buffer polyfill

@michael-ciniawsky
Copy link
Member

Mind testing quickly testing that out ? 😛

@ArgonAlex
Copy link
Author

Nope that doesn't seem to work. I tried removing the function too and just inlining it the if (useSourceMap) statement, but the Buffer polyfill is still being included.

@michael-ciniawsky
Copy link
Member

Alright I need to ask Tobias what to do about it at best, I come back when I know more :). Meanwhile please continue using your workaround 😛

@bebraw
Copy link
Contributor

bebraw commented Mar 14, 2017

I guess the question is, how to rewrite

var base64 = new Buffer(JSON.stringify(sourceMap)).toString('base64');

without relying on Buffer. That would be one way.

@bebraw
Copy link
Contributor

bebraw commented Mar 14, 2017

See MDN. Either btoa or solution #1 from that page would likely solve this.

@michael-ciniawsky
Copy link
Member

Closed by #501

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

3 participants