Skip to content

Dvurechensky-Templates/NetCoreTemplate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

243 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

✨Dvurechensky✨

Static Badge

🌁 ASP.NET Core MVC Project Template, Frontend β€” TypeScript

Language: πŸ‡¨πŸ‡³ δΈ­ζ–‡ | πŸ‡·πŸ‡Ί Russian | βœ… πŸ‡ΊπŸ‡Έ English (current)


✨ Table of Contents

πŸŽ‡ Configuration Setup Stages πŸŽ‡


  1. β›… Import tsconfig.json β›…

Show tsconfig.json
{
	"compilerOptions": {
		"target": "es2016",
		"module": "es6",
		"moduleResolution": "node",
		"jsx": "preserve",
		"declaration": false,
		"removeComments": true,
		"noImplicitAny": false,
		"noEmitOnError": true,
		"sourceMap": true,
		"esModuleInterop": true,
		"experimentalDecorators": true,
		"emitDecoratorMetadata": true,
		"outDir": "ScriptsAndCss/JsScripts",
		"lib": ["es2016", "dom"]
	},
	"exclude": ["node_modules"]
}

  1. β›… Import webpack.config.js β›…

Show webpack.config.js
const path = require('path')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin')
const TerserPlugin = require('terser-webpack-plugin')

module.exports = {
	entry: {
		app: './ScriptsAndCss/TypeScripts/main_api.ts',
		styles: './ScriptsAndCss/CssFiles/styles.css',
	},
	output: {
		path: path.resolve(__dirname, 'wwwroot/js'),
		filename: '[name].min.js',
	},
	resolve: {
		extensions: ['.ts', '.js', '.css'],
	},
	module: {
		rules: [
			{
				test: /\.ts$/,
				use: 'ts-loader',
				exclude: /node_modules/,
			},
			{
				test: /\.css$/,
				use: [MiniCssExtractPlugin.loader, 'css-loader'],
			},
		],
	},
	plugins: [
		new MiniCssExtractPlugin({
			filename: '../css/app.min.css',
		}),
	],
	mode: 'development',
	watch: true,
}

For production builds, change mode: 'development' to mode: 'production'

Show production config
mode: 'production',
optimization: {
    minimize: true,
    minimizer: [
        new TerserPlugin(),
        new CssMinimizerPlugin()
    ]
},

  1. β›… Import package.json β›…

Show package.json
{
	"version": "1.0.0",
	"name": "asp.net",
	"private": true,
	"devDependencies": {
		"css-minimizer-webpack-plugin": "7.0.0",
		"terser-webpack-plugin": "5.3.12",
		"cytoscape": "^3.31.0",
		"cytoscape-cose-bilkent": "4.1.0",
		"grunt": "1.4.1",
		"style-loader": "^4.0.0",
		"css-loader": "^7.1.2",
		"mini-css-extract-plugin": "^2.9.2",
		"grunt-webpack": "^7.0.0",
		"webpack-cli": "^6.0.1",
		"ts-loader": "^9.5.2",
		"browser-sync": "^3.0.3",
		"grunt-browser-sync": "^2.2.0",
		"grunt-contrib-clean": "2.0.0",
		"grunt-contrib-concat": "2.0.0",
		"grunt-contrib-cssmin": "5.0.0",
		"grunt-contrib-uglify": "5.0.1",
		"grunt-contrib-watch": "1.1.0",
		"grunt-ts": "6.0.0-beta.22"
	},
	"dependencies": {
		"cytoscape": "^3.31.0"
	}
}

  1. β›… Import Gruntfile.js β›…

Show Gruntfile.js
const webpackConfig = require('./webpack.config.js')

module.exports = function (grunt) {
	grunt.initConfig({
		webpack: {
			options: webpackConfig,
			build: {},
		},
		browserSync: {
			dev: {
				bsFiles: {
					src: [
						'wwwroot/css/*.css',
						'wwwroot/js/app.min.js',
						'Views/**/*.cshtml',
					],
				},
				options: {
					watchTask: true,
					proxy: 'localhost:5000',
				},
			},
		},
		watch: {
			ts: {
				files: ['ScriptsAndCss/TypeScripts/**/*.ts'],
				tasks: ['webpack:build'],
			},
		},
	})

	grunt.loadNpmTasks('grunt-webpack')
	grunt.loadNpmTasks('grunt-browser-sync')
	grunt.loadNpmTasks('grunt-contrib-watch')

	grunt.registerTask('build', ['webpack:build'])
	grunt.registerTask('default', ['build', 'browserSync:dev', 'watch'])
}

πŸŽ‡ Build Process Stages πŸŽ‡


  • πŸŒ‹ Restore NPM packages

  • πŸŒ‹ Setup frontend directories:

ScriptsAndCss/
 β”œβ”€ CssFiles/
 β”œβ”€ JsScripts/
 └─ TypeScripts/
  • πŸŒ‹ Install NuGet packages:

    • TypeScript.MSBuild
    • AspNetCore.Mvc.Razor.RuntimeCompilation
    • Swashbuckle.AspNetCore.Swagger
    • Swashbuckle.AspNetCore.SwaggerGen
    • Swashbuckle.AspNetCore.SwaggerUI
  • πŸŒ‹ Update paths in _Layout.cshtml to:

    • app.min.css
    • app.min.js

πŸŽ‡ Result πŸŽ‡

πŸ“· Base πŸ“·

After successful startup:

  • Server: https://localhost:8833
  • Swagger: https://localhost:8833/docs/

πŸ“· Features πŸ“·

  • Live reload via BrowserSync
  • Webpack build + minification
  • TypeScript modern features
  • Scalable backend with ASP.NET Core MVC
  • Strong typing on frontend

πŸ“· Approximate Development Process πŸ“·

πŸŽƒ Frontend (TypeScript + Webpack):

  • Write TypeScript β†’ compile via Webpack
  • Assets are bundled & minimized
  • Grunt automates build tasks

🎈 Backend (ASP.NET Core MVC):

  • Handles business logic & API
  • Serves static files from wwwroot

πŸŽƒ Automation:

  • Grunt automates builds
  • Webpack enables hot reload

🎈 Development:

  • BrowserSync syncs browsers
  • Faster dev via automation

✨Dvurechensky✨