numical / script-ext-html-webpack-plugin

Enhances html-webpack-plugin functionality with different deployment options for your scripts including 'async', 'preload', 'prefetch', 'defer', 'module', custom attributes, and inlining.
MIT License
588 stars 105 forks source link

fix function getScriptName in element.js #19

Closed koalaink closed 7 years ago

koalaink commented 7 years ago

webpack config

{
...
plugins:[
  new webpack.optimize.CommonsChunkPlugin({
      name: [`${project.projectName}/js/vendor`, `${project.projectName}/js/manifest`],
      minChunks: Infinity,
      filename: `[name].[chunkhash:8].js`,
    }),
  new ScriptExtHtmlWebpackPlugin({
      inline: 'manifest'
    }),
]

Error: ScriptExtHtmlWebpackPlugin: no asset with href 'manifest.d41d8cd9.js'

modify function getScriptName as bellow, it works well

const getScriptName = (options, tag, compilation) => {
  let scriptName = getRawScriptName(tag);
  // remove publicPath prefix
  // if (scriptName.includes('/')) {
  //   scriptName = scriptName.replace(CONSTANTS.PUBLIC_PATH_PREFIX, '');
  // }
  scriptName = scriptName.replace(compilation.outputOptions.publicPath, '');
  if (options.htmlWebpackOptions.hash) {
    scriptName = scriptName.split('?', 1)[0];
  }
  return scriptName;
};
numical commented 7 years ago

Hi, I could not repeat your issue - I suspected either the chunkhash or the mutliple '/'s in the path, but neither seemed to break ScriptExt. However your suggested change was a good one so I included it in a refactor for v1.7.4. Could you try out v1.7.4 to see if it fixes your issue. I will assume so as it is your suggesed fix (!) but do let me know if not.

koalaink commented 7 years ago

My issue is fixed with v1.8.0. thx