Skip to content

Commit 88d1bbf

Browse files
authored
fix: Make TypeScript typing more accurate for Options and generate js/css references (#35)
1 parent 868d145 commit 88d1bbf

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

src/index.ts

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ type Options = {
1717
publicPath?: string;
1818
context?: Context;
1919
template?: (
20-
args: Context | { css: string; js: string; publicPath: string }
20+
args: Context & Files & { publicPath: string }
2121
) => string | Promise<string>;
2222
chunks?: string[];
2323
};
@@ -76,8 +76,12 @@ function generateCSSReferences({
7676
}: {
7777
files: string[];
7878
publicPath: string;
79-
attributes: { rel?: string };
80-
}) {
79+
attributes: (Attributes & { rel?: string }) | undefined;
80+
}): string {
81+
if (!attributes) {
82+
return '';
83+
}
84+
8185
const allAttributes = {
8286
...attributes,
8387
rel: 'rel' in attributes ? attributes.rel : 'stylesheet',
@@ -95,11 +99,18 @@ function generateJSReferences({
9599
files = [],
96100
publicPath = '',
97101
attributes = {},
98-
}) {
99-
attributes = generateAttributes(attributes);
100-
102+
}: {
103+
files: string[];
104+
publicPath: string;
105+
attributes: Attributes;
106+
}): string {
101107
return files
102-
.map((file) => `<script src="${publicPath}${file}"${attributes}></script>`)
108+
.map(
109+
(file) =>
110+
`<script src="${publicPath}${file}"${generateAttributes(
111+
attributes
112+
)}></script>`
113+
)
103114
.join('');
104115
}
105116

0 commit comments

Comments
 (0)