vite-plugin-solid 2.1.3 → 2.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -13,7 +13,12 @@ const runtimePublicPath = '/@solid-refresh';
13
13
  const runtimeFilePath = require.resolve('solid-refresh/dist/solid-refresh.mjs');
14
14
 
15
15
  const runtimeCode = readFileSync(runtimeFilePath, 'utf-8');
16
- /** Configuration options for vite-plugin-solid. */
16
+ /** Possible options for the extensions property */
17
+
18
+ function getExtension(filename) {
19
+ const index = filename.lastIndexOf('.');
20
+ return index < 0 ? '' : filename.substring(index);
21
+ }
17
22
 
18
23
  function solidPlugin(options = {}) {
19
24
  let needHmr = false;
@@ -34,12 +39,13 @@ function solidPlugin(options = {}) {
34
39
 
35
40
  const legacyAlias = normalizeAliases(userConfig.alias);
36
41
  if (!userConfig.resolve) userConfig.resolve = {};
37
- userConfig.resolve.alias = [...legacyAlias, ...normalizeAliases((_userConfig$resolve = userConfig.resolve) === null || _userConfig$resolve === void 0 ? void 0 : _userConfig$resolve.alias)];
38
- const nestedDeps = ['solid-js', 'solid-js/web', 'solid-js/store', 'solid-js/html', 'solid-js/h'];
42
+ userConfig.resolve.alias = [...legacyAlias, ...normalizeAliases((_userConfig$resolve = userConfig.resolve) === null || _userConfig$resolve === void 0 ? void 0 : _userConfig$resolve.alias)]; // fix for bundling dev in production
43
+
44
+ const nestedDeps = replaceDev ? ['solid-js', 'solid-js/web', 'solid-js/store', 'solid-js/html', 'solid-js/h'] : [];
39
45
  return {
40
- /**
41
- * We only need esbuild on .ts or .js files.
42
- * .tsx & .jsx files are handled by us
46
+ /**
47
+ * We only need esbuild on .ts or .js files.
48
+ * .tsx & .jsx files are handled by us
43
49
  */
44
50
  esbuild: {
45
51
  include: /\.ts$/
@@ -71,14 +77,21 @@ function solidPlugin(options = {}) {
71
77
  },
72
78
 
73
79
  async transform(source, id, transformOptions) {
74
- // @ts-expect-error anticipate vite changing second parameter as options object
75
- // see https://github.com/vitejs/vite/discussions/5109
76
- const ssr = transformOptions === true || (transformOptions === null || transformOptions === void 0 ? void 0 : transformOptions.ssr);
77
- if (!/\.[jt]sx/.test(id)) return null;
80
+ const isSsr = transformOptions === null || transformOptions === void 0 ? void 0 : transformOptions.ssr;
81
+ const currentFileExtension = getExtension(id);
82
+ const extensionsToWatch = [...(options.extensions || []), '.tsx', '.jsx'];
83
+ const allExtensions = extensionsToWatch.map(extension => // An extension can be a string or a tuple [extension, options]
84
+ typeof extension === 'string' ? extension : extension[0]);
85
+
86
+ if (!allExtensions.includes(currentFileExtension)) {
87
+ return null;
88
+ }
89
+
90
+ const inNodeModules = /node_modules/.test(id);
78
91
  let solidOptions;
79
92
 
80
93
  if (options.ssr) {
81
- if (ssr) {
94
+ if (isSsr) {
82
95
  solidOptions = {
83
96
  generate: 'ssr',
84
97
  hydratable: true
@@ -105,15 +118,25 @@ function solidPlugin(options = {}) {
105
118
  presets: [[solid, { ...solidOptions,
106
119
  ...(options.solid || {})
107
120
  }]],
108
- plugins: needHmr ? [[solidRefresh, {
121
+ plugins: needHmr && !isSsr && !inNodeModules ? [[solidRefresh, {
109
122
  bundler: 'vite'
110
123
  }]] : [],
111
124
  sourceMaps: true,
112
125
  // Vite handles sourcemap flattening
113
126
  inputSourceMap: false
114
- };
127
+ }; // We need to know if the current file extension has a typescript options tied to it
128
+
129
+ const shouldBeProcessedWithTypescript = extensionsToWatch.some(extension => {
130
+ if (typeof extension === 'string') {
131
+ return extension.includes('tsx');
132
+ }
133
+
134
+ const [extensionName, extensionOptions] = extension;
135
+ if (extensionName !== currentFileExtension) return false;
136
+ return extensionOptions.typescript;
137
+ });
115
138
 
116
- if (id.includes('tsx')) {
139
+ if (shouldBeProcessedWithTypescript) {
117
140
  opts.presets.push([ts, options.typescript || {}]);
118
141
  } // Default value for babel user options
119
142
 
@@ -122,7 +145,7 @@ function solidPlugin(options = {}) {
122
145
 
123
146
  if (options.babel) {
124
147
  if (typeof options.babel === 'function') {
125
- const babelOptions = options.babel(source, id, ssr);
148
+ const babelOptions = options.babel(source, id, isSsr);
126
149
  babelUserOptions = babelOptions instanceof Promise ? await babelOptions : babelOptions;
127
150
  } else {
128
151
  babelUserOptions = options.babel;
@@ -142,11 +165,11 @@ function solidPlugin(options = {}) {
142
165
 
143
166
  };
144
167
  }
145
- /**
146
- * This basically normalize all aliases of the config into
147
- * the array format of the alias.
148
- *
149
- * eg: alias: { '@': 'src/' } => [{ find: '@', replacement: 'src/' }]
168
+ /**
169
+ * This basically normalize all aliases of the config into
170
+ * the array format of the alias.
171
+ *
172
+ * eg: alias: { '@': 'src/' } => [{ find: '@', replacement: 'src/' }]
150
173
  */
151
174
 
152
175
  function normalizeAliases(alias = []) {
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sources":["../../src/index.ts"],"sourcesContent":["import { transformAsync, TransformOptions } from '@babel/core';\r\nimport ts from '@babel/preset-typescript';\r\nimport solid from 'babel-preset-solid';\r\nimport { readFileSync } from 'fs';\r\nimport { mergeAndConcat } from 'merge-anything';\r\nimport { createRequire } from 'module';\r\nimport solidRefresh from 'solid-refresh/babel.js';\r\nimport type { Alias, AliasOptions, Plugin, UserConfig } from 'vite';\r\n\r\nconst require = createRequire(import.meta.url);\r\n\r\nconst runtimePublicPath = '/@solid-refresh';\r\nconst runtimeFilePath = require.resolve('solid-refresh/dist/solid-refresh.mjs');\r\nconst runtimeCode = readFileSync(runtimeFilePath, 'utf-8');\r\n\r\n/** Configuration options for vite-plugin-solid. */\r\nexport interface Options {\r\n /**\r\n * This will inject solid-js/dev in place of solid-js in dev mode. Has no\r\n * effect in prod. If set to `false`, it won't inject it in dev. This is\r\n * useful for extra logs and debugging.\r\n *\r\n * @default true\r\n */\r\n dev: boolean;\r\n /**\r\n * This will force SSR code in the produced files. This is experiemental\r\n * and mostly not working yet.\r\n *\r\n * @default false\r\n */\r\n ssr: boolean;\r\n /**\r\n * This will inject HMR runtime in dev mode. Has no effect in prod. If\r\n * set to `false`, it won't inject the runtime in dev.\r\n *\r\n * @default true\r\n */\r\n hot: boolean;\r\n /**\r\n * Pass any additional babel transform options. They will be merged with\r\n * the transformations required by Solid.\r\n *\r\n * @default {}\r\n */\r\n babel:\r\n | TransformOptions\r\n | ((source: string, id: string, ssr: boolean) => TransformOptions)\r\n | ((source: string, id: string, ssr: boolean) => Promise<TransformOptions>);\r\n typescript: {\r\n /**\r\n * Forcibly enables jsx parsing. Otherwise angle brackets will be treated as\r\n * typescript's legacy type assertion var foo = <string>bar;. Also, isTSX:\r\n * true requires allExtensions: true.\r\n *\r\n * @default false\r\n */\r\n isTSX?: boolean;\r\n\r\n /**\r\n * Replace the function used when compiling JSX expressions. This is so that\r\n * we know that the import is not a type import, and should not be removed.\r\n *\r\n * @default React\r\n */\r\n jsxPragma?: string;\r\n\r\n /**\r\n * Replace the function used when compiling JSX fragment expressions. This\r\n * is so that we know that the import is not a type import, and should not\r\n * be removed.\r\n *\r\n * @default React.Fragment\r\n */\r\n jsxPragmaFrag?: string;\r\n\r\n /**\r\n * Indicates that every file should be parsed as TS or TSX (depending on the\r\n * isTSX option).\r\n *\r\n * @default false\r\n */\r\n allExtensions?: boolean;\r\n\r\n /**\r\n * Enables compilation of TypeScript namespaces.\r\n *\r\n * @default uses the default set by @babel/plugin-transform-typescript.\r\n */\r\n allowNamespaces?: boolean;\r\n\r\n /**\r\n * When enabled, type-only class fields are only removed if they are\r\n * prefixed with the declare modifier:\r\n *\r\n * > NOTE: This will be enabled by default in Babel 8\r\n *\r\n * @default false\r\n *\r\n * @example\r\n * ```ts\r\n * class A {\r\n * declare foo: string; // Removed\r\n * bar: string; // Initialized to undefined\r\n * prop?: string; // Initialized to undefined\r\n * prop1!: string // Initialized to undefined\r\n * }\r\n * ```\r\n */\r\n allowDeclareFields?: boolean;\r\n\r\n /**\r\n * When set to true, the transform will only remove type-only imports\r\n * (introduced in TypeScript 3.8). This should only be used if you are using\r\n * TypeScript >= 3.8.\r\n *\r\n * @default false\r\n */\r\n onlyRemoveTypeImports?: boolean;\r\n\r\n /**\r\n * When set to true, Babel will inline enum values rather than using the\r\n * usual enum output:\r\n *\r\n * This option differs from TypeScript's --isolatedModules behavior, which\r\n * ignores the const modifier and compiles them as normal enums, and aligns\r\n * Babel's behavior with TypeScript's default behavior.\r\n *\r\n * ```ts\r\n * // Input\r\n * const enum Animals {\r\n * Fish\r\n * }\r\n * console.log(Animals.Fish);\r\n *\r\n * // Default output\r\n * var Animals;\r\n *\r\n * (function (Animals) {\r\n * Animals[Animals[\"Fish\"] = 0] = \"Fish\";\r\n * })(Animals || (Animals = {}));\r\n *\r\n * console.log(Animals.Fish);\r\n *\r\n * // `optimizeConstEnums` output\r\n * console.log(0);\r\n * ```\r\n *\r\n * However, when exporting a const enum Babel will compile it to a plain\r\n * object literal so that it doesn't need to rely on cross-file analysis\r\n * when compiling it:\r\n *\r\n * ```ts\r\n * // Input\r\n * export const enum Animals {\r\n * Fish,\r\n * }\r\n *\r\n * // `optimizeConstEnums` output\r\n * export var Animals = {\r\n * Fish: 0,\r\n * };\r\n * ```\r\n *\r\n * @default false\r\n */\r\n optimizeConstEnums?: boolean;\r\n };\r\n /**\r\n * Pass any additional [babel-plugin-jsx-dom-expressions](https://github.com/ryansolid/dom-expressions/tree/main/packages/babel-plugin-jsx-dom-expressions#plugin-options).\r\n * 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).\r\n *\r\n * @default {}\r\n */\r\n solid: {\r\n /**\r\n * The name of the runtime module to import the methods from.\r\n *\r\n * @default \"solid-js/web\"\r\n */\r\n moduleName?: string;\r\n\r\n /**\r\n * The output mode of the compiler.\r\n * Can be:\r\n * - \"dom\" is standard output\r\n * - \"ssr\" is for server side rendering of strings.\r\n *\r\n * @default \"dom\"\r\n */\r\n generate?: 'ssr' | 'dom';\r\n\r\n /**\r\n * Indicate whether the output should contain hydratable markers.\r\n *\r\n * @default false\r\n */\r\n hydratable?: boolean;\r\n\r\n /**\r\n * Boolean to indicate whether to enable automatic event delegation on camelCase.\r\n *\r\n * @default true\r\n */\r\n delegateEvents?: boolean;\r\n\r\n /**\r\n * Boolean indicates whether smart conditional detection should be used.\r\n * This optimizes simple boolean expressions and ternaries in JSX.\r\n *\r\n * @default true\r\n */\r\n wrapConditionals?: boolean;\r\n\r\n /**\r\n * Boolean indicates whether to set current render context on Custom Elements and slots.\r\n * Useful for seemless Context API with Web Components.\r\n *\r\n * @default true\r\n */\r\n contextToCustomElements?: boolean;\r\n\r\n /**\r\n * Array of Component exports from module, that aren't included by default with the library.\r\n * This plugin will automatically import them if it comes across them in the JSX.\r\n *\r\n * @default [\"For\",\"Show\",\"Switch\",\"Match\",\"Suspense\",\"SuspenseList\",\"Portal\",\"Index\",\"Dynamic\",\"ErrorBoundary\"]\r\n */\r\n builtIns?: string[];\r\n };\r\n}\r\n\r\nexport default function solidPlugin(options: Partial<Options> = {}): Plugin {\r\n let needHmr = false;\r\n let replaceDev = false;\r\n let projectRoot = process.cwd();\r\n\r\n return {\r\n name: 'solid',\r\n enforce: 'pre',\r\n\r\n config(userConfig, { command }): UserConfig {\r\n // We inject the dev mode only if the user explicitely wants it or if we are in dev (serve) mode\r\n replaceDev = options.dev === true || (options.dev !== false && command === 'serve');\r\n projectRoot = userConfig.root;\r\n\r\n // TODO: remove when fully removed from vite\r\n const legacyAlias = normalizeAliases(userConfig.alias);\r\n\r\n if (!userConfig.resolve) userConfig.resolve = {};\r\n userConfig.resolve.alias = [...legacyAlias, ...normalizeAliases(userConfig.resolve?.alias)];\r\n\r\n const nestedDeps = [\r\n 'solid-js',\r\n 'solid-js/web',\r\n 'solid-js/store',\r\n 'solid-js/html',\r\n 'solid-js/h',\r\n ];\r\n\r\n return {\r\n /**\r\n * We only need esbuild on .ts or .js files.\r\n * .tsx & .jsx files are handled by us\r\n */\r\n esbuild: { include: /\\.ts$/ },\r\n resolve: {\r\n conditions: ['solid', ...(replaceDev ? ['development'] : [])],\r\n dedupe: nestedDeps,\r\n alias: [{ find: /^solid-refresh$/, replacement: runtimePublicPath }],\r\n },\r\n optimizeDeps: {\r\n include: nestedDeps,\r\n },\r\n } as UserConfig;\r\n },\r\n\r\n configResolved(config) {\r\n needHmr = config.command === 'serve' && !config.isProduction && options.hot !== false;\r\n },\r\n\r\n resolveId(id) {\r\n if (id === runtimePublicPath) return id;\r\n },\r\n\r\n load(id) {\r\n if (id === runtimePublicPath) return runtimeCode;\r\n },\r\n\r\n async transform(source, id, transformOptions) {\r\n // @ts-expect-error anticipate vite changing second parameter as options object\r\n // see https://github.com/vitejs/vite/discussions/5109\r\n const ssr: boolean = transformOptions === true || transformOptions?.ssr;\r\n\r\n if (!/\\.[jt]sx/.test(id)) return null;\r\n\r\n let solidOptions: { generate: 'ssr' | 'dom'; hydratable: boolean };\r\n\r\n if (options.ssr) {\r\n if (ssr) {\r\n solidOptions = { generate: 'ssr', hydratable: true };\r\n } else {\r\n solidOptions = { generate: 'dom', hydratable: true };\r\n }\r\n } else {\r\n solidOptions = { generate: 'dom', hydratable: false };\r\n }\r\n\r\n const opts: TransformOptions = {\r\n babelrc: false,\r\n configFile: false,\r\n root: projectRoot,\r\n filename: id,\r\n sourceFileName: id,\r\n presets: [[solid, { ...solidOptions, ...(options.solid || {}) }]],\r\n plugins: needHmr ? [[solidRefresh, { bundler: 'vite' }]] : [],\r\n sourceMaps: true,\r\n // Vite handles sourcemap flattening\r\n inputSourceMap: false as any,\r\n };\r\n\r\n if (id.includes('tsx')) {\r\n opts.presets.push([ts, options.typescript || {}]);\r\n }\r\n\r\n // Default value for babel user options\r\n let babelUserOptions: TransformOptions = {};\r\n\r\n if (options.babel) {\r\n if (typeof options.babel === 'function') {\r\n const babelOptions = options.babel(source, id, ssr);\r\n babelUserOptions = babelOptions instanceof Promise ? await babelOptions : babelOptions;\r\n } else {\r\n babelUserOptions = options.babel;\r\n }\r\n }\r\n\r\n const babelOptions = mergeAndConcat(babelUserOptions, opts) as TransformOptions;\r\n\r\n const { code, map } = await transformAsync(source, babelOptions);\r\n\r\n return { code, map };\r\n },\r\n };\r\n}\r\n\r\n/**\r\n * This basically normalize all aliases of the config into\r\n * the array format of the alias.\r\n *\r\n * eg: alias: { '@': 'src/' } => [{ find: '@', replacement: 'src/' }]\r\n */\r\nfunction normalizeAliases(alias: AliasOptions = []): Alias[] {\r\n return Array.isArray(alias)\r\n ? alias\r\n : Object.entries(alias).map(([find, replacement]) => ({ find, replacement }));\r\n}\r\n"],"names":["require","createRequire","import","meta","url","runtimePublicPath","runtimeFilePath","resolve","runtimeCode","readFileSync","solidPlugin","options","needHmr","replaceDev","projectRoot","process","cwd","name","enforce","config","userConfig","command","dev","root","legacyAlias","normalizeAliases","alias","nestedDeps","esbuild","include","conditions","dedupe","find","replacement","optimizeDeps","configResolved","isProduction","hot","resolveId","id","load","transform","source","transformOptions","ssr","test","solidOptions","generate","hydratable","opts","babelrc","configFile","filename","sourceFileName","presets","solid","plugins","solidRefresh","bundler","sourceMaps","inputSourceMap","includes","push","ts","typescript","babelUserOptions","babel","babelOptions","Promise","mergeAndConcat","code","map","transformAsync","Array","isArray","Object","entries"],"mappings":";;;;;;;;AASA,MAAMA,OAAO,GAAGC,aAAa,CAACC,MAAM,CAACC,IAAP,CAAYC,GAAb,CAA7B;;AAEA,MAAMC,iBAAiB,GAAG,iBAA1B;;AACA,MAAMC,eAAe,GAAGN,OAAO,CAACO,OAAR,CAAgB,sCAAhB,CAAxB;;AACA,MAAMC,WAAW,GAAGC,YAAY,CAACH,eAAD,EAAkB,OAAlB,CAAhC;AAEA;;AAyNe,SAASI,WAAT,CAAqBC,OAAyB,GAAG,EAAjD,EAA6D;AAC1E,MAAIC,OAAO,GAAG,KAAd;AACA,MAAIC,UAAU,GAAG,KAAjB;AACA,MAAIC,WAAW,GAAGC,OAAO,CAACC,GAAR,EAAlB;AAEA,SAAO;AACLC,IAAAA,IAAI,EAAE,OADD;AAELC,IAAAA,OAAO,EAAE,KAFJ;;AAILC,IAAAA,MAAM,C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ACA;AACA;AACA;AACA;AACA;;AACA,SAAS9C,gBAAT,CAA0BC,KAAmB,GAAG,EAAhD,EAA6D;AAC3D,SAAO+C,KAAK,CAACC,OAAN,CAAchD,KAAd,IACHA,KADG,GAEHiD,MAAM,CAACC,OAAP,CAAelD,KAAf,EAAsB6C,GAAtB,CAA0B,CAAC,CAACvC,IAAD,EAAOC,WAAP,CAAD,MAA0B;AAAED,IAAAA,IAAF;AAAQC,IAAAA;AAAR,GAA1B,CAA1B,CAFJ;AAGD;;;;"}
1
+ {"version":3,"file":"index.mjs","sources":["../../src/index.ts"],"sourcesContent":["import { transformAsync, TransformOptions } from '@babel/core';\nimport ts from '@babel/preset-typescript';\nimport solid from 'babel-preset-solid';\nimport { readFileSync } from 'fs';\nimport { mergeAndConcat } from 'merge-anything';\nimport { createRequire } from 'module';\nimport solidRefresh from 'solid-refresh/babel.js';\nimport type { Alias, AliasOptions, Plugin, UserConfig } from 'vite';\n\nconst require = createRequire(import.meta.url);\n\nconst runtimePublicPath = '/@solid-refresh';\nconst runtimeFilePath = require.resolve('solid-refresh/dist/solid-refresh.mjs');\nconst runtimeCode = readFileSync(runtimeFilePath, 'utf-8');\n\n/** Possible options for the extensions property */\nexport interface ExtensionOptions {\n typescript?: boolean;\n}\n\n/** Configuration options for vite-plugin-solid. */\nexport interface Options {\n /**\n * This will inject solid-js/dev in place of solid-js in dev mode. Has no\n * effect in prod. If set to `false`, it won't inject it in dev. This is\n * useful for extra logs and debugging.\n *\n * @default true\n */\n dev: boolean;\n /**\n * This will force SSR code in the produced files. This is experiemental\n * and mostly not working yet.\n *\n * @default false\n */\n ssr: boolean;\n /**\n * This will inject HMR runtime in dev mode. Has no effect in prod. If\n * set to `false`, it won't inject the runtime in dev.\n *\n * @default true\n */\n hot: boolean;\n /**\n * This registers additional extensions that should be processed by\n * vite-plugin-solid.\n *\n * @default undefined\n */\n extensions?: (string | [string, ExtensionOptions])[];\n /**\n * Pass any additional babel transform options. They will be merged with\n * the transformations required by Solid.\n *\n * @default {}\n */\n babel:\n | TransformOptions\n | ((source: string, id: string, ssr: boolean) => TransformOptions)\n | ((source: string, id: string, ssr: boolean) => Promise<TransformOptions>);\n typescript: {\n /**\n * Forcibly enables jsx parsing. Otherwise angle brackets will be treated as\n * typescript's legacy type assertion var foo = <string>bar;. Also, isTSX:\n * true requires allExtensions: true.\n *\n * @default false\n */\n isTSX?: boolean;\n\n /**\n * Replace the function used when compiling JSX expressions. This is so that\n * we know that the import is not a type import, and should not be removed.\n *\n * @default React\n */\n jsxPragma?: string;\n\n /**\n * Replace the function used when compiling JSX fragment expressions. This\n * is so that we know that the import is not a type import, and should not\n * be removed.\n *\n * @default React.Fragment\n */\n jsxPragmaFrag?: string;\n\n /**\n * Indicates that every file should be parsed as TS or TSX (depending on the\n * isTSX option).\n *\n * @default false\n */\n allExtensions?: boolean;\n\n /**\n * Enables compilation of TypeScript namespaces.\n *\n * @default uses the default set by @babel/plugin-transform-typescript.\n */\n allowNamespaces?: boolean;\n\n /**\n * When enabled, type-only class fields are only removed if they are\n * prefixed with the declare modifier:\n *\n * > NOTE: This will be enabled by default in Babel 8\n *\n * @default false\n *\n * @example\n * ```ts\n * class A {\n * declare foo: string; // Removed\n * bar: string; // Initialized to undefined\n * prop?: string; // Initialized to undefined\n * prop1!: string // Initialized to undefined\n * }\n * ```\n */\n allowDeclareFields?: boolean;\n\n /**\n * When set to true, the transform will only remove type-only imports\n * (introduced in TypeScript 3.8). This should only be used if you are using\n * TypeScript >= 3.8.\n *\n * @default false\n */\n onlyRemoveTypeImports?: boolean;\n\n /**\n * When set to true, Babel will inline enum values rather than using the\n * usual enum output:\n *\n * This option differs from TypeScript's --isolatedModules behavior, which\n * ignores the const modifier and compiles them as normal enums, and aligns\n * Babel's behavior with TypeScript's default behavior.\n *\n * ```ts\n * // Input\n * const enum Animals {\n * Fish\n * }\n * console.log(Animals.Fish);\n *\n * // Default output\n * var Animals;\n *\n * (function (Animals) {\n * Animals[Animals[\"Fish\"] = 0] = \"Fish\";\n * })(Animals || (Animals = {}));\n *\n * console.log(Animals.Fish);\n *\n * // `optimizeConstEnums` output\n * console.log(0);\n * ```\n *\n * However, when exporting a const enum Babel will compile it to a plain\n * object literal so that it doesn't need to rely on cross-file analysis\n * when compiling it:\n *\n * ```ts\n * // Input\n * export const enum Animals {\n * Fish,\n * }\n *\n * // `optimizeConstEnums` output\n * export var Animals = {\n * Fish: 0,\n * };\n * ```\n *\n * @default false\n */\n optimizeConstEnums?: boolean;\n };\n /**\n * Pass any additional [babel-plugin-jsx-dom-expressions](https://github.com/ryansolid/dom-expressions/tree/main/packages/babel-plugin-jsx-dom-expressions#plugin-options).\n * 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).\n *\n * @default {}\n */\n solid: {\n /**\n * The name of the runtime module to import the methods from.\n *\n * @default \"solid-js/web\"\n */\n moduleName?: string;\n\n /**\n * The output mode of the compiler.\n * Can be:\n * - \"dom\" is standard output\n * - \"ssr\" is for server side rendering of strings.\n *\n * @default \"dom\"\n */\n generate?: 'ssr' | 'dom';\n\n /**\n * Indicate whether the output should contain hydratable markers.\n *\n * @default false\n */\n hydratable?: boolean;\n\n /**\n * Boolean to indicate whether to enable automatic event delegation on camelCase.\n *\n * @default true\n */\n delegateEvents?: boolean;\n\n /**\n * Boolean indicates whether smart conditional detection should be used.\n * This optimizes simple boolean expressions and ternaries in JSX.\n *\n * @default true\n */\n wrapConditionals?: boolean;\n\n /**\n * Boolean indicates whether to set current render context on Custom Elements and slots.\n * Useful for seemless Context API with Web Components.\n *\n * @default true\n */\n contextToCustomElements?: boolean;\n\n /**\n * Array of Component exports from module, that aren't included by default with the library.\n * This plugin will automatically import them if it comes across them in the JSX.\n *\n * @default [\"For\",\"Show\",\"Switch\",\"Match\",\"Suspense\",\"SuspenseList\",\"Portal\",\"Index\",\"Dynamic\",\"ErrorBoundary\"]\n */\n builtIns?: string[];\n };\n}\n\nfunction getExtension(filename: string): string {\n const index = filename.lastIndexOf('.');\n return index < 0 ? '' : filename.substring(index);\n}\n\nexport default function solidPlugin(options: Partial<Options> = {}): Plugin {\n let needHmr = false;\n let replaceDev = false;\n let projectRoot = process.cwd();\n\n return {\n name: 'solid',\n enforce: 'pre',\n\n config(userConfig, { command }): UserConfig {\n // We inject the dev mode only if the user explicitely wants it or if we are in dev (serve) mode\n replaceDev = options.dev === true || (options.dev !== false && command === 'serve');\n projectRoot = userConfig.root;\n\n // TODO: remove when fully removed from vite\n const legacyAlias = normalizeAliases(userConfig.alias);\n\n if (!userConfig.resolve) userConfig.resolve = {};\n userConfig.resolve.alias = [...legacyAlias, ...normalizeAliases(userConfig.resolve?.alias)];\n\n // fix for bundling dev in production\n const nestedDeps = replaceDev\n ? ['solid-js', 'solid-js/web', 'solid-js/store', 'solid-js/html', 'solid-js/h']\n : [];\n\n return {\n /**\n * We only need esbuild on .ts or .js files.\n * .tsx & .jsx files are handled by us\n */\n esbuild: { include: /\\.ts$/ },\n resolve: {\n conditions: ['solid', ...(replaceDev ? ['development'] : [])],\n dedupe: nestedDeps,\n alias: [{ find: /^solid-refresh$/, replacement: runtimePublicPath }],\n },\n optimizeDeps: {\n include: nestedDeps,\n },\n } as UserConfig;\n },\n\n configResolved(config) {\n needHmr = config.command === 'serve' && !config.isProduction && options.hot !== false;\n },\n\n resolveId(id) {\n if (id === runtimePublicPath) return id;\n },\n\n load(id) {\n if (id === runtimePublicPath) return runtimeCode;\n },\n\n async transform(source, id, transformOptions) {\n const isSsr = transformOptions?.ssr;\n const currentFileExtension = getExtension(id);\n\n const extensionsToWatch = [...(options.extensions || []), '.tsx', '.jsx'];\n const allExtensions = extensionsToWatch.map((extension) =>\n // An extension can be a string or a tuple [extension, options]\n typeof extension === 'string' ? extension : extension[0],\n );\n\n if (!allExtensions.includes(currentFileExtension)) {\n return null;\n }\n\n const inNodeModules = /node_modules/.test(id);\n\n let solidOptions: { generate: 'ssr' | 'dom'; hydratable: boolean };\n\n if (options.ssr) {\n if (isSsr) {\n solidOptions = { generate: 'ssr', hydratable: true };\n } else {\n solidOptions = { generate: 'dom', hydratable: true };\n }\n } else {\n solidOptions = { generate: 'dom', hydratable: false };\n }\n\n const opts: TransformOptions = {\n babelrc: false,\n configFile: false,\n root: projectRoot,\n filename: id,\n sourceFileName: id,\n presets: [[solid, { ...solidOptions, ...(options.solid || {}) }]],\n plugins: needHmr && !isSsr && !inNodeModules ? [[solidRefresh, { bundler: 'vite' }]] : [],\n sourceMaps: true,\n // Vite handles sourcemap flattening\n inputSourceMap: false as any,\n };\n\n // We need to know if the current file extension has a typescript options tied to it\n const shouldBeProcessedWithTypescript = extensionsToWatch.some((extension) => {\n if (typeof extension === 'string') {\n return extension.includes('tsx');\n }\n\n const [extensionName, extensionOptions] = extension;\n if (extensionName !== currentFileExtension) return false;\n\n return extensionOptions.typescript;\n });\n\n if (shouldBeProcessedWithTypescript) {\n opts.presets.push([ts, options.typescript || {}]);\n }\n\n // Default value for babel user options\n let babelUserOptions: TransformOptions = {};\n\n if (options.babel) {\n if (typeof options.babel === 'function') {\n const babelOptions = options.babel(source, id, isSsr);\n babelUserOptions = babelOptions instanceof Promise ? await babelOptions : babelOptions;\n } else {\n babelUserOptions = options.babel;\n }\n }\n\n const babelOptions = mergeAndConcat(babelUserOptions, opts) as TransformOptions;\n\n const { code, map } = await transformAsync(source, babelOptions);\n\n return { code, map };\n },\n };\n}\n\n/**\n * This basically normalize all aliases of the config into\n * the array format of the alias.\n *\n * eg: alias: { '@': 'src/' } => [{ find: '@', replacement: 'src/' }]\n */\nfunction normalizeAliases(alias: AliasOptions = []): Alias[] {\n return Array.isArray(alias)\n ? alias\n : Object.entries(alias).map(([find, replacement]) => ({ find, replacement }));\n}\n"],"names":["require","createRequire","import","meta","url","runtimePublicPath","runtimeFilePath","resolve","runtimeCode","readFileSync","getExtension","filename","index","lastIndexOf","substring","solidPlugin","options","needHmr","replaceDev","projectRoot","process","cwd","name","enforce","config","userConfig","command","dev","root","legacyAlias","normalizeAliases","alias","nestedDeps","esbuild","include","conditions","dedupe","find","replacement","optimizeDeps","configResolved","isProduction","hot","resolveId","id","load","transform","source","transformOptions","isSsr","ssr","currentFileExtension","extensionsToWatch","extensions","allExtensions","map","extension","includes","inNodeModules","test","solidOptions","generate","hydratable","opts","babelrc","configFile","sourceFileName","presets","solid","plugins","solidRefresh","bundler","sourceMaps","inputSourceMap","shouldBeProcessedWithTypescript","some","extensionName","extensionOptions","typescript","push","ts","babelUserOptions","babel","babelOptions","Promise","mergeAndConcat","code","transformAsync","Array","isArray","Object","entries"],"mappings":";;;;;;;;AASA,MAAMA,OAAO,GAAGC,aAAa,CAACC,MAAM,CAACC,IAAP,CAAYC,GAAb,CAA7B;;AAEA,MAAMC,iBAAiB,GAAG,iBAA1B;;AACA,MAAMC,eAAe,GAAGN,OAAO,CAACO,OAAR,CAAgB,sCAAhB,CAAxB;;AACA,MAAMC,WAAW,GAAGC,YAAY,CAACH,eAAD,EAAkB,OAAlB,CAAhC;AAEA;;AAqOA,SAASI,YAAT,CAAsBC,QAAtB,EAAgD;AAC9C,QAAMC,KAAK,GAAGD,QAAQ,CAACE,WAAT,CAAqB,GAArB,CAAd;AACA,SAAOD,KAAK,GAAG,CAAR,GAAY,EAAZ,GAAiBD,QAAQ,CAACG,SAAT,CAAmBF,KAAnB,CAAxB;AACD;;AAEc,SAASG,WAAT,CAAqBC,OAAyB,GAAG,EAAjD,EAA6D;AAC1E,MAAIC,OAAO,GAAG,KAAd;AACA,MAAIC,UAAU,GAAG,KAAjB;AACA,MAAIC,WAAW,GAAGC,OAAO,CAACC,GAAR,EAAlB;AAEA,SAAO;AACLC,IAAAA,IAAI,EAAE,OADD;AAELC,IAAAA,OAAO,EAAE,KAFJ;;AAILC,IAAAA,MAAM,CAACC,UAAD,EAAa;AAAEC,MAAAA;AAAF,KAAb,EAAsC;AAAA;;AAC1C;AACAR,MAAAA,UAAU,GAAGF,OAAO,CAACW,GAAR,KAAgB,IAAhB,IAAyB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AAEA,UAAIjE,OAAO,CAACkE,KAAZ,EAAmB;AACjB,YAAI,OAAOlE,OAAO,CAACkE,KAAf,KAAyB,UAA7B,EAAyC;AACvC,gBAAMC,YAAY,GAAGnE,OAAO,CAACkE,KAAR,CAAcnC,MAAd,EAAsBH,EAAtB,EAA0BK,KAA1B,CAArB;AACAgC,UAAAA,gBAAgB,GAAGE,YAAY,YAAYC,OAAxB,GAAkC,MAAMD,YAAxC,GAAuDA,YAA1E;AACD,SAHD,MAGO;AACLF,UAAAA,gBAAgB,GAAGjE,OAAO,CAACkE,KAA3B;AACD;AACF;;AAED,YAAMC,YAAY,GAAGE,cAAc,CAACJ,gBAAD,EAAmBlB,IAAnB,CAAnC;AAEA,YAAM;AAAEuB,QAAAA,IAAF;AAAQ/B,QAAAA;AAAR,UAAgB,MAAMgC,cAAc,CAACxC,MAAD,EAASoC,YAAT,CAA1C;AAEA,aAAO;AAAEG,QAAAA,IAAF;AAAQ/B,QAAAA;AAAR,OAAP;AACD;;AA3HI,GAAP;AA6HD;AAED;AACA;AACA;AACA;AACA;AACA;;AACA,SAASzB,gBAAT,CAA0BC,KAAmB,GAAG,EAAhD,EAA6D;AAC3D,SAAOyD,KAAK,CAACC,OAAN,CAAc1D,KAAd,IACHA,KADG,GAEH2D,MAAM,CAACC,OAAP,CAAe5D,KAAf,EAAsBwB,GAAtB,CAA0B,CAAC,CAAClB,IAAD,EAAOC,WAAP,CAAD,MAA0B;AAAED,IAAAA,IAAF;AAAQC,IAAAA;AAAR,GAA1B,CAA1B,CAFJ;AAGD;;;;"}
@@ -1,203 +1,214 @@
1
- import { TransformOptions } from '@babel/core';
2
- import type { Plugin } from 'vite';
3
- /** Configuration options for vite-plugin-solid. */
4
- export interface Options {
5
- /**
6
- * This will inject solid-js/dev in place of solid-js in dev mode. Has no
7
- * effect in prod. If set to `false`, it won't inject it in dev. This is
8
- * useful for extra logs and debugging.
9
- *
10
- * @default true
11
- */
12
- dev: boolean;
13
- /**
14
- * This will force SSR code in the produced files. This is experiemental
15
- * and mostly not working yet.
16
- *
17
- * @default false
18
- */
19
- ssr: boolean;
20
- /**
21
- * This will inject HMR runtime in dev mode. Has no effect in prod. If
22
- * set to `false`, it won't inject the runtime in dev.
23
- *
24
- * @default true
25
- */
26
- hot: boolean;
27
- /**
28
- * Pass any additional babel transform options. They will be merged with
29
- * the transformations required by Solid.
30
- *
31
- * @default {}
32
- */
33
- babel: TransformOptions | ((source: string, id: string, ssr: boolean) => TransformOptions) | ((source: string, id: string, ssr: boolean) => Promise<TransformOptions>);
34
- typescript: {
35
- /**
36
- * Forcibly enables jsx parsing. Otherwise angle brackets will be treated as
37
- * typescript's legacy type assertion var foo = <string>bar;. Also, isTSX:
38
- * true requires allExtensions: true.
39
- *
40
- * @default false
41
- */
42
- isTSX?: boolean;
43
- /**
44
- * Replace the function used when compiling JSX expressions. This is so that
45
- * we know that the import is not a type import, and should not be removed.
46
- *
47
- * @default React
48
- */
49
- jsxPragma?: string;
50
- /**
51
- * Replace the function used when compiling JSX fragment expressions. This
52
- * is so that we know that the import is not a type import, and should not
53
- * be removed.
54
- *
55
- * @default React.Fragment
56
- */
57
- jsxPragmaFrag?: string;
58
- /**
59
- * Indicates that every file should be parsed as TS or TSX (depending on the
60
- * isTSX option).
61
- *
62
- * @default false
63
- */
64
- allExtensions?: boolean;
65
- /**
66
- * Enables compilation of TypeScript namespaces.
67
- *
68
- * @default uses the default set by @babel/plugin-transform-typescript.
69
- */
70
- allowNamespaces?: boolean;
71
- /**
72
- * When enabled, type-only class fields are only removed if they are
73
- * prefixed with the declare modifier:
74
- *
75
- * > NOTE: This will be enabled by default in Babel 8
76
- *
77
- * @default false
78
- *
79
- * @example
80
- * ```ts
81
- * class A {
82
- * declare foo: string; // Removed
83
- * bar: string; // Initialized to undefined
84
- * prop?: string; // Initialized to undefined
85
- * prop1!: string // Initialized to undefined
86
- * }
87
- * ```
88
- */
89
- allowDeclareFields?: boolean;
90
- /**
91
- * When set to true, the transform will only remove type-only imports
92
- * (introduced in TypeScript 3.8). This should only be used if you are using
93
- * TypeScript >= 3.8.
94
- *
95
- * @default false
96
- */
97
- onlyRemoveTypeImports?: boolean;
98
- /**
99
- * When set to true, Babel will inline enum values rather than using the
100
- * usual enum output:
101
- *
102
- * This option differs from TypeScript's --isolatedModules behavior, which
103
- * ignores the const modifier and compiles them as normal enums, and aligns
104
- * Babel's behavior with TypeScript's default behavior.
105
- *
106
- * ```ts
107
- * // Input
108
- * const enum Animals {
109
- * Fish
110
- * }
111
- * console.log(Animals.Fish);
112
- *
113
- * // Default output
114
- * var Animals;
115
- *
116
- * (function (Animals) {
117
- * Animals[Animals["Fish"] = 0] = "Fish";
118
- * })(Animals || (Animals = {}));
119
- *
120
- * console.log(Animals.Fish);
121
- *
122
- * // `optimizeConstEnums` output
123
- * console.log(0);
124
- * ```
125
- *
126
- * However, when exporting a const enum Babel will compile it to a plain
127
- * object literal so that it doesn't need to rely on cross-file analysis
128
- * when compiling it:
129
- *
130
- * ```ts
131
- * // Input
132
- * export const enum Animals {
133
- * Fish,
134
- * }
135
- *
136
- * // `optimizeConstEnums` output
137
- * export var Animals = {
138
- * Fish: 0,
139
- * };
140
- * ```
141
- *
142
- * @default false
143
- */
144
- optimizeConstEnums?: boolean;
145
- };
146
- /**
147
- * Pass any additional [babel-plugin-jsx-dom-expressions](https://github.com/ryansolid/dom-expressions/tree/main/packages/babel-plugin-jsx-dom-expressions#plugin-options).
148
- * 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).
149
- *
150
- * @default {}
151
- */
152
- solid: {
153
- /**
154
- * The name of the runtime module to import the methods from.
155
- *
156
- * @default "solid-js/web"
157
- */
158
- moduleName?: string;
159
- /**
160
- * The output mode of the compiler.
161
- * Can be:
162
- * - "dom" is standard output
163
- * - "ssr" is for server side rendering of strings.
164
- *
165
- * @default "dom"
166
- */
167
- generate?: 'ssr' | 'dom';
168
- /**
169
- * Indicate whether the output should contain hydratable markers.
170
- *
171
- * @default false
172
- */
173
- hydratable?: boolean;
174
- /**
175
- * Boolean to indicate whether to enable automatic event delegation on camelCase.
176
- *
177
- * @default true
178
- */
179
- delegateEvents?: boolean;
180
- /**
181
- * Boolean indicates whether smart conditional detection should be used.
182
- * This optimizes simple boolean expressions and ternaries in JSX.
183
- *
184
- * @default true
185
- */
186
- wrapConditionals?: boolean;
187
- /**
188
- * Boolean indicates whether to set current render context on Custom Elements and slots.
189
- * Useful for seemless Context API with Web Components.
190
- *
191
- * @default true
192
- */
193
- contextToCustomElements?: boolean;
194
- /**
195
- * Array of Component exports from module, that aren't included by default with the library.
196
- * This plugin will automatically import them if it comes across them in the JSX.
197
- *
198
- * @default ["For","Show","Switch","Match","Suspense","SuspenseList","Portal","Index","Dynamic","ErrorBoundary"]
199
- */
200
- builtIns?: string[];
201
- };
202
- }
203
- export default function solidPlugin(options?: Partial<Options>): Plugin;
1
+ import { TransformOptions } from '@babel/core';
2
+ import type { Plugin } from 'vite';
3
+ /** Possible options for the extensions property */
4
+ export interface ExtensionOptions {
5
+ typescript?: boolean;
6
+ }
7
+ /** Configuration options for vite-plugin-solid. */
8
+ export interface Options {
9
+ /**
10
+ * This will inject solid-js/dev in place of solid-js in dev mode. Has no
11
+ * effect in prod. If set to `false`, it won't inject it in dev. This is
12
+ * useful for extra logs and debugging.
13
+ *
14
+ * @default true
15
+ */
16
+ dev: boolean;
17
+ /**
18
+ * This will force SSR code in the produced files. This is experiemental
19
+ * and mostly not working yet.
20
+ *
21
+ * @default false
22
+ */
23
+ ssr: boolean;
24
+ /**
25
+ * This will inject HMR runtime in dev mode. Has no effect in prod. If
26
+ * set to `false`, it won't inject the runtime in dev.
27
+ *
28
+ * @default true
29
+ */
30
+ hot: boolean;
31
+ /**
32
+ * This registers additional extensions that should be processed by
33
+ * vite-plugin-solid.
34
+ *
35
+ * @default undefined
36
+ */
37
+ extensions?: (string | [string, ExtensionOptions])[];
38
+ /**
39
+ * Pass any additional babel transform options. They will be merged with
40
+ * the transformations required by Solid.
41
+ *
42
+ * @default {}
43
+ */
44
+ babel: TransformOptions | ((source: string, id: string, ssr: boolean) => TransformOptions) | ((source: string, id: string, ssr: boolean) => Promise<TransformOptions>);
45
+ typescript: {
46
+ /**
47
+ * Forcibly enables jsx parsing. Otherwise angle brackets will be treated as
48
+ * typescript's legacy type assertion var foo = <string>bar;. Also, isTSX:
49
+ * true requires allExtensions: true.
50
+ *
51
+ * @default false
52
+ */
53
+ isTSX?: boolean;
54
+ /**
55
+ * Replace the function used when compiling JSX expressions. This is so that
56
+ * we know that the import is not a type import, and should not be removed.
57
+ *
58
+ * @default React
59
+ */
60
+ jsxPragma?: string;
61
+ /**
62
+ * Replace the function used when compiling JSX fragment expressions. This
63
+ * is so that we know that the import is not a type import, and should not
64
+ * be removed.
65
+ *
66
+ * @default React.Fragment
67
+ */
68
+ jsxPragmaFrag?: string;
69
+ /**
70
+ * Indicates that every file should be parsed as TS or TSX (depending on the
71
+ * isTSX option).
72
+ *
73
+ * @default false
74
+ */
75
+ allExtensions?: boolean;
76
+ /**
77
+ * Enables compilation of TypeScript namespaces.
78
+ *
79
+ * @default uses the default set by @babel/plugin-transform-typescript.
80
+ */
81
+ allowNamespaces?: boolean;
82
+ /**
83
+ * When enabled, type-only class fields are only removed if they are
84
+ * prefixed with the declare modifier:
85
+ *
86
+ * > NOTE: This will be enabled by default in Babel 8
87
+ *
88
+ * @default false
89
+ *
90
+ * @example
91
+ * ```ts
92
+ * class A {
93
+ * declare foo: string; // Removed
94
+ * bar: string; // Initialized to undefined
95
+ * prop?: string; // Initialized to undefined
96
+ * prop1!: string // Initialized to undefined
97
+ * }
98
+ * ```
99
+ */
100
+ allowDeclareFields?: boolean;
101
+ /**
102
+ * When set to true, the transform will only remove type-only imports
103
+ * (introduced in TypeScript 3.8). This should only be used if you are using
104
+ * TypeScript >= 3.8.
105
+ *
106
+ * @default false
107
+ */
108
+ onlyRemoveTypeImports?: boolean;
109
+ /**
110
+ * When set to true, Babel will inline enum values rather than using the
111
+ * usual enum output:
112
+ *
113
+ * This option differs from TypeScript's --isolatedModules behavior, which
114
+ * ignores the const modifier and compiles them as normal enums, and aligns
115
+ * Babel's behavior with TypeScript's default behavior.
116
+ *
117
+ * ```ts
118
+ * // Input
119
+ * const enum Animals {
120
+ * Fish
121
+ * }
122
+ * console.log(Animals.Fish);
123
+ *
124
+ * // Default output
125
+ * var Animals;
126
+ *
127
+ * (function (Animals) {
128
+ * Animals[Animals["Fish"] = 0] = "Fish";
129
+ * })(Animals || (Animals = {}));
130
+ *
131
+ * console.log(Animals.Fish);
132
+ *
133
+ * // `optimizeConstEnums` output
134
+ * console.log(0);
135
+ * ```
136
+ *
137
+ * However, when exporting a const enum Babel will compile it to a plain
138
+ * object literal so that it doesn't need to rely on cross-file analysis
139
+ * when compiling it:
140
+ *
141
+ * ```ts
142
+ * // Input
143
+ * export const enum Animals {
144
+ * Fish,
145
+ * }
146
+ *
147
+ * // `optimizeConstEnums` output
148
+ * export var Animals = {
149
+ * Fish: 0,
150
+ * };
151
+ * ```
152
+ *
153
+ * @default false
154
+ */
155
+ optimizeConstEnums?: boolean;
156
+ };
157
+ /**
158
+ * Pass any additional [babel-plugin-jsx-dom-expressions](https://github.com/ryansolid/dom-expressions/tree/main/packages/babel-plugin-jsx-dom-expressions#plugin-options).
159
+ * 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).
160
+ *
161
+ * @default {}
162
+ */
163
+ solid: {
164
+ /**
165
+ * The name of the runtime module to import the methods from.
166
+ *
167
+ * @default "solid-js/web"
168
+ */
169
+ moduleName?: string;
170
+ /**
171
+ * The output mode of the compiler.
172
+ * Can be:
173
+ * - "dom" is standard output
174
+ * - "ssr" is for server side rendering of strings.
175
+ *
176
+ * @default "dom"
177
+ */
178
+ generate?: 'ssr' | 'dom';
179
+ /**
180
+ * Indicate whether the output should contain hydratable markers.
181
+ *
182
+ * @default false
183
+ */
184
+ hydratable?: boolean;
185
+ /**
186
+ * Boolean to indicate whether to enable automatic event delegation on camelCase.
187
+ *
188
+ * @default true
189
+ */
190
+ delegateEvents?: boolean;
191
+ /**
192
+ * Boolean indicates whether smart conditional detection should be used.
193
+ * This optimizes simple boolean expressions and ternaries in JSX.
194
+ *
195
+ * @default true
196
+ */
197
+ wrapConditionals?: boolean;
198
+ /**
199
+ * Boolean indicates whether to set current render context on Custom Elements and slots.
200
+ * Useful for seemless Context API with Web Components.
201
+ *
202
+ * @default true
203
+ */
204
+ contextToCustomElements?: boolean;
205
+ /**
206
+ * Array of Component exports from module, that aren't included by default with the library.
207
+ * This plugin will automatically import them if it comes across them in the JSX.
208
+ *
209
+ * @default ["For","Show","Switch","Match","Suspense","SuspenseList","Portal","Index","Dynamic","ErrorBoundary"]
210
+ */
211
+ builtIns?: string[];
212
+ };
213
+ }
214
+ export default function solidPlugin(options?: Partial<Options>): Plugin;