Skip to content

Commit

Permalink
Make KeepNames optional (close #345)
Browse files Browse the repository at this point in the history
  • Loading branch information
ije committed Jun 9, 2022
1 parent 30e7c2c commit 28f20a1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
8 changes: 6 additions & 2 deletions server/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ type BuildTask struct {
Alias map[string]string `json:"alias"`
Deps PkgSlice `json:"deps"`
Target string `json:"target"`
DevMode bool `json:"dev"`
BundleMode bool `json:"bundle"`
NoRequire bool `json:"noRequire"`
DevMode bool `json:"dev"`
KeepNames bool `json:"keepNames"`

// state
id string
Expand All @@ -50,6 +51,9 @@ func (task *BuildTask) ID() string {
if task.NoRequire {
name += ".nr"
}
if task.KeepNames {
name += ".kn"
}
if task.DevMode {
name += ".development"
}
Expand Down Expand Up @@ -329,7 +333,7 @@ esbuild:
MinifyWhitespace: !task.DevMode,
MinifyIdentifiers: !task.DevMode,
MinifySyntax: !task.DevMode,
KeepNames: true, // prevent class/function names erasing
KeepNames: task.KeepNames, // prevent class/function names erasing
Plugins: []api.Plugin{esmResolverPlugin},
Loader: map[string]api.Loader{
".wasm": api.LoaderDataURL,
Expand Down
8 changes: 7 additions & 1 deletion server/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,7 @@ func query(devMode bool) rex.Handle {
isWorker := ctx.Form.Has("worker")
noCheck := ctx.Form.Has("no-check")
noRequire := ctx.Form.Has("no-require")
keepNames := ctx.Form.Has("keep-names")

// force react/jsx-dev-runtime and react-refresh into `dev` mode
if !isDev {
Expand Down Expand Up @@ -454,6 +455,10 @@ func query(devMode bool) rex.Handle {
submodule = strings.TrimSuffix(submodule, ".development")
isDev = true
}
if endsWith(submodule, ".kn") {
submodule = strings.TrimSuffix(submodule, ".kn")
keepNames = true
}
if endsWith(submodule, ".nr") {
submodule = strings.TrimSuffix(submodule, ".nr")
noRequire = true
Expand Down Expand Up @@ -538,9 +543,10 @@ func query(devMode bool) rex.Handle {
Alias: alias,
Deps: deps,
Target: target,
DevMode: isDev,
BundleMode: isBundleMode || isWorker,
NoRequire: noRequire,
DevMode: isDev,
KeepNames: keepNames,
stage: "init",
}
taskID := task.ID()
Expand Down

0 comments on commit 28f20a1

Please sign in to comment.