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
340
votes
8 answers

babel-loader jsx SyntaxError: Unexpected token

I'm a beginner in React + Webpack. I found a weird error in my hello world web app. I'm using babel-loader in webpack to help me convert jsx into js, but it seems like babel can't understand jsx syntax. Here are my dependencies: "devDependencies":…
Keyu Lin
  • 3,669
  • 3
  • 12
  • 8
337
votes
43 answers

Field 'browser' doesn't contain a valid alias configuration

I've started using webpack2 (to be precise, v2.3.2) and after re-creating my config I keep running into an issue I can't seem to solve I get (sorry in advance for ugly dump): ERROR in ./src/main.js Module not found: Error: Can't resolve…
Matthew Herbst
  • 29,477
  • 23
  • 85
  • 128
327
votes
32 answers

The create-react-app imports restriction outside of src directory

I am using create-react-app. I am trying to call an image from my public folder from a file inside my src/components. I am receiving this error message. ./src/components/website_index.js Module not found: You attempted to import…
David Brierton
  • 6,977
  • 12
  • 47
  • 104
313
votes
2 answers

What exactly is Hot Module Replacement in Webpack?

I've read a few pages about Hot Module Replacement in Webpack. There's even a sample app that uses it. I've read all of this and still don't get the idea. What can I do with it? Is it supposed to only be used in development and not in…
Dan Abramov
  • 264,556
  • 84
  • 409
  • 511
311
votes
29 answers

How to add font-awesome to Angular 2 + CLI project

I'm using Angular 2+ and Angular CLI. How do I add font-awesome to my project?
Nik
  • 7,086
  • 6
  • 36
  • 52
309
votes
9 answers

What does "publicPath" in Webpack do?

Webpack docs state that output.publicPath is: The output.path from the view of the JavaScript. Could you please elaborate on what this actually means? I use output.path and output.filename to specify where Webpack should output the result, but I’m…
Misha Moroshko
  • 166,356
  • 226
  • 505
  • 746
306
votes
8 answers

ES6 exporting/importing in index file

I am currently using ES6 in an React app via webpack/babel. I am using index files to gather all components of a module and export them. Unfortunately, that looks like this: import Comp1_ from './Comp1.jsx'; import Comp2_ from './Comp2.jsx'; import…
MoeSattler
  • 6,684
  • 6
  • 24
  • 44
300
votes
5 answers

Webpack style-loader vs css-loader

I have two questions. 1) CSS Loader and Style Loader are two webpack loaders. I couldn't grasp the difference between the two. Why do I have to use two loaders when they both do the same job? 2) What is this .useable.less and .useable.css mentioned…
Anvesh Checka
  • 3,787
  • 2
  • 21
  • 28
282
votes
25 answers

I am getting an "Invalid Host header" message when connecting to webpack-dev-server remotely

I am using as an environment, a Cloud9.io ubuntu VM Online IDE and I have reduced by troubleshooting this error to just running the app with Webpack dev server. I launch it with: webpack-dev-server -d --watch --history-api-fallback --host $IP…
Artur Vieira
  • 4,539
  • 3
  • 11
  • 9
269
votes
14 answers

How to build minified and uncompressed bundle with webpack?

Here's my webpack.config.js var webpack = require("webpack"); module.exports = { entry: "./entry.js", devtool: "source-map", output: { path: "./dist", filename: "bundle.min.js" }, plugins: [ new…
Mulan
  • 129,518
  • 31
  • 228
  • 259
257
votes
13 answers

How to create multiple output paths in Webpack config

Does anyone know how to create multiple output paths in a webpack.config.js file? I'm using bootstrap-sass which comes with a few different font files, etc. For webpack to process these i've included file-loader which is working correctly, however…
spb
  • 4,049
  • 6
  • 22
  • 30
255
votes
18 answers

How can I use ES6 in webpack.config.js?

How to use ES6 in webpack.config ? Like this repo https://github.com/kriasoft/react-starter-kit does ? For instance: using this import webpack from 'webpack'; instead of var webpack = require('webpack'); It is quite a curiosity rather than a…
Whisher
  • 31,320
  • 32
  • 120
  • 201
245
votes
27 answers

Typescript react - Could not find a declaration file for module ''react-materialize'. 'path/to/module-name.js' implicitly has an any type

I am trying to import components from react-materialize as - import {Navbar, NavItem} from 'react-materialize'; But when the webpack is compiling my .tsx it throws an error for the above as - ERROR in ./src/common/navbar.tsx (3,31): error TS7016:…
Joy
  • 6,438
  • 8
  • 44
  • 75
237
votes
14 answers

How to make the webpack dev server run on port 80 and on 0.0.0.0 to make it publicly accessible?

I am new to the whole nodejs/reactjs world so apologies if my question sounds silly. I am currently playing around with reactabular.js. Whenever I do a npm start it always runs on localhost:8080. How do I change it to run on 0.0.0.0:8080 to make it…
90abyss
  • 7,037
  • 19
  • 63
  • 94
235
votes
31 answers

Cannot find module 'webpack/bin/config-yargs'

Getting error when running webpack-dev-server --config config/webpack.dev.js --progress --profile --watch --content-base src/. Here is the error log: module.js:442 throw err; ^ Error: Cannot find module 'webpack/bin/config-yargs' at…
Aleksandar Terziev
  • 2,498
  • 2
  • 11
  • 10