Skip to content
This repository was archived by the owner on Apr 8, 2020. It is now read-only.
This repository was archived by the owner on Apr 8, 2020. It is now read-only.

ExtractTextPlugin doesn't generate any file when the application is launched from Visual Studio and the isDevBuild variable is set to false in webpack.config.js #1229

Description

@rskopal

I use the React template and I would like to try to run my application in Visual Studio without HMR and without style-loader css to head injection. So I set the ASPNETCORE_ENVIRONMENT variable to Staging in the IIS Express and application debug configuration and set the isDevBuild const directly to false in the webpack.config.js. But when I launch the application from Visual Studio no dist/site.css file is generated. If I run the webpack command from command line, the site.css is generated correctly. The webpack.config.js is the same as in the React template except these lines:

  //const isDevBuild = !(env && env.prod);
  const isDevBuild = false;

Is there any problem with the ExtractTextPlugin when webpack build is run from Visual Studio?

Activity

  1. SteveSandersonMS commented on Aug 25, 2017

    @SteveSandersonMS
    Member

    By default, Webpack dev middleware (and hence the runtime webpack build) only runs when the application is in Development environment. If you want to perform a webpack build at some other time (e.g., when your application is in Staging environment), then it's up to you to do so manually, e.g., using webpack on the command line, or by publishing your application using dotnet publish or VS's "Publish" UI, which also performs a webpack build for you.

    If you just want to turn off HMR, you only need to change the HotModuleReplacement = true option to false in the WebpackDevMiddlewareOptions in your Startup.cs. You don't have to change any Webpack config or which environment your application runs in.

  2. rskopal commented on Aug 28, 2017

    @rskopal
    Author

    Thanks for your answer, I didn't notice that the main.js wasn't also generated. I solved the problem by creating two launchSettings configurations in VS, IIS Express and IIS Express Staging, the latter one has the ASPNETCORE_ENVIRONMENT variable set to Staging. Because I'm afraid I'll forget to manually run webpack build after each switch to IIS Express Staging, I added this to the Startup:

    if (env.IsDevelopment()) { ... }
    else if (env.IsStaging())
    {
      app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions
      {
        HotModuleReplacement = false,
        ReactHotModuleReplacement = false,
      });
    } else { ... }
    

    It works well, but after each switching I also have to set the isDevBuild flag directly to false in the webpack.config.js. It would be nice if I could send some parameters to webpack from the Startup, as it is mentioned in comments for the createWebpackDevServer() function in WebpackDevMiddleware.ts or here #816, e.g.:

    app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions
    {
    	HotModuleReplacement = false,
    	ReactHotModuleReplacement = false,
    	EnvironmentVariables = new Dictionary<string, string>()
    	{
    	  { "isStagingBuild", "true" }
    	}
    });
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions