Webpack 5 learning notes
1 Introduction to webpack
1.1 what is a webpack
Webpack is a front-end resource building tool, a static module bundler. In the view of webpack, all resource files (js/json/css/img/less /...) of the front end will be processed as modules. It will perform static analysis according to the dependency of the module and package the corresponding st ...
Added by Acs on Mon, 27 Dec 2021 19:18:54 +0200
Ten thousand word long text decryption webpack - basic use / advanced usage / performance optimization you have everything you want!!!
It's not easy to refuse to pay a compliment
preface
In essence, webpack is a static module packaging tool for modern JavaScript applications. When webpack processes an application, it will internally build a dependency graph from one or more entry points, and then combine each module required in your project into one or more bundles, wh ...
Added by idealbrain on Mon, 20 Dec 2021 15:29:57 +0200
webpack advanced application: creating a library
In addition to packaging applications, webpack can also be used to package JavaScript libraries. The following applies to library authors who want to simplify the packaging strategy.
Create a library
Suppose we are writing a small library called my math, which contains addition and subtraction.
The basic project structure may be as fol ...
Added by xnowandtheworldx on Mon, 20 Dec 2021 15:22:16 +0200
webpack advanced applications: Polyfills
Polyfills
npm install --save @babel/polyfill
Then, import it into our main bundle file:
import '@babel/polyfill'
console.log(Array.from([1, 2, 3], x => x + x))
Note that this approach gives priority to correctness rather than bundle size. In order to be safe and reliable, polyfill/shim must run before all other codes and need to be loa ...
Added by djdaz on Sun, 19 Dec 2021 22:37:59 +0200
43 webpack optimization - Code splitting
Code segmentation
So far, the output of build JS contains javaScript and Css code, and the dependent modules used in the project will also be packaged into build JS JS is huge. It's loading build JS will take a lot of time, resulting in slow page loading. Therefore, the output files need to be reasonably divided to generate multiple multi type ...
Added by tadapapaya on Wed, 15 Dec 2021 23:02:32 +0200
The most complete summary of webpack
webpack
install
Before installation, initialize the project to generate package JSON file
npm init -y
npm init
Next, install webpack and webpack cli
npm i webpack webpack-cli --save
Configure command line
In package The startup command is configured in the scripts field of the JSON file
"scripts":{
"test": "echo \"Error: no test ...
Added by rockstar_tom on Tue, 14 Dec 2021 03:25:49 +0200
[gecko technology] front end mobile terminal and PC terminal adaptive solution, supporting vite packaging configuration
demandMobile terminal adaptationpc side adaptation (within a certain screen range)Implementation principleUsing amfe flexible and postcss px2rem dependency packages, PX is automatically converted to REM after the project is compiled, and the font size value of html will be changed dynamically according to the screen sizeIf you want to understan ...
Added by Kyrillos on Fri, 10 Dec 2021 12:02:58 +0200
Webpack optimized development experience
Webpack Dev ServerIt integrates the functions of automatic compilation and automatic refresh of browser. The webpack dev server does not write to any output files after compilation, but keeps the bundle files in memory and then serves them to the server.yarn add webpack-dev-server --devconst path = require("path");
const { CleanWebpackPlugin } ...
Added by Mastodont on Tue, 30 Nov 2021 09:57:58 +0200
webpack learning notes
webpack function: handle code compression confusion, browser js compatibility and performance optimization
webpack installation process in the project
1,
NPM I webpack webpack cli - g / / global installation of webpack (required)
npm i Webpack@5.42.1 Webpack- cli@4.7.2 -D / / partially install Webpack to the project (required)
2,
webpac ...
Added by oeb on Thu, 18 Nov 2021 14:51:51 +0200
Daily learning: scaffold vueCli, arrow function, front-end routing, vue router, dynamic routing and parameter transfer, navigation guard
Scaffold vueCli
vueCli facilitates the rapid establishment of vue development environment and corresponding webpack configuration. The pre dependencies are node, npm and webpack. Manual use of webpack requires manual introduction of various loader s and plugin s, and handling the compatibility of versions;
// View version
node -v,npm -v,web ...
Added by plasmahba on Fri, 12 Nov 2021 06:30:21 +0200