question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Keep [hash] included within CopyWebpackPlugin

See original GitHub issue

Currently I’m using copy-webpack-plugin with the following configuration

{
  from: resolve('src/app/app.settings.js'),
  to: resolve(OUTPUT_PATH, 'config/[name].[hash].[ext]'),
  flatten: true,
}

The output would include the [hash] and it would look something like app.settings.3eaa9798d11464fbfd3a9c5d412d6b67.js, but as stayed in the README

Note that since copy-webpack-plugin does not actually copy the files to webpack's output directory until after html-webpack-plugin has completed, it is necessary to use the globPath to retrieve filename matches relative to the original location of any such files.

So I was wondering if there’s a way for me to glob the name like app.settings.*.js so the file can be included in the html including the [hash], if I make the globPath point at the original file, it only keeps the original name.

I appreciate any direction, even if its using a different plugin.

Regards.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
jharris4commented, Jan 29, 2019

ok, I’m glad that you seem to have found a solution to your problem. I’m closing the issue…

1reaction
jharris4commented, Jan 20, 2019

Ok, I’ve added support for the hash option to be a function to allow for your use case, and published to npm as version 1.0.7.

The README was updated to give an example:

plugins: [
  new CopyWebpackPlugin([
    { from: 'somepath/somejsfile.js', to: 'js/somejsfile.[hash].js' },
    { from: 'somepath/somecssfile.css', to: 'css/somecssfile.[hash].css' }
  ]),
  new HtmlWebpackPlugin(),
  new HtmlWebpackIncludeAssetsPlugin({
    assets: [{ path: 'js', glob: '*.js', globPath: 'somepath' }],
    assets: [{ path: 'css', glob: '*.css', globPath: 'somepath' }],
    append: false,
    hash: function(assetName, hash) {
      assetName = assetName.replace(/\.js$/, '.' + hash + '.js');
      assetName = assetName.replace(/\.css$/, '.' + hash + '.css');
      return assetName;
    }
  })
]

and a unit test was added to show that it works:

https://github.com/jharris4/html-webpack-include-assets-plugin/blob/master/spec/index.spec.js#L1352

Please let me know whether this works for you so I can close this issue! 😉

Read more comments on GitHub >

github_iconTop Results From Across the Web

CopyWebpackPlugin | webpack
copy-webpack-plugin is not designed to copy files generated from the build process; rather, it is to copy files that already exist in the...
Read more >
copy-webpack-plugin-hash - npm package - Snyk
Copy files && directories with webpack For more information about how to use this package see README · Ensure you're using the healthiest...
Read more >
copy-webpack-plugin-hash - npm
Copy files && directories with webpack. Latest version: 6.0.0, last published: 5 years ago. Start using copy-webpack-plugin-hash in your ...
Read more >
Webpack 4: how to copy a json file while adding a hash to the ...
Trying to use !!file-loader yields the same result. Another option could be to use copy-webpack-plugin with [hash] but then how to link to ......
Read more >
How to Copy Files Using the Copy Webpack Plugin (without ...
In a project using Webpack for the bundler, I needed to copy a folder from a node_modules directory and include the files in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found