rollthecloudinc / quell

Climate aware CMS breaking web apps free from carbon emissions.
https://demo.carbonfreed.app/pages/create-panel-page
GNU General Public License v3.0
14 stars 1 forks source link

Add custom webpack config to prerender #323

Open ng-druid opened 2 years ago

ng-druid commented 2 years ago

I have been trying to have tailwind parse the html generated by the pre-render process of Angular with no success. I think this is because the tailwind processing needs to be added to the pre-render builder. With other builds [build, server, etc.] this can easily be accomplished with custom angular builds. However, no custom builder to augment the web pack script for pre-render exists. Therefore, I think the only path forward to integrate tailwind processing of generated pre-rendered html files into the native build (angular.json) of Angular will be to create a custom builder. Anyone familiar does any of this sound like the right path.

The other option is just to run tailwind after the build and generate a separate css file. However, I would really prefer to have this part of the build process defined by angular.json.


The tailwind processing needs to run after all the routes are pre-rendered to the distribution using this builder.

https://github.com/angular/universal/blob/main/modules/builders/src/prerender/index.ts


I think this can easily be done by following in the footsteps of custom webpack builders.

https://github.com/just-jeb/angular-builders/blob/master/packages/custom-webpack/src/server/index.ts


builds reference

https://github.com/angular/angular-cli/tree/main/packages/angular_devkit/build_angular/src/builders


Meat and potatos of render process.

https://github.com/angular/universal/blob/main/modules/builders/src/prerender/worker.ts


  1. Create @rollthecloudinc/builders
  2. Create druid webpack

The druid webpack builder:

In the case of prerender the target will be prerender and custom webpack config will be the one for additional measures after the app has been pre-rendered. In this case running tailwind pointed at dist through webpack.

{
    "ipe": {
        "prerender": {
          "builder": "@nguniversal/builders:prerender",
          "options": {
            "browserTarget": "ipe:build",
            "serverTarget": "ipe:server"
          },
          "configurations": {
            "dev": {
              "browserTarget": "ipe:build:dev",
              "serverTarget": "ipe:server:dev"
            },
            "prod": {
              "browserTarget": "ipe:build:prod",
              "serverTarget": "ipe:server:prod"
            }
          }
    }
}
{
    "ipe": {
        "dprerender": {
          "builder": "@rollthecloudinc/builders:dpack",
          "options": {
            "target": "ipe:prerender",
            "customWebpackConfig": {
              "path": "./projects/ipe/dpack.config.js"
            }
          },
          "configurations": {
            "dev": {
              "target": "ipe:prerender:dev",
            },
            "prod": {
              "target": "ipe:prerender:prod",
            }
          }
    }
}