microsoft / playwright-dotnet

.NET version of the Playwright testing and automation library.
https://playwright.dev/dotnet/
MIT License
2.47k stars 235 forks source link

Configuration: Specify platform #1845

Closed LukeTOBrien closed 2 years ago

LukeTOBrien commented 2 years ago

Hello,

When you build a project with the Playwright NuGet installed there is a folder called .playwright in the bin/Debug or bin/Release, inside this folder is two more folders: node (197MB) and package (11.8MB).
node folder contains:

Is there a way to specify that I only intend to use win32_64 platform say? That would mean that the other two are not needed and thus save space.
I also noticed that win32_64 folder contains node.exe, is that strictly necessary? As I have node installed and set in the PATH environmental variable.

The project I am working perhaps is using Playwright differently from intended, I have a WYSIWYG editor to edit a web site and I want to export the site as a PDF, so I'm using the Page.Pdf method to do that.
The problem is 197MB is a bit large to send to my server via FTP, so I'm wondering how to reduce.

Thanks,

Luke

vandre commented 2 years ago

I'm also using Playwright for PDF generation. As a workaround what I did is manually delete the linux/mac folders on my deployment server. Saved a little bit of space. It seems to still work.

pavelfeldman commented 2 years ago

My understanding is that Nuget does not allow us to download selective binaries, for the selected platform. So the only solution to this is platform-specific Nuget packages, something we'd want to see upvoted / validated before we do it.

campersau commented 2 years ago

The CopyPlaywrightFilesToOutput target could be adjusted to only copy the node folder for the current OS or check for a custom <PlaywrightPlatform> property so the user can set it themselves in their project. E.g.

<PropertyGroup>
  <PlaywrightPlatform Condition="'$(PlaywrightPlatform)' == '' AND $([MSBuild]::IsOSPlatform('Linux'))">linux</PlaywrightPlatform>
  <PlaywrightPlatform Condition="'$(PlaywrightPlatform)' == '' AND $([MSBuild]::IsOSPlatform('Windows'))">windows</PlaywrightPlatform>
  <PlaywrightPlatform Condition="'$(PlaywrightPlatform)' == '' AND $([MSBuild]::IsOSPlatform('OSX'))">macos</PlaywrightPlatform>
  <PlaywrightPlatform Condition="'$(PlaywrightPlatform)' == ''">all</PlaywrightPlatform>
</PropertyGroup>
<ItemGroup>
  <_CopyItems Include="$(MSBuildThisFileDirectory)..\.playwright\package\**" />
  <_CopyItems Include="$(MSBuildThisFileDirectory)..\.playwright\node\LICENSE" />
  <_CopyItems Include="$(MSBuildThisFileDirectory)..\.playwright\node\**" Condition="'$(PlaywrightPlatform)' == 'all'" />
  <_CopyItems Include="$(MSBuildThisFileDirectory)..\.playwright\node\linux\**" Condition="'$(PlaywrightPlatform)' == 'linux'" />
  <_CopyItems Include="$(MSBuildThisFileDirectory)..\.playwright\node\win32_x64\**" Condition="'$(PlaywrightPlatform)' == 'windows'" />
  <_CopyItems Include="$(MSBuildThisFileDirectory)..\.playwright\node\mac\**" Condition="'$(PlaywrightPlatform)' == 'macos'" />
</ItemGroup>

https://github.com/microsoft/playwright-dotnet/blob/2d27cf9f4adb5f8abcb892145a14c8503b10ef75/src/Playwright/build/Microsoft.Playwright.targets#L3-L9