MikaAK / s3-plugin-webpack

Uploads files to s3 after complete
MIT License
486 stars 125 forks source link

Upload Triggers too Early in Build Process #130

Open sinemacula opened 4 years ago

sinemacula commented 4 years ago

OS: Windows, Mac, and Linux Node: 10.16.3 NPM: 6.11.2 Webpack: 4.41.2 s3-webpack-plugin: 1.0.3

The Issue

Certain assets are excluded from the upload manifest due to the moment at which the S3 plugin triggers.

There are various examples I can give so I will highlight a few:

I managed to find someone else with the same issue: https://stackoverflow.com/questions/57380123/laravel-mix-versioning-when-uploaded-in-s3-thinks-in-previous-hash

I do not believe this is limited to only those that use Laravel Mix. I assume that it is also relevant to those that manipulate their files during the webpack build process, but without using webpack to do it (i.e. it is not in the buid manifest).

I believe that the issue lies here:

https://github.com/MikaAK/s3-plugin-webpack/blob/2fc4d65cd4409e2d170439d8e6ba9b595d1f87ca/src/s3_plugin.js#L91

Potential Solution

I am not overly familiar with webpack plugins so I can't be certain this will not break other parts of the plugin but I tried the following and it seemed to fix the issue:

compiler.hooks.done.tapPromise(packageJson.name, async(compilation) => {

I will also create a pull request.

sinemacula commented 4 years ago

I forgot to say, if you need any additional information, or more non-Laravel Mix examples then let me know and I can expand further, and give some code examples. I wanted to keep the description brief in the first instance.

MikaAK commented 4 years ago

You can fix this by using the directory parameter to specify the build directory. Unfortunately, I don't think making changes to suit larvel is a good idea!

sinemacula commented 4 years ago

Thank you for your prompt response.

As mentioned, this is not relevant to just those using Laravel Mix, it just so happens that the examples I have provided are related to it.

I tested out every available parameter and option before posting as I wanted to ensure I had tried everything. Not to mention, my implementation is already using the directory parameter.

Surely just updating the event to trigger once the compilation is complete is a good thing to do regardless?

MikaAK commented 4 years ago

Awesome, thanks for more info. I've merged it in and will draft a release tonight 😄 Thanks for your work 🙏

sinemacula commented 4 years ago

Thank you so much!!! :-D

sinemacula commented 4 years ago

Hi Mika,

Any update on the release? I can see the build is failing, is there anything I can help with?

MikaAK commented 4 years ago

The tests are failing and I'm not sure why, I was inclined to think it a config on aws issue but some fail others don't, gonna try reverting and testing, if it doesn't fail we'll need to fix tests before launching this

sinemacula commented 4 years ago

Okay, thanks Mika, keep me updated :-D

caseybienvenu commented 4 years ago

I am also experiencing a similar problem. I have one JS file generated using mix.scripts that does not get transferred to S3 the first time the S3 plugin runs. Other files are transferred properly.

Interestingly, when I run a 2nd time, that missing JS file is transferred properly.

Also using s3-webpack-plugin version 1.0.3.

selected-pixel-jameson commented 3 years ago

Also having the exact same issue.