html-webpack-plugin外掛程式的詳細介紹和使用

來源:互聯網
上載者:User

標籤:模板引擎   href   根目錄   產生   public   demo   hot   dev   注入   

 1 var webpack = require(‘webpack‘); 2 var HtmlWebpackPlugin = require(‘html-webpack-plugin‘); 3 module.exports = { 4     devtool:‘eval-source-map‘, 5     devServer:{ 6         inline:true, 7         colors:true, 8         port:8080, 9         contentBase:__dirname + ‘/public‘10     },11     entry:{12         index:__dirname + ‘/app/index.js‘,13         main:__dirname + ‘/app/main.js‘14     },15     output:{16         path:__dirname + ‘/public‘, //通過HtmlWebpackPlugin外掛程式產生的html檔案存放在這個目錄下面17         filename:‘/js/[name].js‘ //編譯產生的js檔案存放到根目錄下面的js目錄下面,如果js目錄不存在則自動建立18     },19     plugins:[20         new HtmlWebpackPlugin({21             title:‘自動產生自訂標題‘,//這個配置不生效,好奇怪22             template:__dirname + ‘/public/tempIndex.html‘,//需要編譯的模板,可以是jade等第三方模板引擎也可以說純html頁面23             filename:‘demo.html‘,//最終產生的檔案名稱,預設是index.html24             hash:true,//是否給所有包含的js、css檔案後面添加hash值,可以用來清除緩衝,但好像不是很管用25             inject:true,// | ‘head‘ | ‘body‘ | false  ,注入所有的資源到特定的 template 或者 templateContent 中,如果設定為 true 或者 body,所有的 javascript 資源將被放置到 body 元素的底部,‘head‘ 將放置到 head 元素中。26             chunks:[‘index‘] //指定產生的檔案demo.hmtl需要包括entry裡的哪些入口檔案(這裡是index,main.js不會引入),不設定的話所以入口js檔案都會被引入進來27         }),28         new webpack.HotModuleReplacementPlugin() //熱載入29     ]30 }

 更詳細的介紹點擊這篇文章

html-webpack-plugin外掛程式的詳細介紹和使用

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.