diff --git a/cmd/build.go b/cmd/build.go index a764d81..436464b 100644 --- a/cmd/build.go +++ b/cmd/build.go @@ -76,6 +76,9 @@ var buildCMD = &cobra.Command{ WebPrefix: outDir, CacheDir: "", }) + // note: altering the order of the appends will break functionality + htmlDoc.Body = append(htmlDoc.Body, wr.DocumentTag(spaEntryComponent.BundleKey())) + htmlDoc.Body = append(htmlDoc.Body, body...) htmlDoc.Body = append(htmlDoc.Body, fmt.Sprintf(``, spaEntryComponent.BundleKey())) diff --git a/examples/spa/pages/app.jsx b/examples/spa/pages/app.jsx index 665b2c2..4efc60a 100644 --- a/examples/spa/pages/app.jsx +++ b/examples/spa/pages/app.jsx @@ -1,10 +1,12 @@ const Example = () => { + const date = new Date(); + return (

Orbit!

Welcome to this example

- Today is {day}/{month}/{year} + Today is {date.toString()}

) diff --git a/pkg/webwrap/javascript.go b/pkg/webwrap/javascript.go index e10ee3a..957b817 100644 --- a/pkg/webwrap/javascript.go +++ b/pkg/webwrap/javascript.go @@ -23,6 +23,8 @@ type JavascriptWrap struct { const javascriptExtension string = "js" +func (s *JavascriptWrap) DocumentTag(string) string { return "" } + func (s *JavascriptWrap) Apply(page jsparse.JSDocument) (map[string]jsparse.JSDocument, error) { if page.Extension() != javascriptExtension { // @@todo bad pattern fix this return nil, fmt.Errorf("invalid extension %s", page.Extension()) diff --git a/pkg/webwrap/react_csr.go b/pkg/webwrap/react_csr.go index ec2318a..bc577c3 100644 --- a/pkg/webwrap/react_csr.go +++ b/pkg/webwrap/react_csr.go @@ -27,6 +27,10 @@ type ReactCSR struct { var ErrComponentExport = errors.New("prefer capitalization for jsx components") var ErrInvalidComponent = errors.New("invalid jsx component") +func (s *ReactCSR) DocumentTag(key string) string { + return fmt.Sprintf(`
`, key) +} + func (s *ReactCSR) Apply(page jsparse.JSDocument) (map[string]jsparse.JSDocument, error) { if len(string(page.Name())) == 0 { return nil, ErrInvalidComponent diff --git a/pkg/webwrap/react_hydrate.go b/pkg/webwrap/react_hydrate.go index dd9743e..aa2a414 100644 --- a/pkg/webwrap/react_hydrate.go +++ b/pkg/webwrap/react_hydrate.go @@ -19,6 +19,10 @@ type ReactHydrate struct { ssr *PartialWrapReactSSR } +func (s *ReactHydrate) DocumentTag(key string) string { + return fmt.Sprintf(`
`, key) +} + func (s *ReactHydrate) Apply(page jsparse.JSDocument) (map[string]jsparse.JSDocument, error) { // react components should always be capitalized. if string(page.Name()[0]) != strings.ToUpper(string(page.Name()[0])) { diff --git a/pkg/webwrap/wrap.go b/pkg/webwrap/wrap.go index 0607b9f..4798c1e 100644 --- a/pkg/webwrap/wrap.go +++ b/pkg/webwrap/wrap.go @@ -34,11 +34,13 @@ type JSWebWrapper interface { Stats() *WrapStats VerifyRequirements() error Version() string + DocumentTag(string) string } type WrapStats struct { - WebVersion string - Bundler string + WebVersion string + Bundler string + HTMLBodyTag string } type JSWebWrapperList []JSWebWrapper