Would like to be able to link to a file whose name includes [hash]
hyanwong opened this issue · comments
I would like to symlink to a file in the build dir, but the file is created using
output: {
filename: '[name].[hash].js',
I would like to use the following follow syntax in your plugin, but I don't think it's supported?
new SymlinkWebpackPlugin({ origin: '[name].[hash].js', symlink: '[name].js' }),
(or possibly just using the [hash]
substitution, as I can hardcode the names)
Thanks!
It seems like you can access the hash using the webpack.ExtendedAPIPlugin
, which creates a global variable __webpack_hash__
, but I can't get this to work as I expect. E.g. I was hoping to do something like this:
plugins: [
new webpack.ExtendedAPIPlugin(),
new SymlinkWebpackPlugin({ origin: 'entry.' + __webpack_hash__ + '.js', symlink: 'entry.js' }),
But I get >> ReferenceError: _webpack_hash_ is not defined
. It there any easy way to access this from within the SymlinkWebpackPlugin config object?
Thanks for your effort to find out the way to make that happens :)
[name]
, [hash]
are actually resolved by TemplatePathPlugin
on compilation
, assetPath
hook.
But SymlinkWebpackPlugin
works among the emitted outputs where all pathnames are resolved. And supporting all placeholders by TemplatePathPlugin
is not a realistic approach in my opinion.
So we need to think about some workaround or another way.
I guess your expectation will be fulfilled by providing another placeholder for "Output filename" right?
I'm wondering if we can write the config as:
{ origin: '[output]', symlink: 'entry.js' }
Probably this makes that [name].[hash].js
is linked from entry.js
.
Does this work for you? If so, I may work on supporting that 🤔
supporting all placeholders by
TemplatePathPlugin
is not a realistic approach in my opinion.
I agree! (there are some other libraries that will do the templating for you, e.g. https://github.com/webpack/webpack/blob/master/lib/TemplatedPathPlugin.js) but you probably don't want to reply on other libs)
So we need to think about some workaround or another way.
I guess your expectation will be fulfilled by providing another placeholder for "Output filename" right?
Well, possibly, although I actually am producing 2 output files, and I want to cut the hash out of both, so it might be a bit more complicated. I actually have solved my problem by, instead of using a symlink, using the FileManagerPlugin
plugin which can do a copy with [hash]
templated filenames, so there's no urgency for me to get this into SymlinkWebpackPlugin
, but it would be preferable.
Thanks!
Good point. Need more considerations to support multiple outputs 🤔
FileManagerPlugin
seems to provide appropriate features with RegexGlob and [hash]
. Let me look into this weekend. Thanks for your input!