无法在 ASP.NET Core 中使用 webpack 中间件

我尝试在 ASP.NET Core 项目中使用 webpack


这是我的 Startup.cs 文件和 Configure 类


public void Configure(IApplicationBuilder app, IHostingEnvironment env)

    {

        if (env.IsDevelopment())

        {

            app.UseDeveloperExceptionPage();

            app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions

            {

                HotModuleReplacement = true

            });

        }

        else

        {

            app.UseExceptionHandler("/Home/Error");

            app.UseHsts();

        }


        app.UseHttpsRedirection();

        app.UseStaticFiles();

        app.UseCookiePolicy();


        app.UseMvc(routes =>

        {

            routes.MapRoute(

                name: "default",

                template: "{controller=Home}/{action=Index}/{id?}");

        });

    }

这是我的 package.json 文件


    {

 "name": "streamline",

 "version": "1.0.0",

 "description": "",

 "main": "index.js",

 "scripts": {

  "test": "echo \"Error: no test specified\" && exit 1",

  "wbp": "webpack"

 },

 "keywords": [],

 "author": "",

 "license": "ISC",

 "devDependencies": {

  "aspnet-webpack": "^3.0.0",

  "bootstrap": "^4.1.2",

  "css-loader": "^1.0.0",

  "extract-text-webpack-plugin": "^4.0.0-beta.0",

  "jquery": "^3.3.1",

  "popper.js": "^1.14.3",

  "style-loader": "^0.21.0",

  "uglifyjs-webpack-plugin": "^1.2.7",

  "webpack": "^4.16.1",

  "webpack-cli": "^3.0.8",

  "webpack-hot-middleware": "^2.22.2"

 },

 "dependencies": {

  "@babel/core": "^7.0.0-beta.53",

  "@babel/preset-env": "^7.0.0-beta.53",

  "babel-loader": "^8.0.0-beta.4"

 }

}


慕村9548890
浏览 267回答 1
1回答

暮色呼如

我有同样的问题。为我解决...npm install --save-dev webpack-cli这给了我线索 npm WARN aspnet-webpack@3.0.0 requires an peer of webpack-dev-middleware @^1.8.4 || ^3.0.0 但没有安装。您必须自己安装对等依赖项。npm WARN acesweb@1.0.0 没有存储库字段。然后..npm install --save-dev webpack-dev-middleware现在它运行并且工作正常。
打开App,查看更多内容
随时随地看视频慕课网APP