vite-plugin-solid 2.1.4 → 2.2.0

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.
package/README.md CHANGED
@@ -1,3 +1,7 @@
1
+ <p>
2
+ <img width="100%" src="https://raw.githubusercontent.com/solidjs/vite-plugin-solid/master/banner.png" alt="Solid Vite Plugin">
3
+ </p>
4
+
1
5
  # ⚡ vite-plugin-solid
2
6
 
3
7
  A simple integration to run [solid-js](https://github.com/solidjs/solid) with [vite](https://github.com/vitejs/vite)
@@ -21,7 +21,12 @@ const runtimePublicPath = '/@solid-refresh';
21
21
  const runtimeFilePath = require$1.resolve('solid-refresh/dist/solid-refresh.mjs');
22
22
 
23
23
  const runtimeCode = fs.readFileSync(runtimeFilePath, 'utf-8');
24
- /** Configuration options for vite-plugin-solid. */
24
+ /** Possible options for the extensions property */
25
+
26
+ function getExtension(filename) {
27
+ const index = filename.lastIndexOf('.');
28
+ return index < 0 ? '' : filename.substring(index);
29
+ }
25
30
 
26
31
  function solidPlugin(options = {}) {
27
32
  let needHmr = false;
@@ -34,15 +39,13 @@ function solidPlugin(options = {}) {
34
39
  config(userConfig, {
35
40
  command
36
41
  }) {
37
- var _userConfig$resolve;
38
-
39
42
  // We inject the dev mode only if the user explicitely wants it or if we are in dev (serve) mode
40
43
  replaceDev = options.dev === true || options.dev !== false && command === 'serve';
41
44
  projectRoot = userConfig.root; // TODO: remove when fully removed from vite
42
45
 
43
46
  const legacyAlias = normalizeAliases(userConfig.alias);
44
47
  if (!userConfig.resolve) userConfig.resolve = {};
45
- 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
48
+ userConfig.resolve.alias = [...legacyAlias, ...normalizeAliases(userConfig.resolve?.alias)]; // fix for bundling dev in production
46
49
 
47
50
  const nestedDeps = replaceDev ? ['solid-js', 'solid-js/web', 'solid-js/store', 'solid-js/html', 'solid-js/h'] : [];
48
51
  return {
@@ -80,15 +83,21 @@ function solidPlugin(options = {}) {
80
83
  },
81
84
 
82
85
  async transform(source, id, transformOptions) {
83
- // @ts-expect-error anticipate vite changing second parameter as options object
84
- // see https://github.com/vitejs/vite/discussions/5109
85
- const ssr = transformOptions === true || (transformOptions === null || transformOptions === void 0 ? void 0 : transformOptions.ssr);
86
- if (!/\.[jt]sx/.test(id)) return null;
86
+ const isSsr = transformOptions?.ssr;
87
+ const currentFileExtension = getExtension(id);
88
+ const extensionsToWatch = [...(options.extensions || []), '.tsx', '.jsx'];
89
+ const allCustomExtensions = extensionsToWatch.map(extension => // An extension can be a string or a tuple [extension, options]
90
+ typeof extension === 'string' ? extension : extension[0]);
91
+
92
+ if (!allCustomExtensions.includes(currentFileExtension)) {
93
+ return null;
94
+ }
95
+
87
96
  const inNodeModules = /node_modules/.test(id);
88
97
  let solidOptions;
89
98
 
90
99
  if (options.ssr) {
91
- if (ssr) {
100
+ if (isSsr) {
92
101
  solidOptions = {
93
102
  generate: 'ssr',
94
103
  hydratable: true
@@ -121,9 +130,19 @@ function solidPlugin(options = {}) {
121
130
  sourceMaps: true,
122
131
  // Vite handles sourcemap flattening
123
132
  inputSourceMap: false
124
- };
133
+ }; // We need to know if the current file extension has a typescript options tied to it
134
+
135
+ const shouldBeProcessedWithTypescript = extensionsToWatch.some(extension => {
136
+ if (typeof extension === 'string') {
137
+ return extension.includes('tsx');
138
+ }
139
+
140
+ const [extensionName, extensionOptions] = extension;
141
+ if (extensionName !== currentFileExtension) return false;
142
+ return extensionOptions.typescript;
143
+ });
125
144
 
126
- if (id.includes('tsx')) {
145
+ if (shouldBeProcessedWithTypescript) {
127
146
  opts.presets.push([ts__default["default"], options.typescript || {}]);
128
147
  } // Default value for babel user options
129
148
 
@@ -132,7 +151,7 @@ function solidPlugin(options = {}) {
132
151
 
133
152
  if (options.babel) {
134
153
  if (typeof options.babel === 'function') {
135
- const babelOptions = options.babel(source, id, ssr);
154
+ const babelOptions = options.babel(source, id, isSsr);
136
155
  babelUserOptions = babelOptions instanceof Promise ? await babelOptions : babelOptions;
137
156
  } else {
138
157
  babelUserOptions = options.babel;
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","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/** 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 * 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\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',\n 'solid-js/web',\n 'solid-js/store',\n 'solid-js/html',\n '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 // @ts-expect-error anticipate vite changing second parameter as options object\n // see https://github.com/vitejs/vite/discussions/5109\n const ssr: boolean = transformOptions === true || transformOptions?.ssr;\n\n if (!/\\.[jt]sx/.test(id)) return null;\n const inNodeModules = /node_modules/.test(id);\n\n let solidOptions: { generate: 'ssr' | 'dom'; hydratable: boolean };\n\n if (options.ssr) {\n if (ssr) {\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 && !inNodeModules ? [[solidRefresh, { bundler: 'vite' }]] : [],\n sourceMaps: true,\n // Vite handles sourcemap flattening\n inputSourceMap: false as any,\n };\n\n if (id.includes('tsx')) {\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, ssr);\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","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","inNodeModules","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,SAAO,GAAGC,sBAAa,CAACC,oMAAD,CAA7B;;AAEA,MAAMC,iBAAiB,GAAG,iBAA1B;;AACA,MAAMC,eAAe,GAAGJ,SAAO,CAACK,OAAR,CAAgB,sCAAhB,CAAxB;;AACA,MAAMC,WAAW,GAAGC,eAAY,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,EAAl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,EAAmBhB,IAAnB,CAAnC;AAEA,YAAM;AAAEqB,QAAAA,IAAF;AAAQC,QAAAA;AAAR,UAAgB,MAAMC,mBAAc,CAAC/B,MAAD,EAAS0B,YAAT,CAA1C;AAEA,aAAO;AAAEG,QAAAA,IAAF;AAAQC,QAAAA;AAAR,OAAP;AACD;;AA3GI,GAAP;AA6GD;AAED;AACA;AACA;AACA;AACA;AACA;;AACA,SAAS/C,gBAAT,CAA0BC,KAAmB,GAAG,EAAhD,EAA6D;AAC3D,SAAOgD,KAAK,CAACC,OAAN,CAAcjD,KAAd,IACHA,KADG,GAEHkD,MAAM,CAACC,OAAP,CAAenD,KAAf,EAAsB8C,GAAtB,CAA0B,CAAC,CAACxC,IAAD,EAAOC,WAAP,CAAD,MAA0B;AAAED,IAAAA,IAAF;AAAQC,IAAAA;AAAR,GAA1B,CAA1B,CAFJ;AAGD;;;;"}
1
+ {"version":3,"file":"index.cjs","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 allCustomExtensions = 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 (!allCustomExtensions.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 && !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","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","allCustomExtensions","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,SAAO,GAAGC,sBAAa,CAACC,oMAAD,CAA7B;;AAEA,MAAMC,iBAAiB,GAAG,iBAA1B;;AACA,MAAMC,eAAe,GAAGJ,SAAO,CAACK,OAAR,CAAgB,sCAAhB,CAAxB;;AACA,MAAMC,WAAW,GAAGC,eAAY,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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AAI,CAACI,OAAL,CAAaY,IAAb,CAAkB,CAACC,sBAAD,EAAKhE,OAAO,CAAC8D,UAAR,IAAsB,EAA3B,CAAlB;AACD,OAvD2C;;;AA0D5C,UAAIG,gBAAkC,GAAG,EAAzC;;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,4BAAc,CAACJ,gBAAD,EAAmBlB,IAAnB,CAAnC;AAEA,YAAM;AAAEuB,QAAAA,IAAF;AAAQ/B,QAAAA;AAAR,UAAgB,MAAMgC,mBAAc,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;;;;"}
@@ -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;
@@ -26,15 +31,13 @@ function solidPlugin(options = {}) {
26
31
  config(userConfig, {
27
32
  command
28
33
  }) {
29
- var _userConfig$resolve;
30
-
31
34
  // We inject the dev mode only if the user explicitely wants it or if we are in dev (serve) mode
32
35
  replaceDev = options.dev === true || options.dev !== false && command === 'serve';
33
36
  projectRoot = userConfig.root; // TODO: remove when fully removed from vite
34
37
 
35
38
  const legacyAlias = normalizeAliases(userConfig.alias);
36
39
  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)]; // fix for bundling dev in production
40
+ userConfig.resolve.alias = [...legacyAlias, ...normalizeAliases(userConfig.resolve?.alias)]; // fix for bundling dev in production
38
41
 
39
42
  const nestedDeps = replaceDev ? ['solid-js', 'solid-js/web', 'solid-js/store', 'solid-js/html', 'solid-js/h'] : [];
40
43
  return {
@@ -72,15 +75,21 @@ function solidPlugin(options = {}) {
72
75
  },
73
76
 
74
77
  async transform(source, id, transformOptions) {
75
- // @ts-expect-error anticipate vite changing second parameter as options object
76
- // see https://github.com/vitejs/vite/discussions/5109
77
- const ssr = transformOptions === true || (transformOptions === null || transformOptions === void 0 ? void 0 : transformOptions.ssr);
78
- if (!/\.[jt]sx/.test(id)) return null;
78
+ const isSsr = transformOptions?.ssr;
79
+ const currentFileExtension = getExtension(id);
80
+ const extensionsToWatch = [...(options.extensions || []), '.tsx', '.jsx'];
81
+ const allCustomExtensions = extensionsToWatch.map(extension => // An extension can be a string or a tuple [extension, options]
82
+ typeof extension === 'string' ? extension : extension[0]);
83
+
84
+ if (!allCustomExtensions.includes(currentFileExtension)) {
85
+ return null;
86
+ }
87
+
79
88
  const inNodeModules = /node_modules/.test(id);
80
89
  let solidOptions;
81
90
 
82
91
  if (options.ssr) {
83
- if (ssr) {
92
+ if (isSsr) {
84
93
  solidOptions = {
85
94
  generate: 'ssr',
86
95
  hydratable: true
@@ -113,9 +122,19 @@ function solidPlugin(options = {}) {
113
122
  sourceMaps: true,
114
123
  // Vite handles sourcemap flattening
115
124
  inputSourceMap: false
116
- };
125
+ }; // We need to know if the current file extension has a typescript options tied to it
126
+
127
+ const shouldBeProcessedWithTypescript = extensionsToWatch.some(extension => {
128
+ if (typeof extension === 'string') {
129
+ return extension.includes('tsx');
130
+ }
131
+
132
+ const [extensionName, extensionOptions] = extension;
133
+ if (extensionName !== currentFileExtension) return false;
134
+ return extensionOptions.typescript;
135
+ });
117
136
 
118
- if (id.includes('tsx')) {
137
+ if (shouldBeProcessedWithTypescript) {
119
138
  opts.presets.push([ts, options.typescript || {}]);
120
139
  } // Default value for babel user options
121
140
 
@@ -124,7 +143,7 @@ function solidPlugin(options = {}) {
124
143
 
125
144
  if (options.babel) {
126
145
  if (typeof options.babel === 'function') {
127
- const babelOptions = options.babel(source, id, ssr);
146
+ const babelOptions = options.babel(source, id, isSsr);
128
147
  babelUserOptions = babelOptions instanceof Promise ? await babelOptions : babelOptions;
129
148
  } else {
130
149
  babelUserOptions = options.babel;
@@ -1 +1 @@
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/** 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 * 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\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',\n 'solid-js/web',\n 'solid-js/store',\n 'solid-js/html',\n '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 // @ts-expect-error anticipate vite changing second parameter as options object\n // see https://github.com/vitejs/vite/discussions/5109\n const ssr: boolean = transformOptions === true || transformOptions?.ssr;\n\n if (!/\\.[jt]sx/.test(id)) return null;\n const inNodeModules = /node_modules/.test(id);\n\n let solidOptions: { generate: 'ssr' | 'dom'; hydratable: boolean };\n\n if (options.ssr) {\n if (ssr) {\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 && !inNodeModules ? [[solidRefresh, { bundler: 'vite' }]] : [],\n sourceMaps: true,\n // Vite handles sourcemap flattening\n inputSourceMap: false as any,\n };\n\n if (id.includes('tsx')) {\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, ssr);\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","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","inNodeModules","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,CAACC,UAAD,EAAa;AAAEC,MAAAA;AAAF,KAAb,EAAsC;AAAA;;AAC1C;AACAR,MAAAA,UAAU,GAAGF,OAAO,CAACW,GAAR,KAAgB,IAAhB,IAAyBX,OAAO,CAACW,GAAR,KAAgB,KAAhB,IAAyBD,OAAO,KAAK,OAA3E;AACAP,MAAAA,WAAW,GAAGM,UAAU,CAACG,IAAzB,CAH0C;;AAM1C,YAAMC,WAAW,GAAGC,gBAAgB,CAACL,UAAU,CAACM,KAAZ,CAApC;AAEA,UAAI,CAACN,UAAU,CAAC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AAD,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 allCustomExtensions = 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 (!allCustomExtensions.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 && !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","allCustomExtensions","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;AAC1C;AACAR,MAAAA,UAAU,GAAGF,OAAO,CAACW,GAAR,KAAgB,IAAhB,IAAyBX,OAAO,CAACW,GAAR,KAAgB,KAAhB,IAAyBD,OAAO,KAAK,OAA3E;AACAP,MAAAA,WAAW,GAAGM,UAAU,CAACG,IAAzB,CAH0C;;AAM1C,YAAMC,WAAW,GAAGC,gBAAgB,CAACL,UAAU,CAACM,KAAZ,CAApC;AAEA,UAAI,CAACN,UAAU,CAAClB,OAAh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AAuDA,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,5 +1,9 @@
1
1
  import { TransformOptions } from '@babel/core';
2
2
  import type { Plugin } from 'vite';
3
+ /** Possible options for the extensions property */
4
+ export interface ExtensionOptions {
5
+ typescript?: boolean;
6
+ }
3
7
  /** Configuration options for vite-plugin-solid. */
4
8
  export interface Options {
5
9
  /**
@@ -24,6 +28,13 @@ export interface Options {
24
28
  * @default true
25
29
  */
26
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])[];
27
38
  /**
28
39
  * Pass any additional babel transform options. They will be merged with
29
40
  * the transformations required by Solid.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-solid",
3
- "version": "2.1.4",
3
+ "version": "2.2.0",
4
4
  "description": "solid-js integration plugin for vite 2",
5
5
  "type": "module",
6
6
  "files": [
@@ -15,12 +15,6 @@
15
15
  "require": "./dist/cjs/index.cjs"
16
16
  },
17
17
  "types": "dist/types/index.d.ts",
18
- "scripts": {
19
- "build": "rollup -c && tsc --emitDeclarationOnly",
20
- "dev": "rollup -c -w",
21
- "prepublishOnly": "pnpm build",
22
- "check": "package-check"
23
- },
24
18
  "repository": {
25
19
  "type": "git",
26
20
  "url": "git+https://github.com/solidjs/vite-plugin-solid.git"
@@ -40,26 +34,33 @@
40
34
  },
41
35
  "homepage": "https://github.com/solidjs/vite-plugin-solid#readme",
42
36
  "dependencies": {
43
- "@babel/core": "^7.16.0",
44
- "@babel/preset-typescript": "^7.16.0",
37
+ "@babel/core": "^7.16.7",
38
+ "@babel/preset-typescript": "^7.16.7",
45
39
  "babel-preset-solid": "^1.2.6",
46
- "merge-anything": "^4.0.1",
40
+ "merge-anything": "^4.0.2",
47
41
  "solid-js": "^1.2.6",
48
42
  "solid-refresh": "^0.3.2",
49
- "vite": "^2.7.1"
43
+ "vite": "^2.7.10"
50
44
  },
51
45
  "devDependencies": {
52
- "@babel/plugin-transform-typescript": "^7.16.1",
53
- "@babel/preset-env": "^7.16.0",
46
+ "@babel/plugin-transform-typescript": "^7.16.7",
47
+ "@babel/preset-env": "^7.16.7",
54
48
  "@rollup/plugin-babel": "^5.3.0",
55
49
  "@rollup/plugin-commonjs": "^21.0.1",
56
- "@rollup/plugin-node-resolve": "^13.0.6",
50
+ "@rollup/plugin-node-resolve": "^13.1.2",
57
51
  "@skypack/package-check": "^0.2.2",
58
- "@types/babel__core": "^7.1.16",
59
- "@types/node": "^16.11.6",
60
- "prettier": "^2.4.1",
61
- "rollup": "^2.59.0",
52
+ "@types/babel__core": "^7.1.18",
53
+ "@types/node": "^17.0.7",
54
+ "prettier": "^2.5.1",
55
+ "rollup": "^2.62.0",
62
56
  "rollup-plugin-cleaner": "^1.0.0",
63
- "typescript": "^4.4.4"
64
- }
65
- }
57
+ "typescript": "^4.5.4"
58
+ },
59
+ "packageManager": "pnpm@6.24.4",
60
+ "scripts": {
61
+ "build": "rollup -c && tsc --emitDeclarationOnly",
62
+ "dev": "rollup -c -w",
63
+ "check": "package-check"
64
+ },
65
+ "readme": "<p>\n <img width=\"100%\" src=\"https://raw.githubusercontent.com/solidjs/vite-plugin-solid/master/banner.png\" alt=\"Solid Vite Plugin\">\n</p>\n\n# ⚡ vite-plugin-solid\n\nA simple integration to run [solid-js](https://github.com/solidjs/solid) with [vite](https://github.com/vitejs/vite)\n\n<img alt=\"HMR gif demonstrationdemodemodemo\" src=\".github/hmr.gif\">\n\n# Got a question? / Need help?\n\nJoin [solid discord](https://discord.com/invite/solidjs) and check the [troubleshooting section](#troubleshooting) to see if your question hasn't been already answered.\n\n## Features\n\n- HMR with no configuration needed\n- Drop-in installation as a vite plugin\n- Minimal bundle size\n- Support typescript (`.tsx`) out of the box\n- Support code splitting out of the box\n\n## Requirements\n\nThis module 100% esm compatible. As per [this document](https://nodejs.org/api/esm.html) it is strongly recommended to have at least the version `14.13.0` of node installed.\n\nYou can check your current version of node by typing `node -v` in your terminal. If your version is below that one version I'd encourage you to either do an update globally or use a node version management tool such as [volta](https://volta.sh/) or [nvm](https://github.com/nvm-sh/nvm).\n\n## Quickstart\n\nYou can use the [vite-template-solid](https://github.com/solidjs/templates) starter templates similar to CRA:\n\n```bash\n$ npx degit solidjs/templates/js my-solid-project\n$ cd my-solid-project\n$ npm install # or pnpm install or yarn install\n$ npm run start # starts dev-server with hot-module-reloading\n$ npm run build # builds to /dist\n```\n\n## Installation\n\nInstall `vite`, `vite-plugin-solid` and `babel-preset-solid` as dev dependencies.\n\nInstall `solid-js` as dependency.\n\nYou have to install those so that you are in control to which solid version is used to compile your code.\n\n```bash\n# with npm\n$ npm install -D vite vite-plugin-solid babel-preset-solid\n$ npm install solid-js\n\n# with pnpm\n$ pnpm add -D vite vite-plugin-solid babel-preset-solid\n$ pnpm add solid-js\n\n# with yarn\n$ yarn add -D vite vite-plugin-solid babel-preset-solid\n$ yarn add solid-js\n```\n\nAdd it as plugin to `vite.config.js`\n\n```js\n// vite.config.ts\nimport { defineConfig } from 'vite';\nimport solidPlugin from 'vite-plugin-solid';\n\nexport default defineConfig({\n plugins: [solidPlugin()],\n});\n```\n\n## Run\n\nJust use regular `vite` or `vite build` commands\n\n```json\n{\n \"scripts\": {\n \"dev\": \"vite\",\n \"build\": \"vite build\"\n }\n}\n```\n\n## API\n\n### options\n\n- Type: Object\n- Default: {}\n\n#### options.dev\n\n- Type: Boolean\n- Default: true\n\nThis will inject `solid-js/dev` in place of `solid-js` in dev mode. Has no effect in prod.\nIf set to false, it won't inject it in dev.\nThis is useful for extra logs and debug.\n\n#### options.hot\n\n- Type: Boolean\n- Default: true\n\nThis will inject HMR runtime in dev mode. Has no effect in prod.\nIf set to false, it won't inject the runtime in dev.\n\n#### options.ssr\n\n- Type: Boolean\n- Default: false\n\nThis will force SSR code in the produced files. This is experiemental and mostly not working yet.\n\n#### options.babel\n\n- Type: Babel.TransformOptions\n- Default: {}\n\nPass any additional [babel transform options](https://babeljs.io/docs/en/options). Those will be merged with the transformations required by Solid.\n\n#### options.solid\n\n- Type: [babel-plugin-jsx-dom-expressions](https://github.com/ryansolid/dom-expressions/tree/main/packages/babel-plugin-jsx-dom-expressions#plugin-options)\n- Default: {}\n\nPass any additional [babel-plugin-jsx-dom-expressions](https://github.com/ryansolid/dom-expressions/tree/main/packages/babel-plugin-jsx-dom-expressions#plugin-options).\nThey 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#### options.typescript\n\n- Type: [@babel/preset-typescript](https://babeljs.io/docs/en/babel-preset-typescript)\n- Default: {}\n\nPass any additional [@babel/preset-typescript](https://babeljs.io/docs/en/babel-preset-typescript).\n\n## Note on HMR\n\nStarting from version `1.1.0`, this plugin handle automatic HMR via [solid-refresh](https://github.com/solidjs/solid-refresh).\n\nAt this stage it's still early work but provide basic HMR. In order to get the best out of it there are couple of things to keep in mind:\n\n- When you modify a file every state below this component will be reset to default state (including the current file). The state in parent component is preserved.\n\n- The entrypoint can't benefit from HMR yet and will force a hard reload of the entire app. This is still really fast thanks to browser caching.\n\nIf at least one of this point is blocking to you, you can revert to the old behavior but [opting out the automatic HMR](#options) and placing the following snippet in your entry point:\n\n```jsx\nconst dispose = render(() => <App />, document.body);\n\nif (import.meta.hot) {\n import.meta.hot.accept();\n import.meta.hot.dispose(dispose);\n}\n```\n\n# Troubleshooting\n\n- It appears that Webstorm generate some weird triggers when saving a file. In order to prevent that you can follow [this thread](https://intellij-support.jetbrains.com/hc/en-us/community/posts/360000154544-I-m-having-a-huge-problem-with-Webstorm-and-react-hot-loader-) and disable the **\"Safe Write\"** option in **\"Settings | Appearance & Behavior | System Settings\"**.\n\n- If one of your dependency spit out React code instead of Solid that means that they don't expose JSX properly. To get around it, you might want to manually exclude it from the [dependencies optimization](https://vitejs.dev/config/#optimizedeps-exclude)\n\n- If you are trying to make [directives](https://www.solidjs.com/docs/latest/api#use%3A___) work and they somehow don't try setting the `options.typescript.onlyRemoveTypeImports` option to `true`\n\n## Migration from v1\n\nThe master branch now target vite 2.\n\nThe main breaking change from previous version is that the package has been renamed from `@amoutonbrady/vite-plugin-solid` to `vite-plugin-solid`.\n\nFor other breaking changes, check [the migration guide of vite](https://vitejs.dev/guide/migration.html).\n\n# Credits\n\n- [solid-js](https://github.com/solidjs/solid)\n- [vite](https://github.com/vitejs/vite)\n"
66
+ }