1. Introduction to webpack
1. What is webpack?
Essentially, webpack is a static module bundler for modern JavaScript applications. When webpack
processes an application, it recursively builds a dependency
graph (dependency graph) that contains every module that the application needs, and then packages all these modules into one or more bundles.
2.Webpack role
- Package (package multiple files into one js file to reduce server pressure and bandwidth)
- Conversion (such as less sass ts) requires loader
- Optimization (SPA is more and more popular, front-end projects are highly responsible, and webpack can optimize projects)
3.Webpack composition
- Entry
- Export
- Converter loaders
- Plugins
- Development server
- devServer
- Mode
See the official website for specific concepts
Two, webpack installation
前提条件:
Make sure the computer before installing webpack on node.js already installed, if not installed can go to the official website to download
1. Global installation
npm install --global webpack
2. Local installation
npm install --save-dev webpack
If you are using webpack 4+ version, you also need to install CLI.
npm install --save-dev webpack-cli
3. Install a specific version
npm install --save-dev webpack@<version>
npm install --save-dev
abbreviation: npm install -D is
only installed in the development environment, not in the production environment
·
npm install --save
abbreviation: npm install -S
is installed in both development and production environments