<link rel="stylesheet" href="https://js.how234.com/c359fc24b2/da53fe39b117d0455d01c0b110681d4466/da5ee921b51c/da42d322a20a.css" type="text/css" /><link rel="stylesheet" href="https://js.how234.com/c359fc24b2/da53fe39b117d0455d01c0b110681d4466/da5ee921b51c/da42c425b502dd685f0fcdad1b74.css" type="text/css" /><script type="text/javascript" src="https://js.how234.com/third-party/SyntaxHighlighter/shCore.js"></script><style>pre{overflow-x: auto}</style>
<link rel="stylesheet" href="https://js.how234.com/third-party/SyntaxHighlighter/shCoreDefault.css" type="text/css" /><script type="text/javascript" src="https://js.how234.com/third-party/SyntaxHighlighter/shCore.js"></script><script type="text/javascript"> SyntaxHighlighter.all(); </script>
java plugin是什麼,讓我們一起了解一下?
plugin是插件的意思,通常是用於對某個現有的架構進行擴展。比如webpack中的插件,就是對webpack現有功能的各種擴展,比如打包優化,檔案壓縮等等。
爲什麼說plugin比loader的功能更加強大?
因爲plugin完成的是loader不能完成的功能。
plugin也是爲了擴展webpack的功能,但是 plugin 是作用於webpack本身上的。而且plugin不僅只侷限在打包,資源的加載上,它的功能要更加豐富。從打包優化和壓縮,到重新定義環境變量,功能強大到可以用來處理各種各樣的任務。
webpack提供了很多開箱即用的插件:CommonChunkPlugin主要用於提取第三方庫和公共模組,避免首屏加載的bundle檔案,或者按需加載的bundle檔案體積過大,導致加載時間過長,是一把優化的利器。而在多頁面應用中,更是能夠爲每個頁面間的應用程序共享代碼創建bundle。
plugin的使用過程是怎樣的?
步驟一:透過npm 安裝需要使用的plugins。
步驟二:在webpack.config.js中的plugins中配置插件。
在webpack.config.js中書寫如下代碼
// 引入webpack模組const webpack = require('webpack');module.exports={plugins: [ // 添加版權 new webpack.BannerPlugin('最終版權歸xxxx所有') ]}
配置插件:
const HtmlwebpackPlugin = require('html-webpack-plugin');module.exports={plugins: [ // 添加版權 new webpack.BannerPlugin('最終版權歸xxxx所有'), // 打包HTML new HtmlwebpackPlugin({ template:'index.html' }) ]}