How to configure file entry and file export in webpack
The content of this article is about the methods of configuring file entry and file export in webpack. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.
1. Create a js file as webpack.config.js, which is the configuration file of Webpack
webpack.config.js
module.exports={ entry:{}, //入口文件的配置项 output:{}, //出口文件的配置项 module:{}, //模块:例如解读CSS,图片如何转换,压缩 plugins:[], //插件,用于生产模版和各项功能 devServer:{}//配置webpack开发服务功能}
entry: configuration The address of the entry file can be a single entry or multiple entries.
output: Configure the address of the export file. After webpack2.X version, multiple export configurations are supported.
module: Configuration module, mainly for functions such as parsing CSS and image conversion and compression.
plugins: Configure plug-ins, configure plug-ins with different functions according to your needs.
devServer: Configure the development service function, we will explain it in detail later.
entry option (entry configuration)
entry option in wepback.config.js
//入口文件的配置项 entry:{ //里面的entery是可以随便写的 entry:'./src/entry.js'},
output option (export configuration)
//出口文件的配置项output:{ //打包的路径名称 path:path.resolve(__dirname,'dist'), //打包的文件名称 filename:'bundle.js' },
path.resolve(__dirname,'dist') //Is to obtain the absolute path of the project.
filename: is the name of the packaged file, here we name it bundle.js.
If you just write like this, you will get an error: the path cannot be found. So we need to introduce path in the head of webpack.config.js
const path = require(‘path’);
Now the code of webpack.config.js:
const path = require('path'); module.exports={ //入口文件的配置项 entry:{ entry:'./src/entry.js' }, //出口文件的配置项 output:{ //输出的路径,用了Node语法 path:path.resolve(__dirname,'dist'), //输出的文件名称 filename:'bundle.js' }, //模块:例如解读CSS,图片如何转换,压缩 module:{}, //插件,用于生产模版和各项功能plugins:[], //配置webpack开发服务功能devServer:{}}
Finally enter webpack in the terminal Packaging
Multi-entry and multi-exit configuration:
const path = require('path') //path是一个常量不能更改 ,path 需要引入var webpack = require('webpack') module.exports = { // bundle入口 entry:{ entry:'./src/entry.js', //下面的entry是随便起的名字 entry2:'./src/entry2.js' //有两个入口也要有两个出口 }, // bundle输出 output: { path: path.resolve(__dirname, 'dist'), //绝对路径 filename: '[name].js' //可重命名 当有多个入口文件时,出口文件用name,说明打包的出口文件和入口文件名相同 }, module:{}, plugins:[], devServer:{} }
Note: Two places have been modified: entrance and exit. Modify the meaning of
[name] It is packaged into the same name based on the name of the entry file. If there are several entry files, several files can be packaged.
Related recommendations:
Webpack multi-entry file page packaging details
How Webpack optimizes configuration files
The above is the detailed content of How to configure file entry and file export in webpack. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

If you bought your laptop from a mobile operator, you most likely had the option to activate an eSIM and use your cellular network to connect your computer to the Internet. With eSIM, you don't need to insert another physical SIM card into your laptop because it's already built-in. It is very useful when your device cannot connect to the network. How to check if my Windows 11 device is eSIM compatible? Click the Start button and go to Network & Internet > Cellular > Settings. If you don't see the "Cellular" option, your device doesn't have eSIM capabilities and you should check another option, such as using your mobile device to connect your laptop to a hotspot. In order to activate and

Why should we write the fixed file of the configuration file? We can directly write it as a .py file, such as settings.py or config.py. The advantage of this is that we can directly import parts of it through import in the same project; but if we need to use it in other When sharing configuration files on non-Python platforms, writing a single .py is not a good choice. At this time we should choose a common configuration file type to store these fixed parts. Currently, the commonly used and popular configuration file format types mainly include ini, json, toml, yaml, xml, etc. We can access these types of configuration files through standard libraries or third-party libraries.

Setting up a wireless network is common, but choosing or changing the network type can be confusing, especially if you don't know the consequences. If you're looking for advice on how to change the network type from public to private or vice versa in Windows 11, read on for some helpful information. What are the different network profiles in Windows 11? Windows 11 comes with a number of network profiles, which are essentially sets of settings that can be used to configure various network connections. This is useful if you have multiple connections at home or office so you don't have to set it all up every time you connect to a new network. Private and public network profiles are two common types in Windows 11, but generally

Recently, many Win10 system users want to change the user profile, but they don’t know how to do it. This article will show you how to set the user profile in Win10 system! How to set up user profile in Win10 1. First, press the "Win+I" keys to open the settings interface, and click to enter the "System" settings. 2. Then, in the opened interface, click "About" on the left, then find and click "Advanced System Settings". 3. Then, in the pop-up window, switch to the "" option bar and click "User Configuration" below.

Why write configuration files? During the development process, we often use some fixed parameters or constants. For these more fixed and commonly used parts, they are often written into a fixed file to avoid repetition in different module codes and keep the core code clean. We can directly write this fixed file into a .py file, such as settings.py or config.py. The advantage of this is that we can directly import parts of it through import in the same project; but if we need to do it on other non-Python platforms When configuring file sharing, writing a single .py is not a good choice. At this time we should choose a common configuration file type

Helm is an important component of Kubernetes that simplifies the deployment of Kubernetes applications by bundling configuration files into a package called HelmChart. This approach makes updating a single configuration file more convenient than modifying multiple files. With Helm, users can easily deploy Kubernetes applications, simplifying the entire deployment process and improving efficiency. In this guide, I'll cover different ways to implement Helm on Ubuntu. Please note: The commands in the following guide apply to Ubuntu 22.04 as well as all Ubuntu versions and Debian-based distributions. These commands are tested and should work correctly on your system. in U

An effective method to solve the garbled problem of eclipse requires specific code examples. In recent years, with the rapid development of software development, eclipse, as one of the most popular integrated development environments, has provided convenience and efficiency to many developers. However, you may encounter garbled code problems when using eclipse, which brings trouble to project development and code reading. This article will introduce some effective methods to solve the problem of garbled characters in Eclipse and provide specific code examples. Modify eclipse file encoding settings: in eclip

1. This method of writing the configuration in a Python file is very simple, but it has serious security issues. We all know that the configuration should not be written in the code. If someone uploads our source code to github, then the database The configuration is equivalent to being disclosed to the whole world. Of course, this simple method can also be used when the configuration file does not contain sensitive information. 2. Use external configuration files to separate configuration files and code. Usually, json, yaml or ini file formats are used to store configurations. Combining environment variables and python libraries to read external files. First of all, development usually does not come into contact with the generation environment, so the configuration file of the generation environment is written by operation and maintenance. After operation and maintenance writes the configuration required by the application, it is placed in
