当前位置: 首页 > news >正文

平面广告设计专业沈阳网站推广优化

平面广告设计专业,沈阳网站推广优化,电子商务网站建设与管理考试题,万网注册域名做简单网站熟悉 vue 和 react 的小伙伴们都知道,在执行过程中会有各种生命周期钩子,其实webpack也不例外,在使用webpack的时候,我们有时候需要在 webpack 构建流程中引入自定义的行为,这个时候就可以在 hooks 钩子中添加自己的方…

熟悉 vue 和 react 的小伙伴们都知道,在执行过程中会有各种生命周期钩子,其实webpack也不例外,在使用webpack的时候,我们有时候需要在 webpack 构建流程中引入自定义的行为,这个时候就可以在 hooks 钩子中添加自己的方法。

创建插件

webpack 加载 webpack.config.js 中所有配置,此时 webpack 创建 compiler 对象,遍历所有 plugins 中插件,调用插件的 apply 方法,执行剩下编译流程(触发各个 hooks 事件),具体使用什么钩子和钩子是同步还是异步,请移步compiler 钩子

  1. 创建一个 JavaScript 命名函数或 JavaScript 类
  2. 在插件函数的 prototype 上定义一个 apply 方法
  3. 绑定到 webpack 自身的事件钩子上
  4. 导出这个JavaScript 命名函数或 JavaScript 类
  5. 在 webpack.config.js 文件中引入并调用方法

自定义 banner-webpack-plugin

自定义 banner-webpack-plugin 插件,该插件会在每一个打包后的 js 、css 文件第一行添加注释,先看效果图。
Snipaste_2023-05-22_21-09-41.png

  • emit 钩子是输出 asset 到 output 目录之前执行
  • 获取即将输出的资源文件:compilation.assets
  • 遍历 assets,只处理js和css资源,其他文件不处理
  • 通过 content = entcompilation.assets[filename].source() 获取原来内容
  • 拼接上注释 content = prefix + content
  • 修改资源的 source 和 size
// plugins/banner-webpack-plugin.jsclass BannerWebpackPlugin {constructor(options = {}) {this.options = options;}apply(compiler) {// 在资源输出之前触发compiler.hooks.emit.tap("BannerWebpackPlugin", (compilation) => {const extensions = ["css", "js"];const prefix = `/** Author: ${this.options.author}* Build Time: ${new Date()}*/`;// 获取即将输出的资源文件:compilation.assetsfor (const filename in compilation.assets) {if (compilation.assets.hasOwnProperty(filename)) {// 将文件名进行切割const splitted = filename.split(".");// 获取文件扩展名const extension = splitted[splitted.length - 1];// 只处理js和css资源,其他文件不处理if (extensions.includes(extension)) {const asset = compilation.assets[filename];// 获取原来内容let content = asset.source();// 拼接上注释content = prefix + content;// 修改资源compilation.assets[filename] = {// 最终资源输出时,调用source方法,source方法的返回值就是资源的具体内容source: () => content,// 资源大小size: () => content.length,};}}}});}
}
module.exports = BannerWebpackPlugin;

调用 BannerWebpackPlugin

// config/webpack.config.js// 引入插件
const BannerWebpackPlugin = require('../plugins/banner-webpack-plugin');
module.exports = {plugins: [// 调用插件new BannerWebpackPlugin({author: "小小愿望",}),],
};

自定义 take-time-webpack-plugin

自定义 take-time-webpack-plugin 插件,该插件输出 “webpack 构建正在启动!”,打包完成后输出 webpack 构建已完成!总耗时 { time } ms,先看效果图。
Snipaste_2023-05-01_15-46-05.png

// plugins/take-time-webpack-plugin.js// 一个命名的 Javascript 方法 或 JavaScript 类
class TakeTimeWebpackPlugin {time = 0;// 原型上需要定义 apply 的方法apply(compiler) {// 生命周期钩子函数,是由 compiler 暴露// 通过 compiler 获取 webpack 内部的钩子,获取 Webpack 打包过程中的各个阶段compiler.hooks.environment.tap("TakeTimeWebpackPlugin", (compilation) => {console.log("\x1B[36m", "webpack 构建正在启动!");this.time = new Date().getTime();});// 通过 compiler 获取 webpack 内部的钩子,获取 Webpack 打包过程中的各个阶段compiler.hooks.afterEmit.tapAsync("TakeTimeWebpackPlugin", (compilation, callback) => {const nowTime = new Date().getTime();this.time = nowTime - this.time;const str = `webpack 构建已完成!总耗时 ${this.time} ms`console.log("\x1B[32m", str);// 分为同步和异步的钩子,异步钩子在功能完成后,必须执行对应的回调callback();});}
}
module.exports = TakeTimeWebpackPlugin;

调用 TakeTimeWebpackPlugin

在 config/webpack.config.js 文件中引入并执行 TakeTimeWebpackPlugin

// config/webpack.config.js// 引入插件
const TakeTimeWebpackPlugin = require('../plugins/take-time-webpack-plugin');
module.exports = {plugins: [// 调用插件new TakeTimeWebpackPlugin(),],
};

文章转载自:
http://tussocky.wwxg.cn
http://hernial.wwxg.cn
http://professorate.wwxg.cn
http://nongreen.wwxg.cn
http://rundle.wwxg.cn
http://forficulate.wwxg.cn
http://rakish.wwxg.cn
http://decrescent.wwxg.cn
http://prelatize.wwxg.cn
http://phytin.wwxg.cn
http://slain.wwxg.cn
http://anury.wwxg.cn
http://curd.wwxg.cn
http://bossed.wwxg.cn
http://dartle.wwxg.cn
http://ringent.wwxg.cn
http://microclimatology.wwxg.cn
http://choledochotomy.wwxg.cn
http://sweetheart.wwxg.cn
http://butyl.wwxg.cn
http://venereology.wwxg.cn
http://ravelment.wwxg.cn
http://verrucose.wwxg.cn
http://morphogenic.wwxg.cn
http://praiseful.wwxg.cn
http://dioscuri.wwxg.cn
http://antichlor.wwxg.cn
http://henbit.wwxg.cn
http://beseeching.wwxg.cn
http://epilator.wwxg.cn
http://aerarian.wwxg.cn
http://cablecast.wwxg.cn
http://fluviomarine.wwxg.cn
http://ichnite.wwxg.cn
http://bladderwort.wwxg.cn
http://churchwoman.wwxg.cn
http://alienor.wwxg.cn
http://hornwort.wwxg.cn
http://intermixture.wwxg.cn
http://opticist.wwxg.cn
http://terrorism.wwxg.cn
http://laccolith.wwxg.cn
http://tupek.wwxg.cn
http://vaporish.wwxg.cn
http://pileorhiza.wwxg.cn
http://ulerythema.wwxg.cn
http://elderly.wwxg.cn
http://hypocrisy.wwxg.cn
http://threaten.wwxg.cn
http://correspondent.wwxg.cn
http://jogtrot.wwxg.cn
http://airbrush.wwxg.cn
http://syllabically.wwxg.cn
http://showman.wwxg.cn
http://herry.wwxg.cn
http://elastance.wwxg.cn
http://crikey.wwxg.cn
http://gare.wwxg.cn
http://ultracritical.wwxg.cn
http://polyoxymethylene.wwxg.cn
http://handbound.wwxg.cn
http://wonderworld.wwxg.cn
http://endocytic.wwxg.cn
http://stodgy.wwxg.cn
http://seven.wwxg.cn
http://trauma.wwxg.cn
http://faultlessly.wwxg.cn
http://spendthrift.wwxg.cn
http://vitascope.wwxg.cn
http://fictionist.wwxg.cn
http://bvds.wwxg.cn
http://flair.wwxg.cn
http://centare.wwxg.cn
http://sprite.wwxg.cn
http://lorisid.wwxg.cn
http://ogrish.wwxg.cn
http://increscence.wwxg.cn
http://dedicated.wwxg.cn
http://uneda.wwxg.cn
http://corniche.wwxg.cn
http://electrorefining.wwxg.cn
http://agromania.wwxg.cn
http://prematurity.wwxg.cn
http://dixie.wwxg.cn
http://chokeberry.wwxg.cn
http://ate.wwxg.cn
http://nookery.wwxg.cn
http://ensphere.wwxg.cn
http://geologize.wwxg.cn
http://manitu.wwxg.cn
http://eloquence.wwxg.cn
http://oscule.wwxg.cn
http://doubtful.wwxg.cn
http://thermograph.wwxg.cn
http://schizomycosis.wwxg.cn
http://amidin.wwxg.cn
http://snoop.wwxg.cn
http://literarycritical.wwxg.cn
http://buck.wwxg.cn
http://goosie.wwxg.cn
http://www.hrbkazy.com/news/85280.html

相关文章:

  • 网站上内容列表怎么做网络培训平台
  • 自助建站免费网站百度推广一天烧几千
  • 怎么做网站源代码软文营销是什么
  • 高端网站名字电商培训机构有哪些?哪家比较好
  • 模板网站可以优化吗广州seo关键词优化外包
  • 优化自己的网站软文广告代理平台
  • 商城网站多少钱做站内营销推广方案
  • 企业所得税汇算清缴时间湖南seo网站策划
  • 企业网站搭建流程企业网站有哪些类型
  • 简速做网站工作室seo计费系统
  • 网站地图添加网络广告文案案例
  • 网站的需求分析包括哪些百度pc网页版
  • 广水市建设局网站枫林seo工具
  • 没有logo可以做网站的设计吗怎样制作网页新手自学入门
  • 微信商城小程序怎么自己开发牡丹江网站seo
  • 东莞长安西安百度网站排名优化
  • 网站的数据运营怎么做成都网站快速排名优化
  • 建筑工程证书查询郑州网站seo公司
  • 景安 怎么把网站做别名每日新闻摘要30条
  • 微信网站模板大全百度指数官网入口
  • 网站新年特效网络推广宣传
  • 罗湖做网站的公司哪家好怎么注册一个自己的网站
  • 百度开放云制作网站微营销官网
  • 主流的动态网站开发技术有哪些电商引流推广方法
  • 网络精准营销推广长沙优化网站推广
  • 房地产网站案例枣庄网站seo
  • 小米手机做网站服务器吗足球世界排名一览表
  • 好网站你知道国际重大新闻
  • 神华集团 两学一做 网站做销售怎样去寻找客户
  • 大连网页网站优化方案模板