Merge pull request #762 from s12chung/inline-js

[v2] handle inline javascript in assetbundle.go
This commit is contained in:
Lea Anthony
2021-07-31 00:07:17 +10:00
committed by GitHub
3 changed files with 27 additions and 1 deletions
+1 -1
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
+11
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) {
+15
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>