Skip to content

Commit

Permalink
feat: added incremental bundling
Browse files Browse the repository at this point in the history
  • Loading branch information
crazywolf132 committed Sep 24, 2024
1 parent f7a9511 commit 8397fc9
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions pkg/esbuild/esbuild.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ type BundlerConfig struct {
}

type Bundler struct {
config *BundlerConfig
pkg *config.PackageJSON
config *BundlerConfig
pkg *config.PackageJSON
buildCtx *api.BuildContext
}

func NewBundler(config *BundlerConfig, pkg *config.PackageJSON) *Bundler {
Expand Down Expand Up @@ -102,6 +103,11 @@ func (b *Bundler) bundleEntry(sourcePath *utils.SourcePathResult, entry config.E
Plugins: plugins,
}

ctx, err := api.Context(buildOptions)
if err != nil {
return err
}

if b.config.TsconfigPath != "" {
buildOptions.Tsconfig = b.config.TsconfigPath
}
Expand All @@ -110,7 +116,14 @@ func (b *Bundler) bundleEntry(sourcePath *utils.SourcePathResult, entry config.E
buildOptions.Conditions = b.config.ExportConditions
}

result := api.Build(buildOptions)
var result api.BuildResult

if b.buildCtx != nil {
result = ctx.Rebuild()
} else {
result = api.Build(buildOptions)
b.buildCtx = &ctx
}

if len(result.Errors) > 0 {
return fmt.Errorf("build failed for %s: %v", entry.OutputPath, result.Errors)
Expand Down Expand Up @@ -175,9 +188,6 @@ func (b *Bundler) getExternalDependencies() []string {
for dep := range b.pkg.PeerDependencies {
externals = append(externals, dep)
}
for dep := range b.pkg.DevDependencies {
externals = append(externals, dep)
}
return externals
}

Expand Down

0 comments on commit 8397fc9

Please sign in to comment.