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
14
votes
1 answer

Async/Await not waiting

I'm running into an issue which I don't fully understand. I feel like there are likely concepts which I haven't grasped, code that could be optimized, and possibly a bug thrown in for good measure. To greatly simplify the overall flow: A request is…
ArrayKnight
  • 6,956
  • 4
  • 17
  • 20
14
votes
1 answer

Webpack UglifyJS remove dead code, but don't minimize code

How to remove dead code, but don't minimize code, using Webpack and UglifyJS?
Lunigorn
  • 1,340
  • 3
  • 19
  • 27
14
votes
3 answers

Webpack Error - Cannot Resolve File or Directory

I am getting this error when I npm start my webpack-dev-server: ERROR in multi main Module not found: Error: Cannot resolve 'file' or 'directory' /var/www/html/151208-DressingAphrodite/app in /var/www/html/151208-DressingAphrodite @ multi…
Kayote
  • 14,579
  • 25
  • 85
  • 144
14
votes
1 answer

Replacing/aliasing a file using Webpack

I am trying to use a very new third-party module in my project, which I installed using npm. The module was apparently developed on an OS with a case-insensitive file system, so it requires a file injectable.js whereas the actual file name is…
azangru
  • 2,644
  • 5
  • 34
  • 55
14
votes
1 answer

404 because of restarting the webpack-dev-server

I'm getting this in my developer tools when I try change my react component and save it to see if hot loader updated my page: GET http://localhost:3000/public/bundle/76566a1ad7e45b834d4e.hot-update.json 404 (Not Found)hotDownloadManifest @…
Liondancer
  • 15,721
  • 51
  • 149
  • 255
14
votes
1 answer

Dynamic require in Webpack at build time

Considering there's Webpack config ... entry: { 'bundle-with-dependency-a': 'common-entry.js', 'bundle-with-dependency-b': 'common-entry.js' }, resolve: { alias: { 'dep-a': ..., 'dep-b': ... }, }, and I would expect…
Estus Flask
  • 206,104
  • 70
  • 425
  • 565
14
votes
1 answer

chrome sometimes caching webpack://scripts wierdly

I use webpack as a module bundler I have map files enabled In chrome my original script files come from a special webpack resource I'm not too sure what causes it but sometimes an old version of a script gets cached. The actual new code is still…
undefined
  • 33,537
  • 22
  • 129
  • 198
14
votes
1 answer

Webpack can't resolve html-loader

I am converting a project using requirejs to webpack and having trouble with the "html-loader" loader. package.json: "html-loader": "^0.3.0", "webpack": "^1.11.0", "webpack-dev-server": "^1.10.1" app/js/webpack.config.js: // folder structure: …
jbarreiros
  • 1,103
  • 1
  • 10
  • 21
14
votes
2 answers

How to reconcile global webpack install and local loaders

My package.json includes webpack and some loaders: "devDependencies": { "babel-core": "^5.2.17", "babel-loader": "^5.0.0", "jsx-loader": "^0.13.2", "node-libs-browser": "^0.5.0", "webpack": "^1.9.4" } When I run webpack it's not in my…
Alex Mcp
  • 19,037
  • 12
  • 60
  • 93
14
votes
3 answers

Webpack HMR never updates the page

I've been messing around with different features of Webpack, and I'm slowly making sense of things. Typical console-output: [WDS] App updated. Recompiling... [WDS] App hot update... [HMR] Checking for updates on the server... [HMR] The following…
SimenB
  • 6,410
  • 2
  • 23
  • 27
14
votes
3 answers

Exclude a module from webpack bundle

I'd like the same functionality like RequireJS empty: http://requirejs.org/docs/optimization.html#empty My use-case is that I include jquery-migrate in development, but I'd like to exclude this when built for production. Using IgnorePlugin just…
SimenB
  • 6,410
  • 2
  • 23
  • 27
14
votes
1 answer

How to require 'ace-builds/ace' with Webpack and noParse option

I'm currently trying to require ace-builds (installed from bower) with webpack. Since it's a huge lib, I'm adding the whole folder to noParse option. I'm running webpack with -d option on terminal. The problem is: when my code tries to require it,…
gabrielhpugliese
  • 2,588
  • 19
  • 19
14
votes
4 answers

Environment Variables in an isomorphic JS app: Webpack find & replace?

I'm using webpack to bundle an isomorphic JS app (based on this example) so that the browser runs the same code as the server. Everything is running smoothly except I have a config.js with some settings which are pulled in from environment variables…
JP.
  • 5,507
  • 15
  • 59
  • 100
13
votes
4 answers

Brand new Rails 6.1.4.1 fails with webpack error - TypeError: Class constructor ServeCommand cannot be invoked without 'new'

A brand new Rails 6.1.4.1 app fails to run bin/webpack-dev-server with the following error: /rails_app/node_modules/webpack-cli/bin/utils/prompt-command.js:46 return func(...args); ^ TypeError: Class constructor ServeCommand cannot…
Scott K
  • 163
  • 1
  • 1
  • 9
13
votes
1 answer

When I update react-dev-utils to the @next version. I can't find typescriptFormatter and WatchMissingNodeModulesPlugin

when updating webpack from 4 to 5, I got the error: TypeError: message.split is not a function which is thrown in react-dev-utils/formatWebpackMessages.js. Then I update react-dev-utils to then @next version which fix this. However in the @next…
fawinell
  • 253
  • 4
  • 12
1 2 3
99
100