Skip to content

Commit

Permalink
fix orbit
Browse files Browse the repository at this point in the history
  • Loading branch information
GuyARoss committed Oct 23, 2024
1 parent 8ad99b9 commit e65a4a2
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 16 deletions.
4 changes: 4 additions & 0 deletions internal/assets/embed/orbit.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ func buildHTMLPages(data []byte, pages ...PageRender) *htmlDoc {
ctx := context.Background()
for _, p := range pages {
if op := wrapDocRender[p]; op != nil {
if useManifestConfig {
html.Head = append(html.Head, fmt.Sprintf(`<link rel="stylesheet" href="/p/%s.css">`, string(p)))
}

html, ctx = op.fn(ctx, string(p), data, html)
}
}
Expand Down
2 changes: 2 additions & 0 deletions internal/assets/embed/orbit_dynamic.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,5 @@ type DocumentRenderer struct {
}

var wrapDocRender = map[PageRender]*DocumentRenderer{}

var useManifestConfig bool = false
10 changes: 5 additions & 5 deletions internal/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ func Build(opts *BuildOpts) (srcpack.PackedComponentList, error) {
fileAssets := make([]fs.DirEntry, 0)
switch {
case experiments.GlobalExperimentalFeatures.PreferViteCompiler:
fileAssets = append(fileAssets, ats.AssetEntry(assets.VitePackConfig))
default:
fileAssets = append(fileAssets, ats.AssetEntry(assets.WebPackConfig),
ats.AssetEntry(assets.SSRProtoFile),
Expand Down Expand Up @@ -80,10 +79,11 @@ func Build(opts *BuildOpts) (srcpack.PackedComponentList, error) {
}

bg := libout.New(&libout.BundleGroupOpts{
PackageName: opts.Packname,
BaseBundleOut: ".orbit/dist",
BundleMode: opts.Mode,
PublicDir: opts.PublicDir,
PackageName: opts.Packname,
BaseBundleOut: ".orbit/dist",
BundleMode: opts.Mode,
PublicDir: opts.PublicDir,
UseManifestConfig: experiments.GlobalExperimentalFeatures.PreferViteCompiler,
})

ctx := context.Background()
Expand Down
10 changes: 10 additions & 0 deletions internal/libout/goout.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,13 @@ func (l *GOLibout) HTTPFile(packageName string) (LiboutFile, error) {
}, nil
}

func boolToString(b bool) string {
if b {
return "true"
}
return "false"
}

func (l *GOLibout) EnvFile(bg *BundleGroup) (LiboutFile, error) {
out := strings.Builder{}

Expand Down Expand Up @@ -300,6 +307,9 @@ type DocumentRenderer struct {
out.WriteString(fmt.Sprintf(`var hotReloadPort int = %d`, bg.HotReloadPort))
out.WriteString("\n")

out.WriteString(fmt.Sprintf(`var useManifestConfig bool = %s`, boolToString(bg.UseManifestConfig)))
out.WriteString("\n")

out.WriteString("type PageRender string\n\n")

for idx, p := range bg.pages {
Expand Down
11 changes: 6 additions & 5 deletions internal/libout/libout.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ import (
)

type BundleGroupOpts struct {
PackageName string
BaseBundleOut string
BundleMode string
PublicDir string
HotReloadPort int
PackageName string
BaseBundleOut string
BundleMode string
PublicDir string
HotReloadPort int
UseManifestConfig bool
}

type page struct {
Expand Down
44 changes: 38 additions & 6 deletions pkg/webwrap/react_csr.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,43 @@ func (s *ReactCSR) RequiredBodyDOMElements(ctx context.Context, cache *CacheDOMO

func (b *ReactCSR) Setup(ctx context.Context, settings *BundleOpts) (*BundledResource, error) {
page := jsparse.NewEmptyDocument()
bundleFilePath := fmt.Sprintf("%s/%s.js", b.PageOutputDir, settings.BundleKey)

if experiments.GlobalExperimentalFeatures.PreferViteCompiler {
bundleFilePath := fmt.Sprintf("%s/%s.jsx", b.PageOutputDir, settings.BundleKey)

page.AddOther(fmt.Sprintf(`
import { defineConfig } from 'vite';
import { resolve } from 'path';
import react from '@vitejs/plugin-react';
export default defineConfig({
plugins: [react()],
build: {
outDir: '../../dist',
manifest: true,
rollupOptions: {
input: resolve(__dirname, "./%s.jsx"),
output: {
entryFileNames: '[name].js',
chunkFileNames: '[name].js',
assetFileNames: '[name].[ext]'
}
}
},
optimizeDeps: {
include: ['@emotion/styled'],
},
});
`, settings.BundleKey))

return &BundledResource{
BundleOpFileDescriptor: map[string]string{"normal": bundleFilePath},
Configurators: []BundleConfigurator{},
Configurators: []BundleConfigurator{
{
FilePath: fmt.Sprintf("%s/%s.config.js", b.PageOutputDir, settings.BundleKey),
Page: page,
},
},
}, nil
}

Expand All @@ -156,6 +186,8 @@ func (b *ReactCSR) Setup(ctx context.Context, settings *BundleOpts) (*BundledRes

outputFileName := fmt.Sprintf("%s.js", settings.BundleKey)

bundleFilePath := fmt.Sprintf("%s/%s.js", b.PageOutputDir, settings.BundleKey)

page.AddOther(fmt.Sprintf(`module.exports = merge(baseConfig, {
entry: ['./%s'],
mode: '%s',
Expand All @@ -176,12 +208,12 @@ func (b *ReactCSR) Setup(ctx context.Context, settings *BundleOpts) (*BundledRes
}

func (b *ReactCSR) Bundle(configuratorFilePath string, filePath string) error {
if experiments.GlobalExperimentalFeatures.PreferViteCompiler { // TODO: do this once
cmd := exec.Command("vite", "build", ".orbit/base/pages", "--config", ".orbit/assets/vite.config.js")
output, err := cmd.Output()
if experiments.GlobalExperimentalFeatures.PreferViteCompiler {
cmd := exec.Command("vite", "build", ".orbit/base/pages", "--config", configuratorFilePath)
_, err := cmd.Output()

if err != nil {
b.Logger.Warn(fmt.Sprintf(`invalid pack: vite '%s'`, output))
b.Logger.Warn(fmt.Sprintf(`invalid pack: vite '%s'`, err))
return parseerror.New("failed to bundle, this could denote a syntax error", filePath)
}
return nil
Expand Down

0 comments on commit e65a4a2

Please sign in to comment.