Implemented Tailwind CSS class list extraction and integrated it into the build process of the frontend package
Some checks failed
Dev Publish: Nuget / Publish Dev Packages (push) Failing after 16s
Some checks failed
Dev Publish: Nuget / Publish Dev Packages (push) Failing after 16s
This commit was merged in pull request #2.
This commit is contained in:
@@ -32,6 +32,10 @@ jobs:
|
|||||||
run: rm -rf ./artifacts
|
run: rm -rf ./artifacts
|
||||||
|
|
||||||
# Publish frontend
|
# Publish frontend
|
||||||
|
- name: Build tailwind styles and extract class list
|
||||||
|
working-directory: Hosts/Moonlight.Frontend.Host/Styles
|
||||||
|
run: npm run build
|
||||||
|
|
||||||
- name: Build project
|
- name: Build project
|
||||||
run: dotnet build Moonlight.Frontend --configuration Debug
|
run: dotnet build Moonlight.Frontend --configuration Debug
|
||||||
|
|
||||||
|
|||||||
@@ -14,11 +14,11 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="10.0.1"/>
|
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="10.0.1"/>
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="10.0.1" PrivateAssets="all"/>
|
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="10.0.1" PrivateAssets="all"/>
|
||||||
<PackageReference Include="MoonCore.PluginFramework" Version="1.0.9" />
|
<PackageReference Include="MoonCore.PluginFramework" Version="1.0.9"/>
|
||||||
<PackageReference Include="MoonCore.PluginFramework.Generator" Version="1.0.3" />
|
<PackageReference Include="MoonCore.PluginFramework.Generator" Version="1.0.3"/>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\..\Moonlight.Frontend\Moonlight.Frontend.csproj" />
|
<ProjectReference Include="..\..\Moonlight.Frontend\Moonlight.Frontend.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
25
Hosts/Moonlight.Frontend.Host/Styles/extract-classes.mjs
Normal file
25
Hosts/Moonlight.Frontend.Host/Styles/extract-classes.mjs
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
import fs from 'fs';
|
||||||
|
import selectorParser from 'postcss-selector-parser';
|
||||||
|
|
||||||
|
export default function extractTailwindClasses(opts = {}) {
|
||||||
|
const classSet = new Set();
|
||||||
|
|
||||||
|
return {
|
||||||
|
postcssPlugin: 'extract-tailwind-classes',
|
||||||
|
Rule(rule) {
|
||||||
|
selectorParser(selectors => {
|
||||||
|
selectors.walkClasses(node => {
|
||||||
|
classSet.add(node.value);
|
||||||
|
});
|
||||||
|
}).processSync(rule.selector);
|
||||||
|
},
|
||||||
|
OnceExit() {
|
||||||
|
const classArray = Array.from(classSet).sort();
|
||||||
|
fs.mkdirSync('../../../Moonlight.Frontend/Styles', { recursive: true });
|
||||||
|
fs.writeFileSync('../../../Moonlight.Frontend/Styles/Moonlight.Frontend.map', classArray.join('\n'));
|
||||||
|
console.log(`Extracted classes ${classArray.length}`);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
extractTailwindClasses.postcss = true;
|
||||||
@@ -1,15 +1,20 @@
|
|||||||
{
|
{
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"tailwind": "npx postcss styles.css -o ../wwwroot/style.min.css --watch",
|
"dev": "npx postcss styles.css -o ../wwwroot/style.min.css --watch",
|
||||||
"tailwind-build": "npx postcss styles.css -o ../wwwroot/style.min.css"
|
"dev-build": "npx postcss styles.css -o ../wwwroot/style.min.css",
|
||||||
|
"build": "cross-env EXTRACT_CLASSES=true npx postcss styles.css -o ../wwwroot/style.min.css"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@tailwindcss/postcss": "^4.1.18",
|
"@tailwindcss/postcss": "^4.1.18",
|
||||||
"cssnano": "^7.1.2",
|
"cssnano": "^7.1.2",
|
||||||
"postcss": "^8.5.6",
|
"postcss": "^8.5.6",
|
||||||
"postcss-cli": "^11.0.1",
|
"postcss-cli": "^11.0.1",
|
||||||
|
"postcss-selector-parser": "^7.1.1",
|
||||||
"shadcnblazor": "^1.0.5",
|
"shadcnblazor": "^1.0.5",
|
||||||
"tailwindcss": "^4.1.18",
|
"tailwindcss": "^4.1.18",
|
||||||
"tw-animate-css": "^1.4.0"
|
"tw-animate-css": "^1.4.0"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"cross-env": "^10.1.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,18 @@
|
|||||||
export default {
|
import tailwindcss from '@tailwindcss/postcss';
|
||||||
plugins: {
|
import cssnano from 'cssnano';
|
||||||
"@tailwindcss/postcss": {},
|
import extractTailwindClasses from './extract-classes.mjs';
|
||||||
"cssnano":{
|
|
||||||
preset: 'default'
|
const plugins = [
|
||||||
}
|
tailwindcss,
|
||||||
}
|
cssnano({
|
||||||
|
preset: 'default'
|
||||||
|
})
|
||||||
|
];
|
||||||
|
|
||||||
|
if (process.env.EXTRACT_CLASSES === "true") {
|
||||||
|
plugins.push(extractTailwindClasses());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export default {
|
||||||
|
plugins
|
||||||
|
};
|
||||||
@@ -23,7 +23,6 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Components.Authorization" Version="10.0.1"/>
|
<PackageReference Include="Microsoft.AspNetCore.Components.Authorization" Version="10.0.1"/>
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="10.0.1"/>
|
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="10.0.1"/>
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="10.0.1" PrivateAssets="all"/>
|
|
||||||
<PackageReference Include="Riok.Mapperly" Version="4.3.1-next.0"/>
|
<PackageReference Include="Riok.Mapperly" Version="4.3.1-next.0"/>
|
||||||
<PackageReference Include="ShadcnBlazor" Version="1.0.5" />
|
<PackageReference Include="ShadcnBlazor" Version="1.0.5" />
|
||||||
<PackageReference Include="ShadcnBlazor.Extras" Version="1.0.5" />
|
<PackageReference Include="ShadcnBlazor.Extras" Version="1.0.5" />
|
||||||
@@ -33,4 +32,8 @@
|
|||||||
<ProjectReference Include="..\Moonlight.Shared\Moonlight.Shared.csproj"/>
|
<ProjectReference Include="..\Moonlight.Shared\Moonlight.Shared.csproj"/>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<None Include="Styles/*" Pack="true" PackagePath="Styles/" />
|
||||||
|
<None Include="Moonlight.Frontend.targets" Pack="true" PackagePath="build\Moonlight.Frontend.targets" />
|
||||||
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
15
Moonlight.Frontend/Moonlight.Frontend.targets
Normal file
15
Moonlight.Frontend/Moonlight.Frontend.targets
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
<Project>
|
||||||
|
<PropertyGroup>
|
||||||
|
<MoonlightCssClassDir Condition="'$(MoonlightCssClassDir)' == ''">
|
||||||
|
$(MSBuildProjectDirectory)\bin\Moonlight.Frontend
|
||||||
|
</MoonlightCssClassDir>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<Target Name="CopyContents" BeforeTargets="Build">
|
||||||
|
<ItemGroup>
|
||||||
|
<Files Include="$(MSBuildThisFileDirectory)..\Styles\**\*" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<Copy SourceFiles="@(Files)" DestinationFolder="$(MoonlightCssClassDir)" SkipUnchangedFiles="true" />
|
||||||
|
</Target>
|
||||||
|
</Project>
|
||||||
1
Moonlight.Frontend/Styles/Moonlight.Frontend.map
Normal file
1
Moonlight.Frontend/Styles/Moonlight.Frontend.map
Normal file
@@ -0,0 +1 @@
|
|||||||
|
THIS WILL BE GENERATED ON PACKAGE BUILD
|
||||||
Reference in New Issue
Block a user