GithubHelp home page GithubHelp logo

Comments (1)

jonhilt avatar jonhilt commented on September 25, 2024

The manual process to implement the same approach in a Blazor Server project is as follows (and is what will need to be in place when we create a Blazor Server version of the template).

Copy the following into your own (Blazor Server) project's .csproj file.

    <ItemGroup>
        <InputStylesheets Include="Styles\**\*.css" />
    </ItemGroup>

    <Target Name="CheckForNpm" BeforeTargets="BuildCSS">
        <Message Text="Checking for NPM" Importance="high" />
        <Exec Command="npm -v" ContinueOnError="true">
            <Output TaskParameter="ExitCode" PropertyName="ErrorCode" />
        </Exec>
        <Error Condition="'$(ErrorCode)' != '0'" Text="Please install NPM" />
    </Target>

    <Target Name="BuildCSS" BeforeTargets="Compile" Inputs="@(InputStylesheets)" Outputs="wwwroot/css/app.css" Condition=" '$(Configuration)' == 'Debug' ">
        <Message Text="Compiling CSS for development" Importance="high" />
        <Exec Command="npx tailwindcss -i Styles/app.css -o wwwroot/css/app.css" />
    </Target>

    <Target Name="BuildCSSForProd" BeforeTargets="Compile" Condition="'$(Configuration)' == 'Release'">
        <Message Text="Compiling CSS for production" Importance="high" />
        <Exec Command="npx tailwindcss -i Styles/app.css -o wwwroot/css/app.css" EnvironmentVariables="NODE_ENV=production" />
    </Target>

Add a Styles folder to the root of your project and create an app.css in there with these contents:

@tailwind base;
@tailwind components;
@tailwind utilities;

#blazor-error-ui {
    display: none !important;
}

Finally, create a file called tailwind.config.js with the following contents, in the root of your Blazor Server project.

module.exports = {
  purge: {
    content: [
        './**/*.razor',
        './**/*.cshtml'
    ]
},
  darkMode: false, // or 'media' or 'class'
  theme: {
    extend: {},
  },
  variants: {
    extend: {},
  },
  plugins: [],
}

Once this is all in place, when you build your project, Tailwind CLI will kick in and create a file at wwwroot\css\app.css.

Note, if you already have a file at wwwroot\css\app.css. you'll want to rename it, delete it, or change the code you paste into your csproj file (replace all references to wwwroot/css/app.css with a different name).

The final step is to include the app.css file in your blazor project's _Host.cs file:

<head>
    ...

    <link href="css/app.css" rel="stylesheet" />   
</head>

from blazortailwindtemplate.

Related Issues (7)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.