You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a CSS asset main.css , 2 js assets vendor.js and index.js that my HtmlWebpakPlugin injets into html document. I have to enter the speific publicPath . It works via webpack's output.publicPath or as an option inside new HtmlWebpackPlugin(options). All works great but the thing is, i have to import one of the JS files from another public path. So, suppose i have to import main.css and main.js from https://cdn-1.com/assets and vendor.js from https://cdn-2.com/assets. To ahieve this, i decided to use Rule.generator.publichPath which can give specifi publicPath to assets that satisfy the test: regex condition. So this is my webpack config:
webpack.config.js
modules.exports={output: {
....publicPath: "https://cdn.mysite.com/",}...module: {rules: [{// first ruletest: /(main\.css|index\.js)$/,generator: {publicPath: "https://cdn-1.com/assets",}},{// second ruletest: /vendor\.js$/,generator: {publicPath: "https://cdn-2.com/assets",}},]}...plugins: [newHtmlWebpackPlugin({template: 'public/index.html',minify: true,// minify HTML }),],}
Html plugin totally ignores Rule.generator.publicPath variable and works only with output.publicPath (whether even if i have it or not, it still ignores Rule.generator.publicPath, even if i use public path inside HtmlWebpackPlugins options.
Expected behaviour ☀️
I would like that Rule.generator.publicPath is taken in account Rule.generator.publicPath when rendering an html document so all the and <script> elements have their src/href attributes exactly what i put inside Rule.generator.publicPath which adds more flexibility as to where to serve my assets from. I am not sure there are any ways to add specific public path to some certain assets using html document renderer of this plugin.
Reproduction Example 👾
webpack.config.js
modules.exports={output: {
....publicPath: "https://cdn.mysite.com/",}...module: {rules: [{// first ruletest: /(main\.css|index\.js)$/,generator: {publicPath: "https://cdn-1.com/assets",}},{// second ruletest: /vendor\.js$/,generator: {publicPath: "https://cdn-2.com/assets",}},]}...plugins: [newHtmlWebpackPlugin({template: 'public/index.html',minify: true,// minify HTML }),],}
Current behaviour 💣
I have a CSS asset
main.css
, 2 js assetsvendor.js
andindex.js
that my HtmlWebpakPlugin injets into html document. I have to enter the speificpublicPath
. It works via webpack'soutput.publicPath
or as an option insidenew HtmlWebpackPlugin(options)
. All works great but the thing is, i have to import one of the JS files from another public path. So, suppose i have to importmain.css
andmain.js
fromhttps://cdn-1.com/assets
andvendor.js
fromhttps://cdn-2.com/assets
. To ahieve this, i decided to useRule.generator.publichPath
which can give specifipublicPath
to assets that satisfy thetest: regex
condition. So this is my webpack config:webpack.config.js
Html plugin totally ignores
Rule.generator.publicPath
variable and works only withoutput.publicPath
(whether even if i have it or not, it still ignoresRule.generator.publicPath
, even if i use public path inside HtmlWebpackPlugins options.Expected behaviour ☀️
I would like that
Rule.generator.publicPath
is taken in accountRule.generator.publicPath
when rendering an html document so all the and <script> elements have theirsrc
/href
attributes exactly what i put insideRule.generator.publicPath
which adds more flexibility as to where to serve my assets from. I am not sure there are any ways to add specific public path to some certain assets using html document renderer of this plugin.Reproduction Example 👾
webpack.config.js
Environment 🖥
Node.js v14.17.3
win32 10.0.19042
npm version 6.14.13
[email protected]
[email protected]
The text was updated successfully, but these errors were encountered: