This project is a .NET Razor application that integrates a Node.js-based build pipeline to manage frontend CSS. The Node setup leverages modern tools (like PostCSS, Sass) to build and optimize CSS assets, which are then used by the Razor views.
Before getting started, ensure the following tools are installed on your system:
- .NET SDK (version 6.0 or higher)
- Node.js (version 16 or higher)
- NPM (comes with Node.js installation)
|-- /wwwroot # Static files served by the Razor app
| |-- /css # Final built CSS files
|-- /Node # Node.js files and configs
| |-- package.json # NPM dependencies and scripts
| |-- /src # Source CSS/SCSS files
| |-- /dist # Compiled and optimized CSS
|-- /Pages # Razor pages
|-- /Views # Razor views
|-- /Controllers # Controllers for the app
|-- appsettings.json # App configuration
git clone <repository-url>
cd <repository-folder>
Run the following command to restore .NET dependencies:
dotnet restore
Navigate to the Node
directory and install Node.js dependencies:
cd Node
npm install
Run the following command in the Node
directory to watch and build CSS changes:
npm run dev
This ensures the source CSS (in /Node/src
) is processed and outputted to /Node/dist
. These files are then copied to the wwwroot/css
folder for use by Razor views.
From the project root, execute the following command:
dotnet run
The application will be available at https://localhost:5001
or http://localhost:5000
.
-
npm run dev
Watches CSS files, rebuilds on changes, and copies the output to thewwwroot/css
directory. -
npm run build
Builds and optimizes CSS for production. -
npm run clean
Cleans thedist
folder and resets build files.
Reference the built CSS in your Razor views like this:
<link rel="stylesheet" href="css/styles.css" />
Make sure the paths match the files output to /wwwroot/css
after the build.
- Backend framework for building server-side web applications.
- PostCSS: For CSS transformations.
-
CSS not updating:
Ensurenpm run dev
is running in theNode
directory and that the output files are being copied to/wwwroot/css
. -
Dependency issues:
Check your Node.js or .NET SDK versions and ensure they match the prerequisites.
Feel free to submit issues or pull requests to improve this project.
This project is licensed under the MIT License.