Skip to content

Commit

Permalink
Fixed #158
Browse files Browse the repository at this point in the history
Bug that prevented static deploy command from building components that included a react import.
  • Loading branch information
GuyARoss committed Sep 20, 2023
1 parent 5d505e2 commit db8ac78
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions pkg/webwrap/react_ssr.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,19 @@ func (r *PartialWrapReactSSR) Setup(ctx context.Context, settings *BundleOpts) (
}

func (r *PartialWrapReactSSR) Apply(doc jsparse.JSDocument) (jsparse.JSDocument, error) {
doc.AddImport(&jsparse.ImportDependency{
FinalStatement: "import React from 'react'",
Type: jsparse.ModuleImportType,
})
hasImport := false
for _, imp := range doc.Imports() {
if strings.Contains(imp.FinalStatement, "import React from 'react'") {
hasImport = true
}
}

if !hasImport {
doc.AddImport(&jsparse.ImportDependency{
FinalStatement: "import React from 'react'",
Type: jsparse.ModuleImportType,
})
}

doc.AddOther(fmt.Sprintf(
"export default %s",
Expand Down

0 comments on commit db8ac78

Please sign in to comment.