β¨Dvurechenskyβ¨
Language: π¨π³ δΈζ | π·πΊ Russian | β πΊπΈ English (current)
- β
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"]
}- β
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'tomode: 'production'
Show production config
mode: 'production',
optimization: {
minimize: true,
minimizer: [
new TerserPlugin(),
new CssMinimizerPlugin()
]
},- β
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"
}
}- β
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'])
}-
π Restore NPM packages
-
π Setup frontend directories:
ScriptsAndCss/
ββ CssFiles/
ββ JsScripts/
ββ TypeScripts/
-
π Install NuGet packages:
TypeScript.MSBuildAspNetCore.Mvc.Razor.RuntimeCompilationSwashbuckle.AspNetCore.SwaggerSwashbuckle.AspNetCore.SwaggerGenSwashbuckle.AspNetCore.SwaggerUI
-
π Update paths in
_Layout.cshtmlto:app.min.cssapp.min.js
After successful startup:
- Server:
https://localhost:8833 - Swagger:
https://localhost:8833/docs/
- Live reload via BrowserSync
- Webpack build + minification
- TypeScript modern features
- Scalable backend with ASP.NET Core MVC
- Strong typing on frontend
π 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β¨