Skip to content

Commit e224dff

Browse files
committed
Update html_script_tags.ts
1 parent e6776db commit e224dff

File tree

1 file changed

+2
-16
lines changed

1 file changed

+2
-16
lines changed

build/plugins/html_script_tags.ts

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
import type * as esbuild from '@esbuild';
22

33

4-
const defaultExtensionReplacements = {
5-
'.tsx': '.js',
6-
'.ts': '.js'
7-
}
8-
94
export function htmlScriptTags(options?: {
105
pattern?: RegExp,
11-
extension?: {[extension: string] : string}
6+
replaceExtensionWith?: string
127
}) : esbuild.Plugin {
138
return ({
149
name: 'html-script-tags',
@@ -18,16 +13,7 @@ export function htmlScriptTags(options?: {
1813
contents: Deno.readTextFileSync(args.path).replace(
1914
options?.pattern ?? /(?<=<script.*src=")(.*)(?=".*>)/gm,
2015
(_, scriptSrcPath : string) => {
21-
let path = scriptSrcPath;
22-
let replaced = false;
23-
Object.entries(options?.extension ?? defaultExtensionReplacements).forEach(([extension, replacement]) => {
24-
if (scriptSrcPath.match(extension) && !replaced) {
25-
path = scriptSrcPath.replace(extension, replacement)
26-
replaced = true
27-
}
28-
})
29-
30-
return path;
16+
return scriptSrcPath.replace(/\.tsx?$/, options?.replaceExtensionWith ?? '.js')
3117
}
3218
),
3319
loader: 'copy',

0 commit comments

Comments
 (0)