Closed
Description
Expected behaviour
in html, Can inject cdn dynamically through htmlWebpackPlugin.options
Current behaviour
it not work
Config
Copy the minimal webpack.config.js
to produce this issue:
module.exports = {
chainWebpack: config => {
config
.plugin('html')
.use(HtmlWebpackPlugin)
.tap(options => {
options.cdn = ['production', 'stage'].includes(process.env.NODE_ENV) ? cdn['build'] : cdn['dev']
return options
})
}
}
<% for (var i in htmlWebpackPlugin.options.cdn&&htmlWebpackPlugin.options.cdn.js) { %>
<script src="<%= htmlWebpackPlugin.options.cdn.js[i] %>"></script>
<% } %>
i don't know if delete preload caused it .
i delete reload, because htmlWebpackPlugin4.x seems to be in conflict with preload
Activity
jantimon commentedon Mar 24, 2020
Can you also change the webpack publicPath to be that cdn?
That would be picked up by the html-webpack-plugin automatically.
lijason1121 commentedon May 18, 2020
make sure your value of "publicPath" property in "output" is your cdn address.
stale commentedon Dec 12, 2020
This issue had no activity for at least half a year. It's subject to automatic issue closing if there is no activity in the next 15 days.
gary-dgc commentedon Oct 26, 2022
see you [.use(HtmlWebpackPlugin)], guess you get error:
[ Error: Cannot call .tap() on a plugin that has not yet been defined. Call plugin('html').use(<Plugin>) first.].
if you configured multi-pages in vue.config.js, the [plugin('html')] not exist in config, coz it's replaced with the multi-pages settings, to identify the correct html plugin name, you need to run command to list all the plugins:
Now you can use following to modify the plugin options