Skip to content

Commit 29c5661

Browse files
committed
Add deploy url option to be able to keep paths in sync
1 parent c3235d8 commit 29c5661

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ program
4141
'-e, --exclude [exclude]',
4242
'Optional comma separated list of font names to exclude from the preload link generation. Provide the names without file extension, e.g. "helvetica" instead of "helvetica.woff2"'
4343
)
44+
.option(
45+
'--deployUrl [deployUrl]',
46+
'Optional path prefix for your deployment allowing to preload in builds using a deploy url'
47+
)
4448
.parse(process.argv);
4549

4650
// console.log('Options: ', program.opts());
@@ -56,6 +60,7 @@ if (!program.dist) {
5660

5761
program.dist = FileUtil.normalizePath(program.dist);
5862
program.file = program.file ?? 'index.html';
63+
program.deployUrl = program.deployUrl ?? '';
5964

6065
const appBuildDirs = FileUtil.getAppBuildDirs(program.dist, program.file);
6166

@@ -78,7 +83,7 @@ for (const appBuildDir of appBuildDirs) {
7883
if (fonts && fonts.size > 0) {
7984
const preloadFontLinks = Array.from(fonts.keys())
8085
.map(
81-
(font) => `<link rel="preload" as="font" href="${font}" type="font/${fonts.get(font)}" crossorigin="anonymous">`
86+
(font) => `<link rel="preload" as="font" href="${FileUtil.normalizePath(program.deployUrl + font)}" type="font/${fonts.get(font)}" crossorigin="anonymous">`
8287
)
8388
.join('\n');
8489
const indexFilePath = `${appBuildDir}/${program.file}`;

0 commit comments

Comments
 (0)