如何在.NET 6中使用WebPack?
如何在.NET6 Razor页面中使用WebPack?我在互联网上发现的任何文档都使我更加困惑。
的file1.ts:
export function CCC(): string {
return "AAAAAA";
}
我的文件
import { CCC } from "./file1"
function AAA(): string {
return CCC();
}
这
@page
@model IndexModel
@{
ViewData["Title"] = "Home page";
}
<script>
const str = AAA()
alert(str);
</script>
是
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>@ViewData["Title"] - TypeScriptLab5</title>
<link rel="stylesheet" href="~/TypeScriptLab5.styles.css" asp-append-version="true" />
<script src="~/ts/file1.js"></script>
<script src="~/ts/file.js"></script>
</head>
<body>
@RenderBody()
<script src="~/lib/jquery/dist/jquery.min.js"></script>
@await RenderSectionAsync("Scripts", required: false)
</body>
</html>
。
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddRazorPages();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthorization();
app.MapRazorPages();
app.Run();
这是我
How can I use webpack in .net6 razor pages? Any documentation I've found on the internet about this just confuses me more.
this is my file1.ts:
export function CCC(): string {
return "AAAAAA";
}
this is my file.ts:
import { CCC } from "./file1"
function AAA(): string {
return CCC();
}
this is my Index.cshtml:
@page
@model IndexModel
@{
ViewData["Title"] = "Home page";
}
<script>
const str = AAA()
alert(str);
</script>
this is my layout.cshtml:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>@ViewData["Title"] - TypeScriptLab5</title>
<link rel="stylesheet" href="~/TypeScriptLab5.styles.css" asp-append-version="true" />
<script src="~/ts/file1.js"></script>
<script src="~/ts/file.js"></script>
</head>
<body>
@RenderBody()
<script src="~/lib/jquery/dist/jquery.min.js"></script>
@await RenderSectionAsync("Scripts", required: false)
</body>
</html>
this is my program.cs file:
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddRazorPages();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthorization();
app.MapRazorPages();
app.Run();
I hope I have given enough explanation to present my problem
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于WebPack 5和NET 6,请按照以下步骤:
package.json configuration
webpack.config.js
文件
文件 您可以改用JavaScript。
在您的
_Layout.cshtml
中添加捆绑的脚本:现在您可以使用
&gt; npm run build
命令。For webpack 5 and net 6 follow these steps:
package.json configuration file
webpack.config.js file
tsconfig.json file
I assume
typescript
for these configs and you can use javascript instead.Add bundled scripts in your
_Layout.cshtml
:Now you can bundle project modules using
> npm run build
command.