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

UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'startsWith' of undefined in antd and nextjs

I set up my nextjs project with ant design with all the latest version. When I am trying to configure the next.config.js file, this error is thrown. More specifically the error occurs when I add the webpack configuration. next dev ready - started…
Roomey Rahman
  • 244
  • 2
  • 6
14
votes
3 answers

Serving styles and assets with Webpack 5 module federation

I've successfully implemented the relatively new webpack 5 module federation system in my Angular 11 app, so it can load modules remotely on-demand from another build. One thing I've found nothing about is how to handle assets like stylesheets and…
John White
  • 917
  • 1
  • 12
  • 26
14
votes
3 answers

Webpack 5 and Storybook 6 integration throws an error in DefinePlugin.js

Working on Webpack 5 and Storybook integration in our React apps' repository. Mainly upgrading from Webpack v4 to v5 because its support has been announced here in this blog post officially. Following the suggested full instructions. With the below…
norbitrial
  • 14,716
  • 7
  • 32
  • 59
14
votes
1 answer

Mocking federated modules in host application for jest

Question is exactly same here in fact but has different context: How to mock not installed npm package in jest? I am part of a project where new Module Federation is used from webpack. Basically, I have a host app and it uses remote apps. I am doing…
14
votes
3 answers

Vue and Webpack tree shaking, sideEffects and CSS: CSS of unused components being loaded

We are trying to figure out the correct way of handling tree shaking for CSS in Vue Single File Components with Webpack. In package.json, I have: "sideEffects": ["*.css", "*.less","*.vue" ], this seems to be working properly for stopping Vue…
marcusds
  • 784
  • 1
  • 7
  • 26
14
votes
2 answers

Unable to resolve dependency tree with eslint-config-airbnb

when I'm trying to install eslint-config-airbnb with npx install-peerdeps --dev eslint-config-airbnb I'm getting following error (--legacy-peer-deps flag doesn't help): npm ERR! ERESOLVE unable to resolve dependency tree npm ERR! npm ERR! While…
Paweł
  • 387
  • 1
  • 3
  • 13
14
votes
1 answer

Webpack config problems

I'm taking over a small react tooling project someone else had stopped maintaining. However, I can't get it to run. It's a problem with the webpack config, and I've attempted to reconstruct it at as small a size as possible but I can't get it to…
fesieg
  • 467
  • 1
  • 4
  • 14
14
votes
2 answers

How to use babel/corejs3/webpack correctly for IE11?

With my current config (see below), I'm getting this error: [object Error]{description: "Argument ob...", message: "Argument ob...", name: "TypeError", number: -2147418113, stack: "TypeError: ...", Symbol()_7.bs7gi3oa3wi: undefined} I tried to…
Rhangaun
  • 1,430
  • 2
  • 15
  • 34
14
votes
4 answers

Can't find javascript source map to debug in chrome devtools

I'm using webpack in a .Net project to bundle my javascript files. I recently ran into a bug that I'd like to debug using chrome dev tools. In my webpack config file, I added the following line to generate source maps. devtool: 'source-map' After…
onTheInternet
  • 6,421
  • 10
  • 41
  • 74
14
votes
2 answers

Why is my React component library not tree-shakable?

I have a React component library that I’m bundling with rollup. Then I’m consuming that library in an app setup with create-react-app which uses Webpack under the hood. I expect Webpack to tree-shake the component library. After building the app…
borisdiakur
  • 10,387
  • 7
  • 68
  • 100
14
votes
2 answers

npm package.json aliases like webpack

i am trying to alias a module however i am not sure how to do that with package.json in webpack you would do something like this: module.exports = { //... resolve: { alias: { 'pixi.js': 'pixi.js-legacy' } } }; But what is the…
Marc Rasmussen
  • 19,771
  • 79
  • 203
  • 364
14
votes
3 answers

On webpack how can I import a script without evaluate it?

I'm recently working on some website optimization works, and I start using code splitting in webpack by using import statement like this: import(/* webpackChunkName: 'pageB-chunk' */ './pageB') Which correctly create the pageB-chunk.js, now let's…
小广东
  • 1,151
  • 12
  • 20
14
votes
1 answer

Why not possible to use ES imports in vue.config.js file with VueJS?

Why aren't ES imports working in vue.config.js file? In example: import * as path from 'path'; import * as pjson from './package.json'; module.exports = { configureWebpack: { resolve: { alias: { '@': path.join(__dirname,…
ux.engineer
  • 10,082
  • 13
  • 67
  • 112
14
votes
2 answers

Jsx is used without importing react

I am getting the Jsx is used without importing react Notification by WebStorm even tho I made react library global via: My webpack.config.js plugins: [ new webpack.ProvidePlugin({ React: "react" }) …
InsOp
  • 2,425
  • 3
  • 27
  • 42
14
votes
9 answers

TypeError: react__WEBPACK_IMPORTED_MODULE_2___default(...) is not a function. How do I solve this?

I was using React when I got the following error. TypeError: react__WEBPACK_IMPORTED_MODULE_2___default(...) is not a function How do I solve this? I have added the code below. import React from 'react'; import LoginForm from './loginForm' import…
Dark Programmer
  • 482
  • 3
  • 6
  • 18