implement custom output paths for entry points

This commit is contained in:
Evan Wallace
2021-03-28 03:41:29 -07:00
parent 5767f8c5fe
commit 225d6ef83f
15 changed files with 321 additions and 147 deletions

View File

@@ -271,7 +271,9 @@ type BuildOptions struct {
ChunkNames string
AssetNames string
EntryPoints []string
EntryPoints []string
EntryPointsAdvanced []EntryPoint
Stdin *StdinOptions
Write bool
Incremental bool
@@ -280,6 +282,11 @@ type BuildOptions struct {
Watch *WatchMode
}
type EntryPoint struct {
InputPath string
OutputPath string
}
type WatchMode struct {
OnRebuild func(BuildResult)
}

View File

@@ -792,7 +792,13 @@ func rebuildImpl(
for i, path := range buildOpts.NodePaths {
options.AbsNodePaths[i] = validatePath(log, realFS, path, "node path")
}
entryPoints := append([]string{}, buildOpts.EntryPoints...)
entryPoints := make([]bundler.EntryPoint, 0, len(buildOpts.EntryPoints)+len(buildOpts.EntryPointsAdvanced))
for _, ep := range buildOpts.EntryPoints {
entryPoints = append(entryPoints, bundler.EntryPoint{InputPath: ep})
}
for _, ep := range buildOpts.EntryPointsAdvanced {
entryPoints = append(entryPoints, bundler.EntryPoint{InputPath: ep.InputPath, OutputPath: ep.OutputPath})
}
entryPointCount := len(entryPoints)
if buildOpts.Stdin != nil {
entryPointCount++

View File

@@ -458,7 +458,14 @@ func parseOptionsImpl(
return fmt.Errorf("Unexpected single quote character before flag (use \\\" to escape double quotes): %s", arg), nil
case !strings.HasPrefix(arg, "-") && buildOpts != nil:
buildOpts.EntryPoints = append(buildOpts.EntryPoints, arg)
if equals := strings.IndexByte(arg, '='); equals != -1 {
buildOpts.EntryPointsAdvanced = append(buildOpts.EntryPointsAdvanced, api.EntryPoint{
OutputPath: arg[:equals],
InputPath: arg[equals+1:],
})
} else {
buildOpts.EntryPoints = append(buildOpts.EntryPoints, arg)
}
default:
if buildOpts != nil {
@@ -606,7 +613,7 @@ func runImpl(osArgs []string) int {
}
// Read from stdin when there are no entry points
if len(buildOptions.EntryPoints) == 0 {
if len(buildOptions.EntryPoints)+len(buildOptions.EntryPointsAdvanced) == 0 {
if buildOptions.Stdin == nil {
buildOptions.Stdin = &api.StdinOptions{}
}