javascript - webpack dllPlugin如何打包vendor到html里面?
問(wèn)題描述
使用html-webpack-plugin只能將應(yīng)用的bundle.js寫到html,不能將dll生成的vendor寫入,有沒有什么辦法?
問(wèn)題解答
回答1:可以使用 add-asset-html-webpack-plugin,將打包后的文件,加入html中。通過(guò)以下方式引用,或者參考下我的vue-2.0template
喜歡的話可以給個(gè)star
new HtmlWebpackPlugin({ filename: itemPath, template: template, inject: true, title: item.title || ’Document’, chunks: chunks, chunksSortMode: ’dependency’,}),new AddAssetHtmlPlugin([{ filepath: path.resolve(__dirname, config.build.dll.basePath, config.build.dll.fileName), outputPath: utils.assetsPath(’common/js/’), publicPath: path.join(config.build.publicPath, ’common/js’), includeSourcemap: true}])回答2:
自問(wèn)自答:1、 將vendor.js生成到/dll/,2、 template.html使用html-webpack-plugin的模板語(yǔ)法
<body><script src='http://www.leifengta.com.cn/wenda/<%= htmlWebpackPlugin.optiions.vendor %>'></script></body>
3、 設(shè)置webpack.dev.config.js
//...plugins:[ new HTMLPlugin({template: ’./src/template.html’,filename: ’index.html’vendor: ’/dll/’ + manifest.name + ’.js/’ //manifest就是dll生成的json })]
僅僅用于開發(fā)環(huán)境
相關(guān)文章:
1. node.js - mongodb查找子對(duì)象的名稱為某個(gè)值的對(duì)象的方法2. docker 17.03 怎么配置 registry mirror ?3. docker 下面創(chuàng)建的IMAGE 他們的 ID 一樣?這個(gè)是怎么回事????4. 前端 - @media query 使用出現(xiàn)的問(wèn)題?5. html5 - datatables 加載不出來(lái)數(shù)據(jù)。6. 運(yùn)行python程序時(shí)出現(xiàn)“應(yīng)用程序發(fā)生異常”的內(nèi)存錯(cuò)誤?7. 測(cè)試自動(dòng)化html元素選擇器元素ID或DataAttribute [關(guān)閉]8. javascript - QQ第三方登錄的問(wèn)題9. 利用IPMI遠(yuǎn)程安裝centos報(bào)錯(cuò)!10. spring-mvc - spring-session-redis HttpSessionListener失效

網(wǎng)公網(wǎng)安備