亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

【學習打卡】第3天 前端工程師2022版 webpack 第二講

標簽:
JavaScript

课程名称:前端工程师2022版

课程章节: webpack入门

主讲老师:elex

课程内容:

今天学习的内容包括:

webpack核心?什么是 plugins?

课程收获:

entry    入口,指定入口文件

    1. entry: './src/index.js'    单入口

    2. entry: {

            main: './src/index.js'

            search: './src/search.js'

        }


output    出口

    1. path: path.resolve(__dirname, 'dist')    输出文件夹

        path.resolve(__dirname, 'dist')    拼接内部地址,并格式化地址的方法

            __dirname    node 的根目录    

    2. filename: 'bundle.js'    输出文件名

        filename: '[name].js'    动态命名文件输出,推荐
        
        

什么是 plugins

1.插件

2.loader 被用于帮助 webpack 处理各种模块,而插件则可以用于执行范围更广的任务

3.其他插件 https://www.webpackjs.com/plugins/

html-webpack-plugin

1.安装html-webpack-plugin

  npm install --save-dev [email protected]

2.配置 html-webpack-plugin 插件

  在webpack.config.js中

头部添加const   HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports添加

      plugins: [

    // 单入口

    new HtmlWebpackPlugin({

     template: './index.html'(源码文件)

    })

    // 多页面时 html-webpack-plugin 插件的配置

    new HtmlWebpackPlugin({

      template: './index.html',

      filename: 'index.html',

      chunks: ['index'],

      // html-webpack-plugin 插件的其他功能

      minify: {

        // 删除 index.html 中的注释

        removeComments: true,

        // 删除 index.html 中的空格

        collapseWhitespace: true,

        // 删除各种 html 标签属性值的双引号

        removeAttributeQuotes: true

      }

    }),

    new HtmlWebpackPlugin({

      template: './search.html',

      filename: 'search.html',

      chunks: ['search']

    })

  ]

點擊查看更多內容
1人點贊

若覺得本文不錯,就分享一下吧!

評論

作者其他優質文章

正在加載中
感謝您的支持,我會繼續努力的~
掃碼打賞,你說多少就多少
贊賞金額會直接到老師賬戶
支付方式
打開微信掃一掃,即可進行掃碼打賞哦
今天注冊有機會得

100積分直接送

付費專欄免費學

大額優惠券免費領

立即參與 放棄機會
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號

舉報

0/150
提交
取消