Skip to content

Commit

Permalink
🔨 Optimized post-build script to generate loader-files automatically …
Browse files Browse the repository at this point in the history
…by scanning the manifest file (#1683) (#1685)
  • Loading branch information
devtobi committed May 15, 2024
1 parent e438dad commit e290266
Showing 1 changed file with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import path from "node:path";
import { generateLoaderJs } from './lib/fileGenerator.js';
import manifest from '../dist/src/.vite/manifest.json' assert {type: 'json'};

Expand All @@ -24,10 +25,18 @@ import manifest from '../dist/src/.vite/manifest.json' assert {type: 'json'};
* but will automatically get it's new hash-value added every time we build our code.
*/

// read filename from manifest.json
const digiWFServiceInstancesWebComponent = manifest['src/digiwf-service-instances-webcomponent.ts'].file;
const digiWFHelloWorldWebComponent = manifest['src/digiwf-hello-world-webcomponent.ts'].file;
// Required filename content to be treated as webcomponent
const REQUIRED_PREFIX = 'src/';
const REQUIRED_SUFFIX = '-webcomponent.ts';

// generate loaderJs with the app script's filename
generateLoaderJs(digiWFServiceInstancesWebComponent, 'src', 'digiwf-service-instances-webcomponent');
generateLoaderJs(digiWFHelloWorldWebComponent, 'src', 'digiwf-hello-world-webcomponent');
for (const key in manifest) {
if (key.startsWith(REQUIRED_PREFIX) && key.endsWith(REQUIRED_SUFFIX)) {
// read filename from manifest
const entrypoint = manifest[key].file;

// get fileName and directory for generating loader file
const fileName = path.basename(key, path.extname(key));
const dirName = path.dirname(key);
generateLoaderJs(entrypoint, dirName, fileName);
}
}

0 comments on commit e290266

Please sign in to comment.