Skip to content
This repository was archived by the owner on Aug 28, 2026. It is now read-only.
This repository was archived by the owner on Aug 28, 2026. It is now read-only.

Unnecessary Buffer polyfill when source maps are disabled #454

Closed

Description

@ArgonAlex

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.

Activity

  1. michael-ciniawsky commented on Mar 14, 2017

    @michael-ciniawsky
    Contributor

    @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

  2. michael-ciniawsky commented on Mar 14, 2017

    @michael-ciniawsky
    Contributor

    Mind testing quickly testing that out ? 😛

  3. ArgonAlex commented on Mar 14, 2017

    @ArgonAlex
    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.

  4. michael-ciniawsky commented on Mar 14, 2017

    @michael-ciniawsky
    Contributor

    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 😛

  5. bebraw commented on Mar 14, 2017

    @bebraw
    Contributor

    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.

  6. bebraw commented on Mar 14, 2017

    @bebraw
    Contributor

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

  7. michael-ciniawsky commented on Apr 20, 2017

    @michael-ciniawsky
    Contributor

    Closed by #501

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Fields

Priority

None yet

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions