i use webpack in my asp.net core 6 mvc project. I use webpack-dev-server to run the browser automatically. My question is, how can I see the changes on index.cshtml instead of index.html. (When I change the extension of the html file from html to cshtml, the browser cannot load the cshtml file)
in webpack.config.js:
const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const TerserPlugin = require("terser-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const CssMinimizerPlugin = require("css-minimizer-webpack-plugin");
const NodePolyfillPlugin = require("node-polyfill-webpack-plugin");
module.exports = {
entry: {
opencv: './wwwroot/Source/example1.js',
},
mode: 'development',
devtool: 'inline-source-map',
devServer: {
static: {
directory: path.join(__dirname,'/wwwroot/distt/' ),
publicPath: '/devserverdist4/',
},
compress: true,
port: 9003,
open: true,
},
plugins: [
new HtmlWebpackPlugin({
title: 'index1',
}),
new HtmlWebpackPlugin({
title: 'index2',
filename: 'index2.html',
}),
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery',
'window.jQuery': 'jquery',
Popper: ['popper.js', 'default']
}),
new MiniCssExtractPlugin({
filename: '[name].styles.css',
}),
new NodePolyfillPlugin(),
new webpack.DefinePlugin({
'process.env.ASSET_PATH': JSON.stringify(ASSET_PATH),
}),
],
output: {
filename: '[name].bundle.js',
path: path.join(__dirname, '/wwwroot/dist/'),
publicPath: '/outputdist1/',
clean: true,
},
optimization: {
minimize: true,
minimizer: [new TerserPlugin(), new CssMinimizerPlugin(),],
},
module: {
rules: [
{
test: /\.css$/i,
use: [MiniCssExtractPlugin.loader, "css-loader"],
},
{
test: /\.js?$/,
use: {
loader: 'babel-loader', options: {
presets:
['@babel/preset-react', '@babel/preset-env']
}
}
},
]
},
resolve: {
fallback: {
fs: false,
},
}
};
What I have tried:
I want to use the webpack-dev-server feature in my mvc project views that have cshtml extension