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

Webpack adds the nodejs shims when they actually not necessary. #194

Closed
sullenor opened this issue Mar 16, 2017 · 4 comments
Closed

Webpack adds the nodejs shims when they actually not necessary. #194

sullenor opened this issue Mar 16, 2017 · 4 comments
Assignees

Comments

@sullenor
Copy link

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

I think it's a bug (not sure).

What is the current behavior?

Webpack includes in the resulting bundle nodejs shims for buffer, process and path modules when they are actually not necessary. It adds about 30kb in the minified bundle.
I faced this issue after updating version of webpack from 1.x to 2.x.

If the current behavior is a bug, please provide the steps to reproduce.

I made a small example, which illustrates the problem: https://github.com/sullenor/webpack-shims and attached the stats files:

What is the expected behavior?

Expected the resulting bundle to have a smaller size: ~3-5kb, not 33kb (minimized).

If this is a feature request, what is motivation or use case for changing the behavior?

No

Please mention other relevant information such as the browser version, Node.js version, webpack version and Operating System.

macOs Sierra 10.12.3, nodejs v7.7.2, webpack v2.2.1,
https://github.com/sullenor/webpack-shims/blob/master/package.json#L3-L6

From webpack/webpack#4473

@michael-ciniawsky
Copy link
Member

michael-ciniawsky commented Mar 16, 2017

@sullenor We need to investigate but not sure if we can fix it easily, as a workaround could you try

webpack.config.js

module.exports = {
...
node: {
  buffer: false
  ...
  }
}

I know it's inconvenient and shouldn't be a requirement to use style-loader or any other loader, but for the meantime 😛

@sullenor
Copy link
Author

sullenor commented Mar 17, 2017

@michael-ciniawsky looks like I came to the similar workaround :)

thank you!

@ablankenship10
Copy link

ablankenship10 commented May 1, 2017

Think I am having a similar but slightly different issue. Without style-loader the webpack output:

Version: webpack 2.4.1
Time: 79ms
    Asset     Size  Chunks             Chunk Names
bundle.js  2.74 kB       0  [emitted]  main
   [0] ./src/main.js 0 bytes {0} [built]
   [1] ./index.js 26 bytes {0} [built]

Importing 1 empty stylesheet into my project causes this:

Version: webpack 2.4.1
Time: 372ms
    Asset     Size  Chunks             Chunk Names
bundle.js  73.5 kB       0  [emitted]  main
   [0] ./src/main.js 33 bytes {0} [built]
   [1] ./index.js 26 bytes {0} [built]
   [2] ./~/base64-js/index.js 3.48 kB {0} [built]
   [3] ./~/buffer/index.js 48.6 kB {0} [built]
   [4] ./~/css-loader!./src/style.css 199 bytes {0} [built]
   [5] ./~/css-loader/lib/css-base.js 2.19 kB {0} [built]
   [6] ./~/ieee754/index.js 2.05 kB {0} [built]
   [7] ./~/isarray/index.js 132 bytes {0} [built]
   [8] ./~/style-loader/addStyles.js 8.51 kB {0} [built]
   [9] ./~/style-loader/fixUrls.js 3.01 kB {0} [built]
  [10] ./src/style.css 899 bytes {0} [built]
  [11] (webpack)/buildin/global.js 509 bytes {0} [built]

My webpack config with the work around mentioned above:

module.exports = {
  entry: './index.js',
  output: {
    filename: 'bundle.js'
  },
  node: {
    buffer: false
  },
  module: {
    loaders: [
      {test: /\.html$/, loader: "html-loader"},
      {test: /\.less$/, loader: 'style-loader!css-loader!less-loader'},
      {test: /\.css$/, loader: 'style-loader!css-loader'},
    ]
  }
};

EDIT: It looks like the problem is actually with css-loader, not style-loader, and the work around should be Buffer with a capital B not lowercase.

Issue Ref from webpack-contrib/css-loader#454

@michael-ciniawsky
Copy link
Member

@michael-ciniawsky michael-ciniawsky removed this from Refactor in Dashboard May 22, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants