Clean Webpack Plugin: Tsaftace Gina Tsabta

"CleanWebpackPlugin" sanannen plugin ne don Webpack hakan yana taimaka muku sarrafa kayan aikin ginin ku ta tsaftace ƙayyadaddun kundayen adireshi kafin ƙirƙirar sabbin fayiloli. Wannan na iya zama da amfani don hana tsofaffi ko fayilolin da ba dole ba daga tarawa a cikin kundin adireshin ginin ku. Ga taƙaitaccen bayanin yadda ake amfani da CleanWebpackPlugin:

Shigarwa

Da farko, tabbatar cewa kuna Webpack da kuma webpack-cli shigar a cikin aikinku, kamar yadda aka nuna a cikin bayanan baya. Sannan, shigar da CleanWebpackPlugin:

npm install clean-webpack-plugin --save-dev

Kanfigareshan

Bude webpack.config.js fayil ɗin ku kuma shigo da plugin ɗin:

const { CleanWebpackPlugin } = require('clean-webpack-plugin');

A cikin plugins tsararrun, sanya CleanWebpackPlugin:

module.exports = {  
  // ...other configuration options  
  
  plugins: [  
    new CleanWebpackPlugin()  
    // ...other plugins  
  ]  
};  

Ta hanyar tsoho, plugin ɗin zai tsaftace output.path ƙayyadaddun a cikin tsarin ku Webpack.

Kanfigareshan na Musamman

Kuna iya keɓance ɗabi'ar na'urar CleanWebpackPlugin ta hanyar wuce zaɓuka zuwa maginin sa. Misali:

new CleanWebpackPlugin({  
  cleanOnceBeforeBuildPatterns: ['**/*', '!importantFile.txt']  
})  

A cikin wannan misalin, za a share duk fayiloli da kundayen adireshi banda importantFile.txt.

Gudu Webpack

Lokacin da kuke gudu Webpack don gina aikin ku, CleanWebpackPlugin za a share ƙayyadaddun kundayen adireshi ta atomatik kafin ƙirƙirar sabbin fayilolin ginawa.

Ka tuna don koma zuwa ga takaddun hukuma na clean-webpack-plugin don ƙarin haɓakawa da zaɓuɓɓuka. Wannan plugin ɗin zai iya taimakawa sosai wajen kiyaye tsarin fitarwa mai tsabta da kuma guje wa ƙugiya mara amfani.