s3-plugin-webpack icon indicating copy to clipboard operation
s3-plugin-webpack copied to clipboard

Upload Triggers too Early in Build Process

Open sinemacula opened this issue 4 years ago • 10 comments

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:

  • Assets copied during the build process without using webpack e.g. Laravel Mix
  • Assets compiled with mix.scripts, mix.styles and mix.babel when using Laravel Mix
  • Assets manually generated after the build process e.g. merged CSS files

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 avatar Jan 16 '20 22:01 sinemacula

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.

sinemacula avatar Jan 16 '20 22:01 sinemacula

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!

MikaAK avatar Jan 17 '20 18:01 MikaAK

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?

sinemacula avatar Jan 17 '20 21:01 sinemacula

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

MikaAK avatar Jan 17 '20 22:01 MikaAK

Thank you so much!!! :-D

sinemacula avatar Jan 17 '20 23:01 sinemacula

Hi Mika,

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

sinemacula avatar Jan 20 '20 23:01 sinemacula

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

MikaAK avatar Jan 30 '20 19:01 MikaAK

Okay, thanks Mika, keep me updated :-D

sinemacula avatar Feb 06 '20 11:02 sinemacula

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.

caseybienvenu avatar Jul 08 '20 05:07 caseybienvenu

Also having the exact same issue.

selected-pixel-jameson avatar Sep 24 '20 03:09 selected-pixel-jameson