icelam / html-inline-script-webpack-plugin

A webpack plugin for converting external script files to inline script block. Requires 'html-webpack-plugin' to work.
https://www.npmjs.com/package/html-inline-script-webpack-plugin
MIT License
55 stars 10 forks source link

fix: resolve public path base on html-webpack-plugin and webpack config #448

Closed icelam closed 1 year ago

icelam commented 1 year ago

Description

Fix #447.

When using html-webpack-plugin to set a filename for a HTML file, the file does not necessarily need to be located in the same folder as output.path. If the filename includes a folder, it will be output to a child folder. This can cause the script assets to have a different public path than the one set in the output.publicPath of webpack.

This PR fixes the public path logic by resolving public path in the following order:

  1. Using the public path provided by html-webpack-plugin
  2. Using the public path set in webpack config by user
  3. Resolve manually using the output name of html file and webpack output path

How has this been tested?

  1. Test with example webpack provided by the issue creator
  2. Test with webpack config that doesn't have folder specified in the filename of html-webpack-plugin options
  3. Add new test case

Types of changes

Remarks

N/A