Table of Contents
According to the js compression mentioned in the previous article, npm run server will report an error after running " >According to the js compression mentioned in the previous article, npm run server will report an error after running
1. Packaging of html files
Home Web Front-end HTML Tutorial How to package html files? Introduction to the method of packaging html files

How to package html files? Introduction to the method of packaging html files

Aug 18, 2018 pm 03:38 PM

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 login
    i 「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 login

    The 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 login
    • Delete 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:

    Write your own HTML and package it with Cordova What are the differences between using AppCan, Dcloud, WeX5, and ApiCloud?

    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!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Is HTML easy to learn for beginners? Is HTML easy to learn for beginners? Apr 07, 2025 am 12:11 AM

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.

The Roles of HTML, CSS, and JavaScript: Core Responsibilities The Roles of HTML, CSS, and JavaScript: Core Responsibilities Apr 08, 2025 pm 07:05 PM

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.

What is an example of a starting tag in HTML? What is an example of a starting tag in HTML? Apr 06, 2025 am 12:04 AM

AnexampleofastartingtaginHTMLis,whichbeginsaparagraph.StartingtagsareessentialinHTMLastheyinitiateelements,definetheirtypes,andarecrucialforstructuringwebpagesandconstructingtheDOM.

Understanding HTML, CSS, and JavaScript: A Beginner's Guide Understanding HTML, CSS, and JavaScript: A Beginner's Guide Apr 12, 2025 am 12:02 AM

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

Gitee Pages static website deployment failed: How to troubleshoot and resolve single file 404 errors? Gitee Pages static website deployment failed: How to troubleshoot and resolve single file 404 errors? Apr 04, 2025 pm 11:54 PM

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

How to implement adaptive layout of Y-axis position in web annotation? How to implement adaptive layout of Y-axis position in web annotation? Apr 04, 2025 pm 11:30 PM

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...

How to use CSS3 and JavaScript to achieve the effect of scattering and enlarging the surrounding pictures after clicking? How to use CSS3 and JavaScript to achieve the effect of scattering and enlarging the surrounding pictures after clicking? Apr 05, 2025 am 06:15 AM

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...

Why do you need to call Vue.use(VueRouter) in the index.js file under the router folder? Why do you need to call Vue.use(VueRouter) in the index.js file under the router folder? Apr 05, 2025 pm 01:03 PM

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...

See all articles