handle inline javascript in assetbundle.go

This commit is contained in:
Steve Chung 2021-07-21 17:22:07 -04:00
commit 8a5287794e
3 changed files with 27 additions and 1 deletions

View file

@ -137,7 +137,7 @@ func (a *AssetBundle) processHTML(htmldata string) error {
break
}
}
if !paths.Contains(asset.Path) {
if !paths.Contains(asset.Path) && asset.Path != "" {
err := asset.Load(a.basedirectory)
if err != nil {
return err

View file

@ -44,6 +44,17 @@ func TestNewAssetBundle(t *testing.T) {
},
wantErr: false,
},
{
name: "inline javascript",
pathToHTML: "testdata/inline_javascript.html",
wantAssets: []string{
AssetTypes.HTML,
AssetTypes.FAVICON,
AssetTypes.JS,
AssetTypes.CSS,
},
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {

View file

@ -0,0 +1,15 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/src/favicon.svg"></link>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<script type="text/javascript" src="src/bundle.js"></script>
<link rel="stylesheet" href="src/style.css"></link>
<title>Vite App</title>
<script>console.log("test")</script>
</head>
<body>
<div id="root"></div>
</body>
</html>