


How to package html files? Introduction to the method of packaging html files
The content of this article is about how to package html files? The introduction to the method of packaging html files has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.
According to the js compression mentioned in the previous article, npm run server will report an error after running
To understand this problem, we must first figure it out Know what is a development environment and what is a production environment. JS is basically not compressed in the development environment. During development preview, we need to clearly indicate the number of error lines and error information, so there is no need to compress JavaScript code. Only in the production environment will JS code be compressed to speed up the work efficiency of the program. devServer is used in the development environment, while compressed JS is used in the production environment. In the development environment, the production environment is done, so Webpack sets up conflict reporting.
Compressed js in the production environment will not be able to debug (the line cannot be found)
In actual development, the webpack configuration files are separated, one file for the development environment and one file for the production environment.
1. Packaging of html files
Cut and copy the index.html under the dist directory to the src directory, and the js introduced in index.html The code can be deleted (js code will be automatically introduced), this is the template file
-
Introduce the plug-in in webpack-config.js
plugins:[ new htmlPlugin({ minify:{ removeAttributeQuotes:true //对html进行压缩,去掉属性的双引号 }, hash:true, //为了开发中js有缓存效果,加入hash可以有效避免缓存JS template:'./src/index.html' //是要打包的html模板路径和文件名称 }) ]
Copy after logini 「wds」: Project is running at http://10.212.109.18:8087/ i 「wds」: webpack output is served from / i 「wds」: Content not from webpack is served from F:\webLearn\webpackLearn\dist ‼ 「wdm」: Hash: 027dd749b565ba3b200d Version: webpack 4.15.1 Time: 3008ms Built at: 2018-07-11 08:49:13 Asset Size Chunks Chunk Names entry2.js 139 KiB 0 [emitted] entry2 entry.js 145 KiB 1 [emitted] entry index.html 427 bytes [emitted] Entrypoint entry = entry.js Entrypoint entry2 = entry2.js
Copy after loginThe above code appears That is, it is successful
The packaging is successful as shown below
Hash: 40112e2b8d4dc81b512b Version: webpack 4.15.1 Time: 5299ms Built at: 2018-07-11 08:47:26 Asset Size Chunks Chunk Names entry2.js 962 bytes 0 [emitted] entry2 entry.js 6.75 KiB 1 [emitted] entry index.html 427 bytes [emitted] [0] ./src/entry2.js 33 bytes {0} [built] [4] ./node_modules/css-loader!./src/css/index.css 227 bytes {1} [built] [5] ./src/css/index.css 1.06 KiB {1} [built] [6] ./src/entry.js 94 bytes {1} [built] + 3 hidden modules WARNING in configuration The 'mode' option has not been set, webpack will fallback to 'production' for this value. Set 'mode' option to 'development' or 'production' to enable defaults for each environment. You can also set it to 'none' to disable any default behavior. Learn more: https://webpack.js.org/concepts/mode/ Child html-webpack-plugin for "index.html": 1 asset [0] (webpack)/buildin/module.js 497 bytes {0} [built] [1] (webpack)/buildin/global.js 489 bytes {0} [built] [3] ./node_modules/html-webpack-plugin/lib/loader.js!./src/index.html 511 bytes {0} [built] + 1 hidden module
Copy after loginDelete the dist directory and run it in the terminal Enter webpack for packaging
Enter npm run dev in the terminal and run it in the browser
The configuration in the plugins is as follows:
const htmlPlugin=require('html-webpack-plugin');
Install in the terminal: npm install –save-dev html-webpack-plugin
Configure html
Related recommendations:
How to package css files? How to package css files
The above is the detailed content of How to package html files? Introduction to the method of packaging html files. 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



HTML is suitable for beginners because it is simple and easy to learn and can quickly see results. 1) The learning curve of HTML is smooth and easy to get started. 2) Just master the basic tags to start creating web pages. 3) High flexibility and can be used in combination with CSS and JavaScript. 4) Rich learning resources and modern tools support the learning process.

HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.

AnexampleofastartingtaginHTMLis,whichbeginsaparagraph.StartingtagsareessentialinHTMLastheyinitiateelements,definetheirtypes,andarecrucialforstructuringwebpagesandconstructingtheDOM.

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

GiteePages static website deployment failed: 404 error troubleshooting and resolution when using Gitee...

The Y-axis position adaptive algorithm for web annotation function This article will explore how to implement annotation functions similar to Word documents, especially how to deal with the interval between annotations...

To achieve the effect of scattering and enlarging the surrounding images after clicking on the image, many web designs need to achieve an interactive effect: click on a certain image to make the surrounding...

The necessity of registering VueRouter in the index.js file under the router folder When developing Vue applications, you often encounter problems with routing configuration. Special...
