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
3 answers

What does the lazy mode of webpack dev server do?

I am running my webpack-dev-server with webpack-dev-server --lazy --inline --progress --colors --port 8082 However this shows a 404 error in my browser when it tries to access bundle.js. Everything else seems fine since if i replace --lazy with…
pdeva
  • 43,605
  • 46
  • 133
  • 171
15
votes
1 answer

Angular 2: Cannot read property 'validator' of undefined

Ok so this is officially driving me mad now. I have two components in my Angular 2 app at the moment, each including a form. The signup form is working fine, but I am having trouble with my signin form. Most recently I have been using the signup…
serlingpa
  • 12,024
  • 24
  • 80
  • 130
15
votes
1 answer

Cannot start webpack-dev-server with gulp

When I run 'webpack-dev-server' from my terminal it runs fine : $ webpack-dev-server http://localhost:3333/ webpack result is served from /./assets/ content is served from C:\Users\Komo\Documents\work\training Hash: e705c984af7e83cbb685 Version:…
Komo
  • 2,043
  • 1
  • 22
  • 35
15
votes
2 answers

Handle WebPack CSS imports when testing with Mocha and Babel

When testing .js files that have Webpack CSS imports like import './style.css', Mocha throws a syntax error (because it tries to import and parse the CSS file as JS). There is a solution for this that has already been posted on Stack Overflow, but…
user3773571
15
votes
4 answers

React.js Decorators are not supported yet in 6.x pending proposal update

The technologies that i am using to build my app is React, Web-pack, Babel and AlT(flux implementation) I'm getting an error when web pack tries to compile my app. Not sure what libraries i am missing. Could someone please advice ? ##.babelrc…
Erkan Demir
  • 785
  • 1
  • 8
  • 24
15
votes
2 answers

webpack - require('node_modules/leaflet/leaflet.css')

So I'm trying to build a map app using webpack and leaflet. I can require leaflet.js from my map.js file, but I can't call leaflet.css without getting an error. My current webpack.config.js looks like: 'use strict' var webpack =…
hloughrey
  • 958
  • 3
  • 11
  • 22
15
votes
3 answers

Make webpack's library output compatible with babel6

Babel's 6th version changes the functioning of export default and in particular its relation with commonjs require. To summarise, while until babel5, require('module') where giving the default export of the module, it now always returns the module…
Quentin Roy
  • 7,677
  • 2
  • 32
  • 50
15
votes
2 answers

How to code HTML with jade and webpack with hot reload

I'm new with webpack, trying to setup simple config to code HTML/CSS with jade templates, PostCSS, hot reload and serve HTML through webpack-dev-server to speed up coding experience. So I will have multiple entry points, some jade files with…
arturkin
  • 958
  • 1
  • 6
  • 19
15
votes
4 answers

Module not found: Error: Cannot resolve module 'server'

I try to use webpack for managing files in my project. I use webpack-dev-server and bower-webpack-plugin. When I run server, I get error in browser console. Module not found: Error: Cannot resolve module 'server' webpack.config.js const…
Matt
  • 8,195
  • 31
  • 115
  • 225
15
votes
2 answers

Webpack dynamically create a module

I am writing a plugin which creates a SVG sprite. It globs over the directories, merge SVG files in one image and returns the result. The idea is to dynamically create a module (which contains merged images) so that other modules can require it as…
kisenka
  • 171
  • 8
15
votes
6 answers

How to shim tinymce in webpack?

I'm trying to get tinymce recognized by webpack. It sets a property named tinymce on window, so evidently one option is to require() it using syntax like this (described at the bottom of the EXPORTING section of the webpack…
Rob Johansen
  • 5,076
  • 10
  • 40
  • 72
15
votes
1 answer

Using webpack with an existing requirejs application

I am working with an existing application (canvas-lms) that uses RequireJS in its build system. I'm working on a pseudo-standalone application that plugs into Canvas (a "client_app" in Canvas parlance). This is a fontend-only app that makes API…
grahamb
  • 887
  • 3
  • 7
  • 22
15
votes
2 answers

Include direct link to webpack entry points in application HTML?

My webpack entry point includes a [hash] in the name: entry: "index.js", output: { path: "build/", filename: "index-[hash].js", } How can I link directly to that entry point from my application's HTML? For example, I'd like the HTML that's…
David Wolever
  • 148,955
  • 89
  • 346
  • 502
14
votes
5 answers

Uncaught TypeError: Cannot read properties of null (reading 'useContext')

so no where in my react code do I use the useContext property. I have a npm package which has a compiled webpack file that has a component in there. when i try to use the component in my react app it throw the error Uncaught TypeError: Cannot read…
Grant mitchell
  • 277
  • 1
  • 2
  • 12
14
votes
3 answers

how can I use top level "await" in typescript next.js

When I use "await" on top-level like this: const LuckyDrawInstance=await new web3.eth.Contract(abi) I got a warning on the terminal: "set experiments.topLevelAwait true". When I tried to add this to "tsconfig.json", it still does not work. it says…
Yilmaz
  • 35,338
  • 10
  • 157
  • 202