Questions tagged [webpack]

Webpack is a module bundler. Its main purpose is to bundle JavaScript files for usage in a browser, yet it can also transform, bundle, or package just about any resource or asset. Webpack takes modules with dependencies and generates static assets representing those modules. Webpack enables extensibility and promotes best practices in web architecture and performance.

Introduction

Webpack is a bundler for modules. The main purpose is to bundle JavaScript files for usage in a browser, yet it can also transform, bundle, or package just about any resource or asset.

TL;DR

  • Bundles ES Modules, CommonJS, and AMD modules (even combined).
  • Can create a single bundle or multiple chunks that are asynchronously loaded at runtime (to reduce initial loading time).
  • Dependencies are resolved during compilation, reducing the runtime size.
  • Loaders can preprocess files while compiling, e.g., TypeScript to JavaScript, Handlebars strings to compiled functions, images to Base64, etc.
  • Highly modular plugin system to do whatever else your application requires.

Get Started

Check out webpack's quick Get Started guide and the other guides.

Browser Compatibility

Webpack supports all browsers that are ES5-compliant (IE8 and below are not supported). Webpack also needs Promise for import() and require.ensure(). If you want to support older browsers, you will need to load a polyfill before using these expressions.

Support

Webpack Open Collective - Help support the teams' ongoing development efforts.

Community

Webpack Examples

Webpack Examples - Examples of common Webpack functionality.

License

MIT

Links

GitHub

Website

42504 questions
15
votes
9 answers

Angular-cli 'JavaScript heap out of memory' on asset optimization

I'm creating a leaflet map inside an Angular-cli project. Map tiles are stored locally in the 'assets' folder because it's a raster map. The problem is when I've many zoom levels of the map, I've more than 280 thousands images with approximate size…
Ahmed Abdelrahman
  • 778
  • 3
  • 12
  • 30
15
votes
3 answers

Webpack-dev-server proxy requests very slow

I am using webpack-dev-server proxy: devServer: { proxy: { '/api': { target: 'http://mybackedn.url', changeOrigin: true } } } Requests take too much time. Chrome network…
Sergey Tyupaev
  • 1,264
  • 9
  • 23
15
votes
1 answer

Using webpack 2 from gulp (webpack-stream for webpack 2)?

I am trying to update to webpack 2. I use webpack-stream to run stuff from gulp, but it appears that webpack-stream is using it's own dependency on webpack which is webpack 1. I have not been able to find any webpack-stream with webpack 2. Is there…
Ilya Chernomordik
  • 27,817
  • 27
  • 121
  • 207
15
votes
2 answers

Error: Please call "TestBed.compileComponents" before your test

I'm getting this error: Error: This test module uses the component MessagesComponent which is using a "templateUrl", but they were never compiled. Please call "TestBed.compileComponents" before your test. When trying to run this simple test…
CommonSenseCode
  • 23,522
  • 33
  • 131
  • 186
15
votes
5 answers

Switching from Gulp to Webpack

UPDATE 30.04.20 [ Moving to Webpack ] My first question is about how recommended is this switch for simple projects, just to Pre-Process/Concat/Minify? Understanding this future "standards", like Webpack in together with…
Locke
  • 629
  • 1
  • 5
  • 21
15
votes
13 answers

webpack hangs at on "95% emit" / "95% emitting"

This is my production webpack config. The two quotes in the title refer to webpack2 and webpack respectively. Both hang for me with a similar error. This is my command to trigger the build set NODE_ENV=production && webpack --config…
bitten
  • 2,463
  • 2
  • 25
  • 44
15
votes
3 answers

serve public static files with webpack

I struggle to get webpack configured as I want it to be. I run my dev-server on localhost:8080 and want to serve my app through localhost:8080/static/js/bundle.js and that is what I get with this webpack.config.js file I've attached below. in my…
Dima Gimburg
  • 1,376
  • 3
  • 17
  • 35
15
votes
3 answers

What exactly am I supposed to do with "module.exports = 'html_template_content'" on webpack

So I want to do a very simple task using webpack. I have a few static HTML templates like e.g. test.html
template content
and all I want to do is return the string inside the template e.g require("raw!./test.html") with…
user3531149
  • 1,519
  • 3
  • 30
  • 48
15
votes
3 answers

Webpack - Style sheet loading but no fonts

I am able to see my stylesheet in the page without problems. However I cannot get my webfonts to work. I have tried to save the output of my css which doesn't happen. I believe this is why the fonts aren't working. Webpack var webpack = require…
Jamie Hutber
  • 26,790
  • 46
  • 179
  • 291
15
votes
2 answers

Modules import and destructuring performances

I recently read on Material-UI's docs: Notice that in the above example, we used: import RaisedButton from 'material-ui/RaisedButton' instead of import {RaisedButton} from 'material-ui' This will make your build process faster and your build output…
Cohars
  • 3,822
  • 1
  • 29
  • 50
15
votes
2 answers

what is require.resolve in webpack loader test

I am learning this imports-loader on webpack. I've already built several webpack demo projects by following tutorials. Here is the code to configure imports-loader: // ./webpack.config.js module.exports = { ... module: { loaders:…
Nicolas S.Xu
  • 13,794
  • 31
  • 84
  • 129
15
votes
3 answers

ReactDom is undefined

I am using React with Webpack and Babel. I am getting a runtime error: Uncaught ReferenceError: ReactDom is not defined My react version is: "devDependencies": { "phantomjs-polyfill": "0.0.2", "react-addons-test-utils": "^0.14.8" }, …
Yaniv Efraim
  • 6,633
  • 7
  • 53
  • 96
15
votes
1 answer

Webpack: how to bundle entries to multiple common chunks with CommonsChunkPlugin?

Say I have two pages Page1 and Page2, both of them use some library(vendors) like jquery backbone which I want to be extracted as a single file, then I want the shared modules(exclude the vendors) to be extracted in another single file, this is the…
hguser
  • 35,079
  • 54
  • 159
  • 293
15
votes
1 answer

Webpack loads from the wrong URL when the path changes

I'm writing a react app and everything works fine when I navigate to localhost:3000, but when I try to go to localhost:3000/foo/page, I get an error message that tells me localhost:3000/foo/bundle.js cannot be loaded. To me, this looks like a…
Brandon Olivier
  • 578
  • 5
  • 16
15
votes
2 answers

How to display a progress bar while loading single bundled javascript file by webpack?

The question is concerning webpack. After packing almost everything into a single bundle.js which is loaded in index.html, the bundle.js file is about 2M and requires several seconds to load. I'd like to display a progress bar indicating loading…
Nicolas S.Xu
  • 13,794
  • 31
  • 84
  • 129