您的位置:首頁技術文章
文章詳情頁

javascript - webpack dllPlugin如何打包vendor到html里面?

瀏覽:152日期:2023-03-12 14:11:17

問題描述

使用html-webpack-plugin只能將應用的bundle.js寫到html,不能將dll生成的vendor寫入,有沒有什么辦法?

問題解答

回答1:

可以使用 add-asset-html-webpack-plugin,將打包后的文件,加入html中。通過以下方式引用,或者參考下我的vue-2.0template

喜歡的話可以給個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:

自問自答:1、 將vendor.js生成到/dll/,2、 template.html使用html-webpack-plugin的模板語法

<body><script src='http://www.wxshucaidpc.com/wenda/<%= htmlWebpackPlugin.optiions.vendor %>'></script></body>

3、 設置webpack.dev.config.js

//...plugins:[ new HTMLPlugin({template: ’./src/template.html’,filename: ’index.html’vendor: ’/dll/’ + manifest.name + ’.js/’ //manifest就是dll生成的json })]

僅僅用于開發環境

標簽: JavaScript
相關文章:
国产综合久久一区二区三区