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 Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

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)

Hot Topics

Java Tutorial
1672
14
PHP Tutorial
1277
29
C# Tutorial
1256
24
HTML: The Structure, CSS: The Style, JavaScript: The Behavior HTML: The Structure, CSS: The Style, JavaScript: The Behavior Apr 18, 2025 am 12:09 AM

The roles of HTML, CSS and JavaScript in web development are: 1. HTML defines the web page structure, 2. CSS controls the web page style, and 3. JavaScript adds dynamic behavior. Together, they build the framework, aesthetics and interactivity of modern websites.

The Future of HTML, CSS, and JavaScript: Web Development Trends The Future of HTML, CSS, and JavaScript: Web Development Trends Apr 19, 2025 am 12:02 AM

The future trends of HTML are semantics and web components, the future trends of CSS are CSS-in-JS and CSSHoudini, and the future trends of JavaScript are WebAssembly and Serverless. 1. HTML semantics improve accessibility and SEO effects, and Web components improve development efficiency, but attention should be paid to browser compatibility. 2. CSS-in-JS enhances style management flexibility but may increase file size. CSSHoudini allows direct operation of CSS rendering. 3.WebAssembly optimizes browser application performance but has a steep learning curve, and Serverless simplifies development but requires optimization of cold start problems.

The Future of HTML: Evolution and Trends in Web Design The Future of HTML: Evolution and Trends in Web Design Apr 17, 2025 am 12:12 AM

The future of HTML is full of infinite possibilities. 1) New features and standards will include more semantic tags and the popularity of WebComponents. 2) The web design trend will continue to develop towards responsive and accessible design. 3) Performance optimization will improve the user experience through responsive image loading and lazy loading technologies.

HTML vs. CSS vs. JavaScript: A Comparative Overview HTML vs. CSS vs. JavaScript: A Comparative Overview Apr 16, 2025 am 12:04 AM

The roles of HTML, CSS and JavaScript in web development are: HTML is responsible for content structure, CSS is responsible for style, and JavaScript is responsible for dynamic behavior. 1. HTML defines the web page structure and content through tags to ensure semantics. 2. CSS controls the web page style through selectors and attributes to make it beautiful and easy to read. 3. JavaScript controls web page behavior through scripts to achieve dynamic and interactive functions.

HTML vs. CSS and JavaScript: Comparing Web Technologies HTML vs. CSS and JavaScript: Comparing Web Technologies Apr 23, 2025 am 12:05 AM

HTML, CSS and JavaScript are the core technologies for building modern web pages: 1. HTML defines the web page structure, 2. CSS is responsible for the appearance of the web page, 3. JavaScript provides web page dynamics and interactivity, and they work together to create a website with a good user experience.

HTML: Is It a Programming Language or Something Else? HTML: Is It a Programming Language or Something Else? Apr 15, 2025 am 12:13 AM

HTMLisnotaprogramminglanguage;itisamarkuplanguage.1)HTMLstructuresandformatswebcontentusingtags.2)ItworkswithCSSforstylingandJavaScriptforinteractivity,enhancingwebdevelopment.

Beyond HTML: Essential Technologies for Web Development Beyond HTML: Essential Technologies for Web Development Apr 26, 2025 am 12:04 AM

To build a website with powerful functions and good user experience, HTML alone is not enough. The following technology is also required: JavaScript gives web page dynamic and interactiveness, and real-time changes are achieved by operating DOM. CSS is responsible for the style and layout of the web page to improve aesthetics and user experience. Modern frameworks and libraries such as React, Vue.js and Angular improve development efficiency and code organization structure.

What is the difference between <strong>, <b> tags and <em>, <i> tags? What is the difference between <strong>, <b> tags and <em>, <i> tags? Apr 28, 2025 pm 05:42 PM

The article discusses the differences between HTML tags , , , and , focusing on their semantic vs. presentational uses and their impact on SEO and accessibility.

See all articles