vite-plugin-solid 2.3.0 → 2.3.1

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,190 +1,190 @@
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
-
5
- # ⚡ vite-plugin-solid
6
-
7
- A simple integration to run [solid-js](https://github.com/solidjs/solid) with [vite](https://github.com/vitejs/vite)
8
-
9
- <img alt="HMR gif demonstrationdemodemodemo" src=".github/hmr.gif">
10
-
11
- # Got a question? / Need help?
12
-
13
- Join [solid discord](https://discord.com/invite/solidjs) and check the [troubleshooting section](#troubleshooting) to see if your question hasn't been already answered.
14
-
15
- ## Features
16
-
17
- - HMR with no configuration needed
18
- - Drop-in installation as a vite plugin
19
- - Minimal bundle size
20
- - Support typescript (`.tsx`) out of the box
21
- - Support code splitting out of the box
22
-
23
- ## Requirements
24
-
25
- This 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.
26
-
27
- You 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).
28
-
29
- ## Quickstart
30
-
31
- You can use the [vite-template-solid](https://github.com/solidjs/templates) starter templates similar to CRA:
32
-
33
- ```bash
34
- $ npx degit solidjs/templates/js my-solid-project
35
- $ cd my-solid-project
36
- $ npm install # or pnpm install or yarn install
37
- $ npm run start # starts dev-server with hot-module-reloading
38
- $ npm run build # builds to /dist
39
- ```
40
-
41
- ## Installation
42
-
43
- Install `vite`, `vite-plugin-solid` and `babel-preset-solid` as dev dependencies.
44
-
45
- Install `solid-js` as dependency.
46
-
47
- You have to install those so that you are in control to which solid version is used to compile your code.
48
-
49
- ```bash
50
- # with npm
51
- $ npm install -D vite vite-plugin-solid babel-preset-solid
52
- $ npm install solid-js
53
-
54
- # with pnpm
55
- $ pnpm add -D vite vite-plugin-solid babel-preset-solid
56
- $ pnpm add solid-js
57
-
58
- # with yarn
59
- $ yarn add -D vite vite-plugin-solid babel-preset-solid
60
- $ yarn add solid-js
61
- ```
62
-
63
- Add it as plugin to `vite.config.js`
64
-
65
- ```js
66
- // vite.config.ts
67
- import { defineConfig } from 'vite';
68
- import solidPlugin from 'vite-plugin-solid';
69
-
70
- export default defineConfig({
71
- plugins: [solidPlugin()],
72
- });
73
- ```
74
-
75
- ## Run
76
-
77
- Just use regular `vite` or `vite build` commands
78
-
79
- ```json
80
- {
81
- "scripts": {
82
- "dev": "vite",
83
- "build": "vite build"
84
- }
85
- }
86
- ```
87
-
88
- ## API
89
-
90
- ### options
91
-
92
- - Type: Object
93
- - Default: {}
94
-
95
- #### options.dev
96
-
97
- - Type: Boolean
98
- - Default: true
99
-
100
- This will inject `solid-js/dev` in place of `solid-js` in dev mode. Has no effect in prod.
101
- If set to false, it won't inject it in dev.
102
- This is useful for extra logs and debug.
103
-
104
- #### options.hot
105
-
106
- - Type: Boolean
107
- - Default: true
108
-
109
- This will inject HMR runtime in dev mode. Has no effect in prod.
110
- If set to false, it won't inject the runtime in dev.
111
-
112
- #### options.ssr
113
-
114
- - Type: Boolean
115
- - Default: false
116
-
117
- This will force SSR code in the produced files. This is experiemental and mostly not working yet.
118
-
119
- #### options.babel
120
-
121
- - Type: Babel.TransformOptions
122
- - Default: {}
123
-
124
- Pass any additional [babel transform options](https://babeljs.io/docs/en/options). Those will be merged with the transformations required by Solid.
125
-
126
- #### options.solid
127
-
128
- - Type: [babel-plugin-jsx-dom-expressions](https://github.com/ryansolid/dom-expressions/tree/main/packages/babel-plugin-jsx-dom-expressions#plugin-options)
129
- - Default: {}
130
-
131
- Pass any additional [babel-plugin-jsx-dom-expressions](https://github.com/ryansolid/dom-expressions/tree/main/packages/babel-plugin-jsx-dom-expressions#plugin-options).
132
- 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).
133
-
134
- #### options.typescript
135
-
136
- - Type: [@babel/preset-typescript](https://babeljs.io/docs/en/babel-preset-typescript)
137
- - Default: {}
138
-
139
- Pass any additional [@babel/preset-typescript](https://babeljs.io/docs/en/babel-preset-typescript).
140
-
141
- #### options.extensions
142
-
143
- - Type: (string, [string, { typescript: boolean }])[]
144
- - Default: []
145
-
146
- An array of custom extension that will be passed through the solid compiler.
147
- By default, the plugin only transform `jsx` and `tsx` files.
148
- This is useful if you want to transform `mdx` files for example.
149
-
150
- ## Note on HMR
151
-
152
- Starting from version `1.1.0`, this plugin handle automatic HMR via [solid-refresh](https://github.com/solidjs/solid-refresh).
153
-
154
- At 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:
155
-
156
- - 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.
157
-
158
- - 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.
159
-
160
- If 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:
161
-
162
- ```jsx
163
- const dispose = render(() => <App />, document.body);
164
-
165
- if (import.meta.hot) {
166
- import.meta.hot.accept();
167
- import.meta.hot.dispose(dispose);
168
- }
169
- ```
170
-
171
- # Troubleshooting
172
-
173
- - 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"**.
174
-
175
- - 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)
176
-
177
- - 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`
178
-
179
- ## Migration from v1
180
-
181
- The master branch now target vite 2.
182
-
183
- The main breaking change from previous version is that the package has been renamed from `@amoutonbrady/vite-plugin-solid` to `vite-plugin-solid`.
184
-
185
- For other breaking changes, check [the migration guide of vite](https://vitejs.dev/guide/migration.html).
186
-
187
- # Credits
188
-
189
- - [solid-js](https://github.com/solidjs/solid)
190
- - [vite](https://github.com/vitejs/vite)
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
+
5
+ # ⚡ vite-plugin-solid
6
+
7
+ A simple integration to run [solid-js](https://github.com/solidjs/solid) with [vite](https://github.com/vitejs/vite)
8
+
9
+ <img alt="HMR gif demonstrationdemodemodemo" src=".github/hmr.gif">
10
+
11
+ # Got a question? / Need help?
12
+
13
+ Join [solid discord](https://discord.com/invite/solidjs) and check the [troubleshooting section](#troubleshooting) to see if your question hasn't been already answered.
14
+
15
+ ## Features
16
+
17
+ - HMR with no configuration needed
18
+ - Drop-in installation as a vite plugin
19
+ - Minimal bundle size
20
+ - Support typescript (`.tsx`) out of the box
21
+ - Support code splitting out of the box
22
+
23
+ ## Requirements
24
+
25
+ This 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.
26
+
27
+ You 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).
28
+
29
+ ## Quickstart
30
+
31
+ You can use the [vite-template-solid](https://github.com/solidjs/templates) starter templates similar to CRA:
32
+
33
+ ```bash
34
+ $ npx degit solidjs/templates/js my-solid-project
35
+ $ cd my-solid-project
36
+ $ npm install # or pnpm install or yarn install
37
+ $ npm run start # starts dev-server with hot-module-reloading
38
+ $ npm run build # builds to /dist
39
+ ```
40
+
41
+ ## Installation
42
+
43
+ Install `vite`, `vite-plugin-solid` and `babel-preset-solid` as dev dependencies.
44
+
45
+ Install `solid-js` as dependency.
46
+
47
+ You have to install those so that you are in control to which solid version is used to compile your code.
48
+
49
+ ```bash
50
+ # with npm
51
+ $ npm install -D vite vite-plugin-solid babel-preset-solid
52
+ $ npm install solid-js
53
+
54
+ # with pnpm
55
+ $ pnpm add -D vite vite-plugin-solid babel-preset-solid
56
+ $ pnpm add solid-js
57
+
58
+ # with yarn
59
+ $ yarn add -D vite vite-plugin-solid babel-preset-solid
60
+ $ yarn add solid-js
61
+ ```
62
+
63
+ Add it as plugin to `vite.config.js`
64
+
65
+ ```js
66
+ // vite.config.ts
67
+ import { defineConfig } from 'vite';
68
+ import solidPlugin from 'vite-plugin-solid';
69
+
70
+ export default defineConfig({
71
+ plugins: [solidPlugin()],
72
+ });
73
+ ```
74
+
75
+ ## Run
76
+
77
+ Just use regular `vite` or `vite build` commands
78
+
79
+ ```json
80
+ {
81
+ "scripts": {
82
+ "dev": "vite",
83
+ "build": "vite build"
84
+ }
85
+ }
86
+ ```
87
+
88
+ ## API
89
+
90
+ ### options
91
+
92
+ - Type: Object
93
+ - Default: {}
94
+
95
+ #### options.dev
96
+
97
+ - Type: Boolean
98
+ - Default: true
99
+
100
+ This will inject `solid-js/dev` in place of `solid-js` in dev mode. Has no effect in prod.
101
+ If set to false, it won't inject it in dev.
102
+ This is useful for extra logs and debug.
103
+
104
+ #### options.hot
105
+
106
+ - Type: Boolean
107
+ - Default: true
108
+
109
+ This will inject HMR runtime in dev mode. Has no effect in prod.
110
+ If set to false, it won't inject the runtime in dev.
111
+
112
+ #### options.ssr
113
+
114
+ - Type: Boolean
115
+ - Default: false
116
+
117
+ This will force SSR code in the produced files. This is experiemental and mostly not working yet.
118
+
119
+ #### options.babel
120
+
121
+ - Type: Babel.TransformOptions
122
+ - Default: {}
123
+
124
+ Pass any additional [babel transform options](https://babeljs.io/docs/en/options). Those will be merged with the transformations required by Solid.
125
+
126
+ #### options.solid
127
+
128
+ - Type: [babel-plugin-jsx-dom-expressions](https://github.com/ryansolid/dom-expressions/tree/main/packages/babel-plugin-jsx-dom-expressions#plugin-options)
129
+ - Default: {}
130
+
131
+ Pass any additional [babel-plugin-jsx-dom-expressions](https://github.com/ryansolid/dom-expressions/tree/main/packages/babel-plugin-jsx-dom-expressions#plugin-options).
132
+ 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).
133
+
134
+ #### options.typescript
135
+
136
+ - Type: [@babel/preset-typescript](https://babeljs.io/docs/en/babel-preset-typescript)
137
+ - Default: {}
138
+
139
+ Pass any additional [@babel/preset-typescript](https://babeljs.io/docs/en/babel-preset-typescript).
140
+
141
+ #### options.extensions
142
+
143
+ - Type: (string, [string, { typescript: boolean }])[]
144
+ - Default: []
145
+
146
+ An array of custom extension that will be passed through the solid compiler.
147
+ By default, the plugin only transform `jsx` and `tsx` files.
148
+ This is useful if you want to transform `mdx` files for example.
149
+
150
+ ## Note on HMR
151
+
152
+ Starting from version `1.1.0`, this plugin handle automatic HMR via [solid-refresh](https://github.com/solidjs/solid-refresh).
153
+
154
+ At 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:
155
+
156
+ - 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.
157
+
158
+ - 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.
159
+
160
+ If 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:
161
+
162
+ ```jsx
163
+ const dispose = render(() => <App />, document.body);
164
+
165
+ if (import.meta.hot) {
166
+ import.meta.hot.accept();
167
+ import.meta.hot.dispose(dispose);
168
+ }
169
+ ```
170
+
171
+ # Troubleshooting
172
+
173
+ - 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"**.
174
+
175
+ - 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)
176
+
177
+ - 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`
178
+
179
+ ## Migration from v1
180
+
181
+ The master branch now target vite 2.
182
+
183
+ The main breaking change from previous version is that the package has been renamed from `@amoutonbrady/vite-plugin-solid` to `vite-plugin-solid`.
184
+
185
+ For other breaking changes, check [the migration guide of vite](https://vitejs.dev/guide/migration.html).
186
+
187
+ # Credits
188
+
189
+ - [solid-js](https://github.com/solidjs/solid)
190
+ - [vite](https://github.com/vitejs/vite)
@@ -25,7 +25,7 @@ const runtimeCode = fs.readFileSync(runtimeFilePath, 'utf-8');
25
25
 
26
26
  function getExtension(filename) {
27
27
  const index = filename.lastIndexOf('.');
28
- return index < 0 ? '' : filename.substring(index);
28
+ return index < 0 ? '' : filename.substring(index).replace(/\?.+$/, '');
29
29
  }
30
30
 
31
31
  function solidPlugin(options = {}) {
@@ -47,9 +47,9 @@ function solidPlugin(options = {}) {
47
47
 
48
48
  const nestedDeps = replaceDev ? ['solid-js', 'solid-js/web', 'solid-js/store', 'solid-js/html', 'solid-js/h'] : [];
49
49
  return {
50
- /**
51
- * We only need esbuild on .ts or .js files.
52
- * .tsx & .jsx files are handled by us
50
+ /**
51
+ * We only need esbuild on .ts or .js files.
52
+ * .tsx & .jsx files are handled by us
53
53
  */
54
54
  esbuild: {
55
55
  include: /\.ts$/
@@ -169,11 +169,11 @@ function solidPlugin(options = {}) {
169
169
 
170
170
  };
171
171
  }
172
- /**
173
- * This basically normalize all aliases of the config into
174
- * the array format of the alias.
175
- *
176
- * eg: alias: { '@': 'src/' } => [{ find: '@', replacement: 'src/' }]
172
+ /**
173
+ * This basically normalize all aliases of the config into
174
+ * the array format of the alias.
175
+ *
176
+ * eg: alias: { '@': 'src/' } => [{ find: '@', replacement: 'src/' }]
177
177
  */
178
178
 
179
179
  function normalizeAliases(alias = []) {
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","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/** Possible options for the extensions property */\r\nexport interface ExtensionOptions {\r\n typescript?: boolean;\r\n}\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 * This registers additional extensions that should be processed by\r\n * vite-plugin-solid.\r\n *\r\n * @default undefined\r\n */\r\n extensions?: (string | [string, ExtensionOptions])[];\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 * - \"universal\" is for using custom renderers from solid-js/universal\r\n *\r\n * @default \"dom\"\r\n */\r\n generate?: 'ssr' | 'dom' | 'universal';\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\nfunction getExtension(filename: string): string {\r\n const index = filename.lastIndexOf('.');\r\n return index < 0 ? '' : filename.substring(index);\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 if (!userConfig.resolve) userConfig.resolve = {};\r\n userConfig.resolve.alias = normalizeAliases(userConfig.resolve && userConfig.resolve.alias);\r\n\r\n // fix for bundling dev in production\r\n const nestedDeps = replaceDev\r\n ? ['solid-js', 'solid-js/web', 'solid-js/store', 'solid-js/html', '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.mode !== 'production' && 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 const isSsr = transformOptions && transformOptions.ssr;\r\n const currentFileExtension = getExtension(id);\r\n\r\n const extensionsToWatch = [...(options.extensions || []), '.tsx', '.jsx'];\r\n const allExtensions = extensionsToWatch.map((extension) =>\r\n // An extension can be a string or a tuple [extension, options]\r\n typeof extension === 'string' ? extension : extension[0],\r\n );\r\n\r\n if (!allExtensions.includes(currentFileExtension)) {\r\n return null;\r\n }\r\n\r\n const inNodeModules = /node_modules/.test(id);\r\n\r\n let solidOptions: { generate: 'ssr' | 'dom'; hydratable: boolean };\r\n\r\n if (options.ssr) {\r\n if (isSsr) {\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 && !isSsr && !inNodeModules ? [[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 // We need to know if the current file extension has a typescript options tied to it\r\n const shouldBeProcessedWithTypescript = extensionsToWatch.some((extension) => {\r\n if (typeof extension === 'string') {\r\n return extension.includes('tsx');\r\n }\r\n\r\n const [extensionName, extensionOptions] = extension;\r\n if (extensionName !== currentFileExtension) return false;\r\n\r\n return extensionOptions.typescript;\r\n });\r\n\r\n if (shouldBeProcessedWithTypescript) {\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, isSsr);\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","runtimePublicPath","runtimeFilePath","resolve","runtimeCode","readFileSync","getExtension","filename","index","lastIndexOf","substring","solidPlugin","options","needHmr","replaceDev","projectRoot","process","cwd","name","enforce","config","userConfig","command","dev","root","alias","normalizeAliases","nestedDeps","esbuild","include","conditions","dedupe","find","replacement","optimizeDeps","configResolved","mode","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,SAAO,GAAGC,sBAAa,CAACC,oMAAD,CAA7B,CAAA;;AAEA,MAAMC,iBAAiB,GAAG,iBAA1B,CAAA;;AACA,MAAMC,eAAe,GAAGJ,SAAO,CAACK,OAAR,CAAgB,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HD,MAGO;UACLF,gBAAgB,GAAGhE,OAAO,CAACiE,KAA3B,CAAA;AACD,SAAA;AACF,OAAA;;AAED,MAAA,MAAMC,YAAY,GAAGE,4BAAc,CAACJ,gBAAD,EAAmBlB,IAAnB,CAAnC,CAAA;MAEA,MAAM;QAAEuB,IAAF;AAAQ/B,QAAAA,GAAAA;AAAR,OAAA,GAAgB,MAAMgC,mBAAc,CAACxC,MAAD,EAASoC,YAAT,CAA1C,CAAA;MAEA,OAAO;QAAEG,IAAF;AAAQ/B,QAAAA,GAAAA;OAAf,CAAA;AACD,KAAA;;GAxHH,CAAA;AA0HD,CAAA;AAED;AACA;AACA;AACA;AACA;AACA;;AACA,SAASxB,gBAAT,CAA0BD,KAAmB,GAAG,EAAhD,EAA6D;EAC3D,OAAO0D,KAAK,CAACC,OAAN,CAAc3D,KAAd,CACHA,GAAAA,KADG,GAEH4D,MAAM,CAACC,OAAP,CAAe7D,KAAf,CAAA,CAAsByB,GAAtB,CAA0B,CAAC,CAAClB,IAAD,EAAOC,WAAP,CAAD,MAA0B;IAAED,IAAF;AAAQC,IAAAA,WAAAA;AAAR,GAA1B,CAA1B,CAFJ,CAAA;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 * - \"universal\" is for using custom renderers from solid-js/universal\n *\n * @default \"dom\"\n */\n generate?: 'ssr' | 'dom' | 'universal';\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).replace(/\\?.+$/, '');\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 if (!userConfig.resolve) userConfig.resolve = {};\n userConfig.resolve.alias = normalizeAliases(userConfig.resolve && 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.mode !== 'production' && 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 && 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","runtimePublicPath","runtimeFilePath","resolve","runtimeCode","readFileSync","getExtension","filename","index","lastIndexOf","substring","replace","solidPlugin","options","needHmr","replaceDev","projectRoot","process","cwd","name","enforce","config","userConfig","command","dev","root","alias","normalizeAliases","nestedDeps","esbuild","include","conditions","dedupe","find","replacement","optimizeDeps","configResolved","mode","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,SAAO,GAAGC,sBAAa,CAACC,oMAAD,CAA7B,CAAA;;AAEA,MAAMC,iBAAiB,GAAG,iBAA1B,CAAA;;AACA,MAAMC,eAAe,GAAGJ,SAAO,CAACK,OAAR,CAAgB,sCAAhB,CAAxB,CAAA;;AACA,MAAMC,WAAW,GAAGC,eAAY,CAACH,eAAD,EAAkB,OAAlB,CAAhC,CAAA;AAEA;;AAsOA,SAASI,YAAT,CAAsBC,QAAtB,EAAgD;AAC9C,EAAA,MAAMC,KAAK,GAAGD,QAAQ,CAACE,WAAT,CAAqB,GAArB,CAAd,CAAA;AACA,EAAA,OAAOD,KAAK,GAAG,CAAR,GAAY,EAAZ,GAAiBD,QAAQ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,GAAgB,MAAMgC,mBAAc,CAACxC,MAAD,EAASoC,YAAT,CAA1C,CAAA;MAEA,OAAO;QAAEG,IAAF;AAAQ/B,QAAAA,GAAAA;OAAf,CAAA;AACD,KAAA;;GAxHH,CAAA;AA0HD,CAAA;AAED;AACA;AACA;AACA;AACA;AACA;;AACA,SAASxB,gBAAT,CAA0BD,KAAmB,GAAG,EAAhD,EAA6D;EAC3D,OAAO0D,KAAK,CAACC,OAAN,CAAc3D,KAAd,CACHA,GAAAA,KADG,GAEH4D,MAAM,CAACC,OAAP,CAAe7D,KAAf,CAAA,CAAsByB,GAAtB,CAA0B,CAAC,CAAClB,IAAD,EAAOC,WAAP,CAAD,MAA0B;IAAED,IAAF;AAAQC,IAAAA,WAAAA;AAAR,GAA1B,CAA1B,CAFJ,CAAA;AAGD;;;;"}
@@ -17,7 +17,7 @@ const runtimeCode = readFileSync(runtimeFilePath, 'utf-8');
17
17
 
18
18
  function getExtension(filename) {
19
19
  const index = filename.lastIndexOf('.');
20
- return index < 0 ? '' : filename.substring(index);
20
+ return index < 0 ? '' : filename.substring(index).replace(/\?.+$/, '');
21
21
  }
22
22
 
23
23
  function solidPlugin(options = {}) {
@@ -39,9 +39,9 @@ function solidPlugin(options = {}) {
39
39
 
40
40
  const nestedDeps = replaceDev ? ['solid-js', 'solid-js/web', 'solid-js/store', 'solid-js/html', 'solid-js/h'] : [];
41
41
  return {
42
- /**
43
- * We only need esbuild on .ts or .js files.
44
- * .tsx & .jsx files are handled by us
42
+ /**
43
+ * We only need esbuild on .ts or .js files.
44
+ * .tsx & .jsx files are handled by us
45
45
  */
46
46
  esbuild: {
47
47
  include: /\.ts$/
@@ -161,11 +161,11 @@ function solidPlugin(options = {}) {
161
161
 
162
162
  };
163
163
  }
164
- /**
165
- * This basically normalize all aliases of the config into
166
- * the array format of the alias.
167
- *
168
- * eg: alias: { '@': 'src/' } => [{ find: '@', replacement: 'src/' }]
164
+ /**
165
+ * This basically normalize all aliases of the config into
166
+ * the array format of the alias.
167
+ *
168
+ * eg: alias: { '@': 'src/' } => [{ find: '@', replacement: 'src/' }]
169
169
  */
170
170
 
171
171
  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/** Possible options for the extensions property */\r\nexport interface ExtensionOptions {\r\n typescript?: boolean;\r\n}\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 * This registers additional extensions that should be processed by\r\n * vite-plugin-solid.\r\n *\r\n * @default undefined\r\n */\r\n extensions?: (string | [string, ExtensionOptions])[];\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 * - \"universal\" is for using custom renderers from solid-js/universal\r\n *\r\n * @default \"dom\"\r\n */\r\n generate?: 'ssr' | 'dom' | 'universal';\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\nfunction getExtension(filename: string): string {\r\n const index = filename.lastIndexOf('.');\r\n return index < 0 ? '' : filename.substring(index);\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 if (!userConfig.resolve) userConfig.resolve = {};\r\n userConfig.resolve.alias = normalizeAliases(userConfig.resolve && userConfig.resolve.alias);\r\n\r\n // fix for bundling dev in production\r\n const nestedDeps = replaceDev\r\n ? ['solid-js', 'solid-js/web', 'solid-js/store', 'solid-js/html', '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.mode !== 'production' && 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 const isSsr = transformOptions && transformOptions.ssr;\r\n const currentFileExtension = getExtension(id);\r\n\r\n const extensionsToWatch = [...(options.extensions || []), '.tsx', '.jsx'];\r\n const allExtensions = extensionsToWatch.map((extension) =>\r\n // An extension can be a string or a tuple [extension, options]\r\n typeof extension === 'string' ? extension : extension[0],\r\n );\r\n\r\n if (!allExtensions.includes(currentFileExtension)) {\r\n return null;\r\n }\r\n\r\n const inNodeModules = /node_modules/.test(id);\r\n\r\n let solidOptions: { generate: 'ssr' | 'dom'; hydratable: boolean };\r\n\r\n if (options.ssr) {\r\n if (isSsr) {\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 && !isSsr && !inNodeModules ? [[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 // We need to know if the current file extension has a typescript options tied to it\r\n const shouldBeProcessedWithTypescript = extensionsToWatch.some((extension) => {\r\n if (typeof extension === 'string') {\r\n return extension.includes('tsx');\r\n }\r\n\r\n const [extensionName, extensionOptions] = extension;\r\n if (extensionName !== currentFileExtension) return false;\r\n\r\n return extensionOptions.typescript;\r\n });\r\n\r\n if (shouldBeProcessedWithTypescript) {\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, isSsr);\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","getExtension","filename","index","lastIndexOf","substring","solidPlugin","options","needHmr","replaceDev","projectRoot","process","cwd","name","enforce","config","userConfig","command","dev","root","alias","normalizeAliases","nestedDeps","esbuild","include","conditions","dedupe","find","replacement","optimizeDeps","configResolved","mode","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,CAAA;;AAEA,MAAMC,iBAAiB,GAAG,iBAA1B,CAAA;;AACA,MAAMC,eAAe,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GAAuDA,YAA1E,CAAA;AACD,SAHD,MAGO;UACLF,gBAAgB,GAAGhE,OAAO,CAACiE,KAA3B,CAAA;AACD,SAAA;AACF,OAAA;;AAED,MAAA,MAAMC,YAAY,GAAGE,cAAc,CAACJ,gBAAD,EAAmBlB,IAAnB,CAAnC,CAAA;MAEA,MAAM;QAAEuB,IAAF;AAAQ/B,QAAAA,GAAAA;AAAR,OAAA,GAAgB,MAAMgC,cAAc,CAACxC,MAAD,EAASoC,YAAT,CAA1C,CAAA;MAEA,OAAO;QAAEG,IAAF;AAAQ/B,QAAAA,GAAAA;OAAf,CAAA;AACD,KAAA;;GAxHH,CAAA;AA0HD,CAAA;AAED;AACA;AACA;AACA;AACA;AACA;;AACA,SAASxB,gBAAT,CAA0BD,KAAmB,GAAG,EAAhD,EAA6D;EAC3D,OAAO0D,KAAK,CAACC,OAAN,CAAc3D,KAAd,CACHA,GAAAA,KADG,GAEH4D,MAAM,CAACC,OAAP,CAAe7D,KAAf,CAAA,CAAsByB,GAAtB,CAA0B,CAAC,CAAClB,IAAD,EAAOC,WAAP,CAAD,MAA0B;IAAED,IAAF;AAAQC,IAAAA,WAAAA;AAAR,GAA1B,CAA1B,CAFJ,CAAA;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 * - \"universal\" is for using custom renderers from solid-js/universal\n *\n * @default \"dom\"\n */\n generate?: 'ssr' | 'dom' | 'universal';\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).replace(/\\?.+$/, '');\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 if (!userConfig.resolve) userConfig.resolve = {};\n userConfig.resolve.alias = normalizeAliases(userConfig.resolve && 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.mode !== 'production' && 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 && 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","replace","solidPlugin","options","needHmr","replaceDev","projectRoot","process","cwd","name","enforce","config","userConfig","command","dev","root","alias","normalizeAliases","nestedDeps","esbuild","include","conditions","dedupe","find","replacement","optimizeDeps","configResolved","mode","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,CAAA;;AAEA,MAAMC,iBAAiB,GAAG,iBAA1B,CAAA;;AACA,MAAMC,eAAe,GAAGN,OAAO,CAACO,OAAR,CAAgB,sCAAhB,CAAxB,CAAA;;AACA,MAAMC,WAAW,GAAGC,YAAY,CAACH,eAAD,EAAkB,OAAlB,CAAhC,CAAA;AAEA;;AAsOA,SAASI,YAAT,CAAsBC,QAAtB,EAAgD;AAC9C,EAAA,MAAMC,KAAK,GAAGD,QAAQ,CAACE,WAAT,CAAqB,GAArB,CAAd,CAAA;AACA,EAAA,OAAOD,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AAF;AAAQ/B,QAAAA,GAAAA;AAAR,OAAA,GAAgB,MAAMgC,cAAc,CAACxC,MAAD,EAASoC,YAAT,CAA1C,CAAA;MAEA,OAAO;QAAEG,IAAF;AAAQ/B,QAAAA,GAAAA;OAAf,CAAA;AACD,KAAA;;GAxHH,CAAA;AA0HD,CAAA;AAED;AACA;AACA;AACA;AACA;AACA;;AACA,SAASxB,gBAAT,CAA0BD,KAAmB,GAAG,EAAhD,EAA6D;EAC3D,OAAO0D,KAAK,CAACC,OAAN,CAAc3D,KAAd,CACHA,GAAAA,KADG,GAEH4D,MAAM,CAACC,OAAP,CAAe7D,KAAf,CAAA,CAAsByB,GAAtB,CAA0B,CAAC,CAAClB,IAAD,EAAOC,WAAP,CAAD,MAA0B;IAAED,IAAF;AAAQC,IAAAA,WAAAA;AAAR,GAA1B,CAA1B,CAFJ,CAAA;AAGD;;;;"}
@@ -1,215 +1,215 @@
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
- * - "universal" is for using custom renderers from solid-js/universal
176
- *
177
- * @default "dom"
178
- */
179
- generate?: 'ssr' | 'dom' | 'universal';
180
- /**
181
- * Indicate whether the output should contain hydratable markers.
182
- *
183
- * @default false
184
- */
185
- hydratable?: boolean;
186
- /**
187
- * Boolean to indicate whether to enable automatic event delegation on camelCase.
188
- *
189
- * @default true
190
- */
191
- delegateEvents?: boolean;
192
- /**
193
- * Boolean indicates whether smart conditional detection should be used.
194
- * This optimizes simple boolean expressions and ternaries in JSX.
195
- *
196
- * @default true
197
- */
198
- wrapConditionals?: boolean;
199
- /**
200
- * Boolean indicates whether to set current render context on Custom Elements and slots.
201
- * Useful for seemless Context API with Web Components.
202
- *
203
- * @default true
204
- */
205
- contextToCustomElements?: boolean;
206
- /**
207
- * Array of Component exports from module, that aren't included by default with the library.
208
- * This plugin will automatically import them if it comes across them in the JSX.
209
- *
210
- * @default ["For","Show","Switch","Match","Suspense","SuspenseList","Portal","Index","Dynamic","ErrorBoundary"]
211
- */
212
- builtIns?: string[];
213
- };
214
- }
215
- 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
+ * - "universal" is for using custom renderers from solid-js/universal
176
+ *
177
+ * @default "dom"
178
+ */
179
+ generate?: 'ssr' | 'dom' | 'universal';
180
+ /**
181
+ * Indicate whether the output should contain hydratable markers.
182
+ *
183
+ * @default false
184
+ */
185
+ hydratable?: boolean;
186
+ /**
187
+ * Boolean to indicate whether to enable automatic event delegation on camelCase.
188
+ *
189
+ * @default true
190
+ */
191
+ delegateEvents?: boolean;
192
+ /**
193
+ * Boolean indicates whether smart conditional detection should be used.
194
+ * This optimizes simple boolean expressions and ternaries in JSX.
195
+ *
196
+ * @default true
197
+ */
198
+ wrapConditionals?: boolean;
199
+ /**
200
+ * Boolean indicates whether to set current render context on Custom Elements and slots.
201
+ * Useful for seemless Context API with Web Components.
202
+ *
203
+ * @default true
204
+ */
205
+ contextToCustomElements?: boolean;
206
+ /**
207
+ * Array of Component exports from module, that aren't included by default with the library.
208
+ * This plugin will automatically import them if it comes across them in the JSX.
209
+ *
210
+ * @default ["For","Show","Switch","Match","Suspense","SuspenseList","Portal","Index","Dynamic","ErrorBoundary"]
211
+ */
212
+ builtIns?: string[];
213
+ };
214
+ }
215
+ export default function solidPlugin(options?: Partial<Options>): Plugin;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-solid",
3
- "version": "2.3.0",
3
+ "version": "2.3.1",
4
4
  "description": "solid-js integration plugin for vite 3",
5
5
  "type": "module",
6
6
  "files": [