Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add solid_options for solid babel plugin options #13

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions src/preset.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import path from 'path'
import * as tsup from 'tsup'
import * as esbuild from 'esbuild'
import { solidPlugin } from 'esbuild-plugin-solid'
import { type Options, solidPlugin } from 'esbuild-plugin-solid'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please alias Options or the while import as solid so it's obvious what Options is.


export interface EntryOptions {
name?: string | undefined
Expand All @@ -11,6 +11,14 @@ export interface EntryOptions {
dev_entry?: boolean | string
/** Setting `true` will generate a server-only entry (default: `false`) */
server_entry?: boolean | string
/**
* Pass any additional [babel-plugin-jsx-dom-expressions](https://github.com/ryansolid/dom-expressions/tree/main/packages/babel-plugin-jsx-dom-expressions#plugin-options).
* They will be merged with the defaults sets by [babel-preset-solid](https://github.com/solidjs/solid/blob/main/packages/babel-preset-solid/index.js#L8-L25).
* Option `generate` will be set to `ssr` if `server_entry` is set to `true` and `dom` otherwise.
*
* @default {}
*/
solid_options?: Options['solid'] | undefined
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why only "solid" field?

}

export type ModifyEsbuildOptions = (
Expand Down Expand Up @@ -67,6 +75,7 @@ export interface EntryType {
dev: boolean
server: boolean
jsx: boolean
solid_options: Options['solid']
}

export interface BuildItem {
Expand Down Expand Up @@ -127,6 +136,7 @@ export function parsePresetOptions(
dev: !!options.dev_entry,
server: !!options.server_entry,
jsx: options.entry.endsWith('.jsx') || options.entry.endsWith('.tsx'),
solid_options: options.solid_options,
},
}
})
Expand Down Expand Up @@ -179,7 +189,11 @@ export function generateTsupOptions(
if (item) {
item.entries.add(entry)
} else {
items.push({ type: { dev, server, jsx }, entries: new Set([entry]) })
const solid_options = entry.options.solid_options ?? {}
items.push({
type: { dev, server, jsx, solid_options },
entries: new Set([entry]),
})
}
}
}
Expand Down Expand Up @@ -247,7 +261,12 @@ export function generateTsupOptions(
},
esbuildPlugins: !type.jsx
? [
solidPlugin({ solid: { generate: type.server ? 'ssr' : 'dom' } }),
solidPlugin({
solid: {
generate: type.server ? 'ssr' : 'dom',
...type.solid_options,
},
}),
Comment on lines -250 to +269
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

imo this should be added to preset, not entry, options as (type: EntryType) => SolidPluginOptions. And without merging with the default one. Either user provides options or we.

...options.esbuild_plugins,
]
: options.esbuild_plugins,
Expand Down