An warware: html-webpack-plug

Rubuta labari mai tsayi game da html-webpack-plugin ya ฦ™unshi bayanan fasaha kaษ—an, amma zan yi iya ฦ™oฦ™arina don warware shi ta hanyar mataki-mataki.

Fakitin gidan yanar gizon HTML yana sauฦ™aฦ™e ฦ™irฦ™irar fayilolin HTML don hidimar dauren fakitin gidan yanar gizon ku. Wannan yana da amfani musamman ga fakitin gidan yanar gizo waษ—anda suka haษ—a da zanta a cikin sunan fayil wanda ke canza kowane tarin. Kuna iya barin plugin ษ—in ya samar muku da fayil ษ—in HTML, sanya shi ya daidaita muku hashes, da riba.

Yanzu bari mu shiga cikin maganin matsalar gama gari da zaku iya fuskanta yayin amfani da fakitin gidan yanar gizon HTML.

Matsala na kowa

Bari mu ce kuna son shigar da rubutun cikin jiki ko shugaban HTML. Wannan ya haษ—a da duk ฦ™ugiya ta tsohuwa - ba abin da muke so ba.

Maganin matsalar

Anan ga kuskuren kuskuren cewa kai da tambarin jiki kawai za a iya amfani da su don allura. Za mu iya samun ฦ™arin zaษ“uษ“ษ“uka ta saita zaษ“in allura a cikin saitin kayan aikin gidan yanar gizon HTML.

Yanzu bari mu nutse cikin wasu codeing JavaScript don misalta wannan ta hanyar da ta fi dacewa.

new HtmlWebpackPlugin({
  inject: 'body',
  
  // Other configurations...
})

Wannan hanya ษ—aya ce ta yin ta. Hakanan zaka iya allurar rubutun a cikin kai kamar haka:

new HtmlWebpackPlugin({
  inject: 'head',
  
  // Other configurations...
})

Bayanin Mataki-Ta-Taki na Code

1. ' allura: jiki' Wannan yana shigar da fayilolin js da aka samar a cikin kasan alamar jikin a cikin wannan yanayin musamman muna tabbatar da cewa an loda duk fayilolin lokacin da muke son fara amfani da su.
2. ' allura: kai' Wannan yana nufin cewa za a sanya rubutun a cikin shugaban HTML.

A wasu lokuta, waษ—annan zaษ“uษ“ษ“ukan ฦ™ila ba su isa ba. Misali, idan muna da wuraren shigarwa da yawa kuma muna son sanya rubutun daban-daban a wurare daban-daban.

Dakunan karatu ko ayyukan da ke ciki

Fakitin Yanar Gizo shine madaidaicin tsarin bundler don aikace-aikacen JavaScript na zamani. Webpack yana ษ—aukar kayayyaki tare da abubuwan dogaro kuma yana haifar da kadarorin da ke wakiltar waษ—annan samfuran.

HtmlWebpackPlugin yana sauฦ™aฦ™a ฦ™irฦ™irar fayilolin HTML don hidimar dauren fakitin gidan yanar gizon ku. HtmlWebpack Plugin yana aiki ta farko yana samar da fayil ษ—in HTML, sannan shigar da rubutun fakitin yanar gizo cikin fayil ษ—in HTML da aka ฦ™irฦ™ira.

  • Shafin gidan yanar gizo
  • HtmlWebpackPlugin

Kamar yadda kuke gani, a wannan tafiya ta hanyar html-webpack-plugin mun tabo abubuwa daban-daban, daga fahimtar ainihin ayyukansa, don magance matsalolin gama gari, nutsewa cikin ษ“arna na lambar da kuma nuna mahimman ษ—akunan karatu da ayyukan da ke ciki.

Shafi posts:

Leave a Comment