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

typescript cannot find module when import svg file

It's web application created with Typescript, React and webpack. I want to use svg file through webpack. However, I got TS2307: Cannot find module '~/images/slide.svg'. Typescript files are put on /frontend/src/, and typescript files are…
hideto
  • 175
  • 1
  • 2
  • 6
14
votes
2 answers

How to inline fonts in CSS with webpack?

Problem background: I am using katex to render some math on a page. I then want to create a PDF version of part of that page, so I create a HTML document that containing the part to be exported that inlines all CSS and pass it to the renderer. The…
Axel
  • 13,939
  • 5
  • 50
  • 79
14
votes
2 answers

Got error: Plugin/Preset files are not allowed to export objects, only functions

I got this error while setup my react app using the webpack and babel. I try to change the version of babel but still getting the same error. I'm not getting where's the problem. ERROR in ./src/index.jsx Module build failed (from…
14
votes
4 answers

postcss-svgo: TypeError: Cannot set property 'multipassCount' of undefined (Gatsby)

On a Gatsby 2.17.6 project, when building: Building production JavaScript and CSS bundles [==== ] 1.940 s 1/6 17% run queries failed Building production JavaScript and CSS bundles - 75.519s ERROR #98123 WEBPACK Generating JavaScript bundles…
nosferatu
  • 374
  • 4
  • 14
14
votes
1 answer

Extremely long compile times with Vuetify 2.1 and Webpack

I am using Vue CLI 3 and Vuetify 2.1 in a new-ish project, and recently delved into overriding Vuetify's SASS variables. After finally getting it to work, I realized that each time I modify the variables.scss file that I created and the project…
J. Jackson
  • 3,326
  • 8
  • 34
  • 74
14
votes
3 answers

Webpack vs ES6 modules

I have recently started learning Webpack. What I have understood is that it bundles various assets like JavaScript, CSS, etc., into bundles. But regarding JavaScript, can't we achieve the same functionality with ES6 modules? For example, ideally…
Abhinandan Khilari
  • 947
  • 3
  • 11
  • 26
14
votes
1 answer

Exported function is undefined in bundle.js after webpack build

I have have build process that is managed by Webpack. It bundles all my files up and generates a single bundle.js file. Very typical pattern. However, when I include that file bundle.js in a webpage, the exported default function is undefined. Why…
calbear47
  • 1,060
  • 2
  • 18
  • 38
14
votes
3 answers

Webpack production mode - NODE_ENV undefined

I want to make production build of my app using webpack: "scripts": { "build": "webpack --mode production", }, In my webpack.config.js I have this line what I am using in whole config: const isDevelopment = process.env.NODE_ENV !==…
David Bubeník
  • 463
  • 6
  • 17
14
votes
5 answers

How to compress the files using gzip in react app

I have created a react app using create-react-app. I want to gzip the files during the build. I expect the files to be gziped
sai prasad
  • 151
  • 1
  • 1
  • 6
14
votes
3 answers

Webpack chunk names with Laravel Mix

I want to use Webpack chunks with Laravel Mix. At the moment this list is outputted: Asset Size Chunks Chunk Names /entry-point.js 3.37 MiB …
SPQRInc
  • 162
  • 4
  • 23
  • 64
14
votes
2 answers

How to prevent Vue global css overwriting itself multiple times

In my vue project I have some globally defined css, like a reset file etc. I load this css using the following in my vue.config: css: { loaderOptions: { sass: { data: ` @import "@/assets/styles/styles.scss"; `, }, …
jordvand9
  • 159
  • 2
  • 6
14
votes
2 answers

ENOTEMPTY: directory not empty, rmdir

I am new in NativeScript, I tried to run my HelloWord app using NativeScript and Angular. I connected my android device and then i run command tns run android its how me following error. Error: ENOTEMPTY: directory not empty, rmdir…
14
votes
2 answers

How do I import an IIFE-based JavaScript module into an Angular TypeScript app?

So I have a third-party SDK written as an oldschool IIFE based module. In other words it looks something like this: var ThirdPartySDK = (function() { var export = {}; // Add some methods to export return export; })(); You would then be…
Zac Delventhal
  • 3,543
  • 3
  • 20
  • 26
14
votes
1 answer

How to include additional ES6 sources in Angular app

I have a custom mode module written in ES6 syntax that I am including in my angular application and I am encountering problems (from uglifyjs) when I attempt to build the app with the -prod flag enabled: Unexpected token: punc () This is an angular…
mindparse
  • 6,115
  • 27
  • 90
  • 191
14
votes
6 answers

Webpack 4: mini-css-extract-plugin + file-loader not loading assets

I'm trying to move assets (images and fonts) used in one of my .scssfiles, but it seems that they get ignored: This is my .scss file: @font-face { font-family: 'myfont'; src: url('../../assets/fonts/myfont.ttf') format('truetype'); …
danielrvt
  • 10,177
  • 20
  • 80
  • 121