vite-plugin-solid 2.1.0 → 2.1.4
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 +177 -188
- package/dist/cjs/index.cjs +29 -14
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/esm/index.mjs +29 -14
- package/dist/esm/index.mjs.map +1 -1
- package/dist/types/index.d.ts +203 -203
- package/package.json +21 -20
package/README.md
CHANGED
|
@@ -1,188 +1,177 @@
|
|
|
1
|
-
# ⚡ vite-plugin-solid
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
#
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
-
|
|
16
|
-
-
|
|
17
|
-
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
$
|
|
33
|
-
$
|
|
34
|
-
$ npm
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
Install `
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
-
|
|
97
|
-
|
|
98
|
-
This
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
The master branch now target vite 2.
|
|
180
|
-
|
|
181
|
-
The main breaking change from previous version is that the package has been renamed from `@amoutonbrady/vite-plugin-solid` to `vite-plugin-solid`.
|
|
182
|
-
|
|
183
|
-
For other breaking changes, check [the migration guide of vite](https://vitejs.dev/guide/migration.html).
|
|
184
|
-
|
|
185
|
-
# Credits
|
|
186
|
-
|
|
187
|
-
- [solid-js](https://github.com/solidjs/solid)
|
|
188
|
-
- [vite](https://github.com/vitejs/vite)
|
|
1
|
+
# ⚡ vite-plugin-solid
|
|
2
|
+
|
|
3
|
+
A simple integration to run [solid-js](https://github.com/solidjs/solid) with [vite](https://github.com/vitejs/vite)
|
|
4
|
+
|
|
5
|
+
<img alt="HMR gif demonstrationdemodemodemo" src=".github/hmr.gif">
|
|
6
|
+
|
|
7
|
+
# Got a question? / Need help?
|
|
8
|
+
|
|
9
|
+
Join [solid discord](https://discord.com/invite/solidjs) and check the [troubleshooting section](#troubleshooting) to see if your question hasn't been already answered.
|
|
10
|
+
|
|
11
|
+
## Features
|
|
12
|
+
|
|
13
|
+
- HMR with no configuration needed
|
|
14
|
+
- Drop-in installation as a vite plugin
|
|
15
|
+
- Minimal bundle size
|
|
16
|
+
- Support typescript (`.tsx`) out of the box
|
|
17
|
+
- Support code splitting out of the box
|
|
18
|
+
|
|
19
|
+
## Requirements
|
|
20
|
+
|
|
21
|
+
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.
|
|
22
|
+
|
|
23
|
+
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).
|
|
24
|
+
|
|
25
|
+
## Quickstart
|
|
26
|
+
|
|
27
|
+
You can use the [vite-template-solid](https://github.com/solidjs/templates) starter templates similar to CRA:
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
$ npx degit solidjs/templates/js my-solid-project
|
|
31
|
+
$ cd my-solid-project
|
|
32
|
+
$ npm install # or pnpm install or yarn install
|
|
33
|
+
$ npm run start # starts dev-server with hot-module-reloading
|
|
34
|
+
$ npm run build # builds to /dist
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Installation
|
|
38
|
+
|
|
39
|
+
Install `vite`, `vite-plugin-solid` and `babel-preset-solid` as dev dependencies.
|
|
40
|
+
|
|
41
|
+
Install `solid-js` as dependency.
|
|
42
|
+
|
|
43
|
+
You have to install those so that you are in control to which solid version is used to compile your code.
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
# with npm
|
|
47
|
+
$ npm install -D vite vite-plugin-solid babel-preset-solid
|
|
48
|
+
$ npm install solid-js
|
|
49
|
+
|
|
50
|
+
# with pnpm
|
|
51
|
+
$ pnpm add -D vite vite-plugin-solid babel-preset-solid
|
|
52
|
+
$ pnpm add solid-js
|
|
53
|
+
|
|
54
|
+
# with yarn
|
|
55
|
+
$ yarn add -D vite vite-plugin-solid babel-preset-solid
|
|
56
|
+
$ yarn add solid-js
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Add it as plugin to `vite.config.js`
|
|
60
|
+
|
|
61
|
+
```js
|
|
62
|
+
// vite.config.ts
|
|
63
|
+
import { defineConfig } from 'vite';
|
|
64
|
+
import solidPlugin from 'vite-plugin-solid';
|
|
65
|
+
|
|
66
|
+
export default defineConfig({
|
|
67
|
+
plugins: [solidPlugin()],
|
|
68
|
+
});
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## Run
|
|
72
|
+
|
|
73
|
+
Just use regular `vite` or `vite build` commands
|
|
74
|
+
|
|
75
|
+
```json
|
|
76
|
+
{
|
|
77
|
+
"scripts": {
|
|
78
|
+
"dev": "vite",
|
|
79
|
+
"build": "vite build"
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## API
|
|
85
|
+
|
|
86
|
+
### options
|
|
87
|
+
|
|
88
|
+
- Type: Object
|
|
89
|
+
- Default: {}
|
|
90
|
+
|
|
91
|
+
#### options.dev
|
|
92
|
+
|
|
93
|
+
- Type: Boolean
|
|
94
|
+
- Default: true
|
|
95
|
+
|
|
96
|
+
This will inject `solid-js/dev` in place of `solid-js` in dev mode. Has no effect in prod.
|
|
97
|
+
If set to false, it won't inject it in dev.
|
|
98
|
+
This is useful for extra logs and debug.
|
|
99
|
+
|
|
100
|
+
#### options.hot
|
|
101
|
+
|
|
102
|
+
- Type: Boolean
|
|
103
|
+
- Default: true
|
|
104
|
+
|
|
105
|
+
This will inject HMR runtime in dev mode. Has no effect in prod.
|
|
106
|
+
If set to false, it won't inject the runtime in dev.
|
|
107
|
+
|
|
108
|
+
#### options.ssr
|
|
109
|
+
|
|
110
|
+
- Type: Boolean
|
|
111
|
+
- Default: false
|
|
112
|
+
|
|
113
|
+
This will force SSR code in the produced files. This is experiemental and mostly not working yet.
|
|
114
|
+
|
|
115
|
+
#### options.babel
|
|
116
|
+
|
|
117
|
+
- Type: Babel.TransformOptions
|
|
118
|
+
- Default: {}
|
|
119
|
+
|
|
120
|
+
Pass any additional [babel transform options](https://babeljs.io/docs/en/options). Those will be merged with the transformations required by Solid.
|
|
121
|
+
|
|
122
|
+
#### options.solid
|
|
123
|
+
|
|
124
|
+
- Type: [babel-plugin-jsx-dom-expressions](https://github.com/ryansolid/dom-expressions/tree/main/packages/babel-plugin-jsx-dom-expressions#plugin-options)
|
|
125
|
+
- Default: {}
|
|
126
|
+
|
|
127
|
+
Pass any additional [babel-plugin-jsx-dom-expressions](https://github.com/ryansolid/dom-expressions/tree/main/packages/babel-plugin-jsx-dom-expressions#plugin-options).
|
|
128
|
+
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).
|
|
129
|
+
|
|
130
|
+
#### options.typescript
|
|
131
|
+
|
|
132
|
+
- Type: [@babel/preset-typescript](https://babeljs.io/docs/en/babel-preset-typescript)
|
|
133
|
+
- Default: {}
|
|
134
|
+
|
|
135
|
+
Pass any additional [@babel/preset-typescript](https://babeljs.io/docs/en/babel-preset-typescript).
|
|
136
|
+
|
|
137
|
+
## Note on HMR
|
|
138
|
+
|
|
139
|
+
Starting from version `1.1.0`, this plugin handle automatic HMR via [solid-refresh](https://github.com/solidjs/solid-refresh).
|
|
140
|
+
|
|
141
|
+
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:
|
|
142
|
+
|
|
143
|
+
- 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.
|
|
144
|
+
|
|
145
|
+
- 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.
|
|
146
|
+
|
|
147
|
+
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:
|
|
148
|
+
|
|
149
|
+
```jsx
|
|
150
|
+
const dispose = render(() => <App />, document.body);
|
|
151
|
+
|
|
152
|
+
if (import.meta.hot) {
|
|
153
|
+
import.meta.hot.accept();
|
|
154
|
+
import.meta.hot.dispose(dispose);
|
|
155
|
+
}
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
# Troubleshooting
|
|
159
|
+
|
|
160
|
+
- 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"**.
|
|
161
|
+
|
|
162
|
+
- 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)
|
|
163
|
+
|
|
164
|
+
- 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`
|
|
165
|
+
|
|
166
|
+
## Migration from v1
|
|
167
|
+
|
|
168
|
+
The master branch now target vite 2.
|
|
169
|
+
|
|
170
|
+
The main breaking change from previous version is that the package has been renamed from `@amoutonbrady/vite-plugin-solid` to `vite-plugin-solid`.
|
|
171
|
+
|
|
172
|
+
For other breaking changes, check [the migration guide of vite](https://vitejs.dev/guide/migration.html).
|
|
173
|
+
|
|
174
|
+
# Credits
|
|
175
|
+
|
|
176
|
+
- [solid-js](https://github.com/solidjs/solid)
|
|
177
|
+
- [vite](https://github.com/vitejs/vite)
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -25,6 +25,8 @@ const runtimeCode = fs.readFileSync(runtimeFilePath, 'utf-8');
|
|
|
25
25
|
|
|
26
26
|
function solidPlugin(options = {}) {
|
|
27
27
|
let needHmr = false;
|
|
28
|
+
let replaceDev = false;
|
|
29
|
+
let projectRoot = process.cwd();
|
|
28
30
|
return {
|
|
29
31
|
name: 'solid',
|
|
30
32
|
enforce: 'pre',
|
|
@@ -35,16 +37,18 @@ function solidPlugin(options = {}) {
|
|
|
35
37
|
var _userConfig$resolve;
|
|
36
38
|
|
|
37
39
|
// We inject the dev mode only if the user explicitely wants it or if we are in dev (serve) mode
|
|
38
|
-
|
|
40
|
+
replaceDev = options.dev === true || options.dev !== false && command === 'serve';
|
|
41
|
+
projectRoot = userConfig.root; // TODO: remove when fully removed from vite
|
|
39
42
|
|
|
40
43
|
const legacyAlias = normalizeAliases(userConfig.alias);
|
|
41
44
|
if (!userConfig.resolve) userConfig.resolve = {};
|
|
42
|
-
userConfig.resolve.alias = [...legacyAlias, ...normalizeAliases((_userConfig$resolve = userConfig.resolve) === null || _userConfig$resolve === void 0 ? void 0 : _userConfig$resolve.alias)];
|
|
43
|
-
|
|
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
|
|
46
|
+
|
|
47
|
+
const nestedDeps = replaceDev ? ['solid-js', 'solid-js/web', 'solid-js/store', 'solid-js/html', 'solid-js/h'] : [];
|
|
44
48
|
return {
|
|
45
|
-
/**
|
|
46
|
-
* We only need esbuild on .ts or .js files.
|
|
47
|
-
* .tsx & .jsx files are handled by us
|
|
49
|
+
/**
|
|
50
|
+
* We only need esbuild on .ts or .js files.
|
|
51
|
+
* .tsx & .jsx files are handled by us
|
|
48
52
|
*/
|
|
49
53
|
esbuild: {
|
|
50
54
|
include: /\.ts$/
|
|
@@ -75,8 +79,12 @@ function solidPlugin(options = {}) {
|
|
|
75
79
|
if (id === runtimePublicPath) return runtimeCode;
|
|
76
80
|
},
|
|
77
81
|
|
|
78
|
-
async transform(source, id,
|
|
82
|
+
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);
|
|
79
86
|
if (!/\.[jt]sx/.test(id)) return null;
|
|
87
|
+
const inNodeModules = /node_modules/.test(id);
|
|
80
88
|
let solidOptions;
|
|
81
89
|
|
|
82
90
|
if (options.ssr) {
|
|
@@ -99,13 +107,20 @@ function solidPlugin(options = {}) {
|
|
|
99
107
|
}
|
|
100
108
|
|
|
101
109
|
const opts = {
|
|
110
|
+
babelrc: false,
|
|
111
|
+
configFile: false,
|
|
112
|
+
root: projectRoot,
|
|
102
113
|
filename: id,
|
|
114
|
+
sourceFileName: id,
|
|
103
115
|
presets: [[solid__default["default"], { ...solidOptions,
|
|
104
116
|
...(options.solid || {})
|
|
105
117
|
}]],
|
|
106
|
-
plugins: needHmr ? [[solidRefresh__default["default"], {
|
|
118
|
+
plugins: needHmr && !inNodeModules ? [[solidRefresh__default["default"], {
|
|
107
119
|
bundler: 'vite'
|
|
108
|
-
}]] : []
|
|
120
|
+
}]] : [],
|
|
121
|
+
sourceMaps: true,
|
|
122
|
+
// Vite handles sourcemap flattening
|
|
123
|
+
inputSourceMap: false
|
|
109
124
|
};
|
|
110
125
|
|
|
111
126
|
if (id.includes('tsx')) {
|
|
@@ -137,11 +152,11 @@ function solidPlugin(options = {}) {
|
|
|
137
152
|
|
|
138
153
|
};
|
|
139
154
|
}
|
|
140
|
-
/**
|
|
141
|
-
* This basically normalize all aliases of the config into
|
|
142
|
-
* the array format of the alias.
|
|
143
|
-
*
|
|
144
|
-
* eg: alias: { '@': 'src/' } => [{ find: '@', replacement: 'src/' }]
|
|
155
|
+
/**
|
|
156
|
+
* This basically normalize all aliases of the config into
|
|
157
|
+
* the array format of the alias.
|
|
158
|
+
*
|
|
159
|
+
* eg: alias: { '@': 'src/' } => [{ find: '@', replacement: 'src/' }]
|
|
145
160
|
*/
|
|
146
161
|
|
|
147
162
|
function normalizeAliases(alias = []) {
|
package/dist/cjs/index.cjs.map
CHANGED
|
@@ -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/** Configuration options for vite-plugin-solid. */\r\nexport interface Options {\r\n /**\r\n * This will inject solid-js/dev in place of solid-js in dev mode. Has no\r\n * effect in prod. If set to `false`, it won't inject it in dev. This is\r\n * useful for extra logs and debugging.\r\n *\r\n * @default true\r\n */\r\n dev: boolean;\r\n /**\r\n * This will force SSR code in the produced files. This is experiemental\r\n * and mostly not working yet.\r\n *\r\n * @default false\r\n */\r\n ssr: boolean;\r\n /**\r\n * This will inject HMR runtime in dev mode. Has no effect in prod. If\r\n * set to `false`, it won't inject the runtime in dev.\r\n *\r\n * @default true\r\n */\r\n hot: boolean;\r\n /**\r\n * Pass any additional babel transform options. They will be merged with\r\n * the transformations required by Solid.\r\n *\r\n * @default {}\r\n */\r\n babel:\r\n | TransformOptions\r\n | ((source: string, id: string, ssr: boolean) => TransformOptions)\r\n | ((source: string, id: string, ssr: boolean) => Promise<TransformOptions>);\r\n typescript: {\r\n /**\r\n * Forcibly enables jsx parsing. Otherwise angle brackets will be treated as\r\n * typescript's legacy type assertion var foo = <string>bar;. Also, isTSX:\r\n * true requires allExtensions: true.\r\n *\r\n * @default false\r\n */\r\n isTSX?: boolean;\r\n\r\n /**\r\n * Replace the function used when compiling JSX expressions. This is so that\r\n * we know that the import is not a type import, and should not be removed.\r\n *\r\n * @default React\r\n */\r\n jsxPragma?: string;\r\n\r\n /**\r\n * Replace the function used when compiling JSX fragment expressions. This\r\n * is so that we know that the import is not a type import, and should not\r\n * be removed.\r\n *\r\n * @default React.Fragment\r\n */\r\n jsxPragmaFrag?: string;\r\n\r\n /**\r\n * Indicates that every file should be parsed as TS or TSX (depending on the\r\n * isTSX option).\r\n *\r\n * @default false\r\n */\r\n allExtensions?: boolean;\r\n\r\n /**\r\n * Enables compilation of TypeScript namespaces.\r\n *\r\n * @default uses the default set by @babel/plugin-transform-typescript.\r\n */\r\n allowNamespaces?: boolean;\r\n\r\n /**\r\n * When enabled, type-only class fields are only removed if they are\r\n * prefixed with the declare modifier:\r\n *\r\n * > NOTE: This will be enabled by default in Babel 8\r\n *\r\n * @default false\r\n *\r\n * @example\r\n * ```ts\r\n * class A {\r\n * declare foo: string; // Removed\r\n * bar: string; // Initialized to undefined\r\n * prop?: string; // Initialized to undefined\r\n * prop1!: string // Initialized to undefined\r\n * }\r\n * ```\r\n */\r\n allowDeclareFields?: boolean;\r\n\r\n /**\r\n * When set to true, the transform will only remove type-only imports\r\n * (introduced in TypeScript 3.8). This should only be used if you are using\r\n * TypeScript >= 3.8.\r\n *\r\n * @default false\r\n */\r\n onlyRemoveTypeImports?: boolean;\r\n\r\n /**\r\n * When set to true, Babel will inline enum values rather than using the\r\n * usual enum output:\r\n *\r\n * This option differs from TypeScript's --isolatedModules behavior, which\r\n * ignores the const modifier and compiles them as normal enums, and aligns\r\n * Babel's behavior with TypeScript's default behavior.\r\n *\r\n * ```ts\r\n * // Input\r\n * const enum Animals {\r\n * Fish\r\n * }\r\n * console.log(Animals.Fish);\r\n *\r\n * // Default output\r\n * var Animals;\r\n *\r\n * (function (Animals) {\r\n * Animals[Animals[\"Fish\"] = 0] = \"Fish\";\r\n * })(Animals || (Animals = {}));\r\n *\r\n * console.log(Animals.Fish);\r\n *\r\n * // `optimizeConstEnums` output\r\n * console.log(0);\r\n * ```\r\n *\r\n * However, when exporting a const enum Babel will compile it to a plain\r\n * object literal so that it doesn't need to rely on cross-file analysis\r\n * when compiling it:\r\n *\r\n * ```ts\r\n * // Input\r\n * export const enum Animals {\r\n * Fish,\r\n * }\r\n *\r\n * // `optimizeConstEnums` output\r\n * export var Animals = {\r\n * Fish: 0,\r\n * };\r\n * ```\r\n *\r\n * @default false\r\n */\r\n optimizeConstEnums?: boolean;\r\n };\r\n /**\r\n * Pass any additional [babel-plugin-jsx-dom-expressions](https://github.com/ryansolid/dom-expressions/tree/main/packages/babel-plugin-jsx-dom-expressions#plugin-options).\r\n * They will be merged with the defaults sets by [babel-preset-solid](https://github.com/solidjs/solid/blob/main/packages/babel-preset-solid/index.js#L8-L25).\r\n *\r\n * @default {}\r\n */\r\n solid: {\r\n /**\r\n * The name of the runtime module to import the methods from.\r\n *\r\n * @default \"solid-js/web\"\r\n */\r\n moduleName?: string;\r\n\r\n /**\r\n * The output mode of the compiler.\r\n * Can be:\r\n * - \"dom\" is standard output\r\n * - \"ssr\" is for server side rendering of strings.\r\n *\r\n * @default \"dom\"\r\n */\r\n generate?: 'ssr' | 'dom';\r\n\r\n /**\r\n * Indicate whether the output should contain hydratable markers.\r\n *\r\n * @default false\r\n */\r\n hydratable?: boolean;\r\n\r\n /**\r\n * Boolean to indicate whether to enable automatic event delegation on camelCase.\r\n *\r\n * @default true\r\n */\r\n delegateEvents?: boolean;\r\n\r\n /**\r\n * Boolean indicates whether smart conditional detection should be used.\r\n * This optimizes simple boolean expressions and ternaries in JSX.\r\n *\r\n * @default true\r\n */\r\n wrapConditionals?: boolean;\r\n\r\n /**\r\n * Boolean indicates whether to set current render context on Custom Elements and slots.\r\n * Useful for seemless Context API with Web Components.\r\n *\r\n * @default true\r\n */\r\n contextToCustomElements?: boolean;\r\n\r\n /**\r\n * Array of Component exports from module, that aren't included by default with the library.\r\n * This plugin will automatically import them if it comes across them in the JSX.\r\n *\r\n * @default [\"For\",\"Show\",\"Switch\",\"Match\",\"Suspense\",\"SuspenseList\",\"Portal\",\"Index\",\"Dynamic\",\"ErrorBoundary\"]\r\n */\r\n builtIns?: string[];\r\n };\r\n}\r\n\r\nexport default function solidPlugin(options: Partial<Options> = {}): Plugin {\r\n let needHmr = false;\r\n\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 const replaceDev = options.dev === true || (options.dev !== false && command === 'serve');\r\n\r\n // TODO: remove when fully removed from vite\r\n const legacyAlias = normalizeAliases(userConfig.alias);\r\n\r\n if (!userConfig.resolve) userConfig.resolve = {};\r\n userConfig.resolve.alias = [...legacyAlias, ...normalizeAliases(userConfig.resolve?.alias)];\r\n\r\n const nestedDeps = [\r\n 'solid-js',\r\n 'solid-js/web',\r\n 'solid-js/store',\r\n 'solid-js/html',\r\n 'solid-js/h',\r\n ];\r\n\r\n return {\r\n /**\r\n * We only need esbuild on .ts or .js files.\r\n * .tsx & .jsx files are handled by us\r\n */\r\n esbuild: { include: /\\.ts$/ },\r\n resolve: {\r\n conditions: ['solid', ...(replaceDev ? ['development'] : [])],\r\n dedupe: nestedDeps,\r\n alias: [{ find: /^solid-refresh$/, replacement: runtimePublicPath }],\r\n },\r\n optimizeDeps: {\r\n include: nestedDeps,\r\n },\r\n } as UserConfig;\r\n },\r\n\r\n configResolved(config) {\r\n needHmr = config.command === 'serve' && !config.isProduction && options.hot !== false;\r\n },\r\n\r\n resolveId(id) {\r\n if (id === runtimePublicPath) return id;\r\n },\r\n\r\n load(id) {\r\n if (id === runtimePublicPath) return runtimeCode;\r\n },\r\n\r\n async transform(source, id, ssr) {\r\n if (!/\\.[jt]sx/.test(id)) return null;\r\n\r\n let solidOptions: { generate: 'ssr' | 'dom'; hydratable: boolean };\r\n\r\n if (options.ssr) {\r\n if (ssr) {\r\n solidOptions = { generate: 'ssr', hydratable: true };\r\n } else {\r\n solidOptions = { generate: 'dom', hydratable: true };\r\n }\r\n } else {\r\n solidOptions = { generate: 'dom', hydratable: false };\r\n }\r\n\r\n const opts: TransformOptions = {\r\n filename: id,\r\n presets: [[solid, { ...solidOptions, ...(options.solid || {}) }]],\r\n plugins: needHmr ? [[solidRefresh, { bundler: 'vite' }]] : [],\r\n };\r\n\r\n if (id.includes('tsx')) {\r\n opts.presets.push([ts, options.typescript || {}]);\r\n }\r\n\r\n // Default value for babel user options\r\n let babelUserOptions: TransformOptions = {};\r\n\r\n if (options.babel) {\r\n if (typeof options.babel === 'function') {\r\n const babelOptions = options.babel(source, id, ssr);\r\n babelUserOptions = babelOptions instanceof Promise ? await babelOptions : babelOptions;\r\n } else {\r\n babelUserOptions = options.babel;\r\n }\r\n }\r\n\r\n const babelOptions = mergeAndConcat(babelUserOptions, opts) as TransformOptions;\r\n\r\n const { code, map } = await transformAsync(source, babelOptions);\r\n\r\n return { code, map };\r\n },\r\n };\r\n}\r\n\r\n/**\r\n * This basically normalize all aliases of the config into\r\n * the array format of the alias.\r\n *\r\n * eg: alias: { '@': 'src/' } => [{ find: '@', replacement: 'src/' }]\r\n */\r\nfunction normalizeAliases(alias: AliasOptions = []): Alias[] {\r\n return Array.isArray(alias)\r\n ? alias\r\n : Object.entries(alias).map(([find, replacement]) => ({ find, replacement }));\r\n}\r\n"],"names":["require","createRequire","import","runtimePublicPath","runtimeFilePath","resolve","runtimeCode","readFileSync","solidPlugin","options","needHmr","name","enforce","config","userConfig","command","replaceDev","dev","legacyAlias","normalizeAliases","alias","nestedDeps","esbuild","include","conditions","dedupe","find","replacement","optimizeDeps","configResolved","isProduction","hot","resolveId","id","load","transform","source","ssr","test","solidOptions","generate","hydratable","opts","filename","presets","solid","plugins","solidRefresh","bundler","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;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;AACA,YAAMC,UAAU,GAAGP,OAAO,CAACQ,GAAR,KAAgB,IAAhB,IAAyBR,OAAO,CAACQ,GAAR,KAAgB,KAAhB,IAAyBF,OAAO,KAAK,OAAjF,CAF0C;;AAK1C,YAAMG,WAAW,GAAGC,gBAAgB,CAACL,UAAU,CAACM,KAAZ,CAApC;AAEA,UAAI,CAACN,UAAU,CAACT,OA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C;AACvC,gBAAMC,YAAY,GAAG9C,OAAO,CAAC6C,KAAR,CAAclB,MAAd,EAAsBH,EAAtB,EAA0BI,GAA1B,CAArB;AACAgB,UAAAA,gBAAgB,GAAGE,YAAY,YAAYC,OAAxB,GAAkC,MAAMD,YAAxC,GAAuDA,YAA1E;AACD,SAHD,MAGO;AACLF,UAAAA,gBAAgB,GAAG5C,OAAO,CAAC6C,KAA3B;AACD;AACF;;AAED,YAAMC,YAAY,GAAGE,4BAAc,CAACJ,gBAAD,EAAmBX,IAAnB,CAAnC;AAEA,YAAM;AAAEgB,QAAAA,IAAF;AAAQC,QAAAA;AAAR,UAAgB,MAAMC,mBAAc,CAACxB,MAAD,EAASmB,YAAT,CAA1C;AAEA,aAAO;AAAEG,QAAAA,IAAF;AAAQC,QAAAA;AAAR,OAAP;AACD;;AA7FI,GAAP;AA+FD;AAED;AACA;AACA;AACA;AACA;AACA;;AACA,SAASxC,gBAAT,CAA0BC,KAAmB,GAAG,EAAhD,EAA6D;AAC3D,SAAOyC,KAAK,CAACC,OAAN,CAAc1C,KAAd,IACHA,KADG,GAEH2C,MAAM,CAACC,OAAP,CAAe5C,KAAf,EAAsBuC,GAAtB,CAA0B,CAAC,CAACjC,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/** 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,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,CAACb,OAAhB,EAAyBa,UAAU,CAACb,OAAX,GAAqB,EAArB;AACzBa,M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AAQC,IAAAA;AAAR,GAA1B,CAA1B,CAFJ;AAGD;;;;"}
|
package/dist/esm/index.mjs
CHANGED
|
@@ -17,6 +17,8 @@ const runtimeCode = readFileSync(runtimeFilePath, 'utf-8');
|
|
|
17
17
|
|
|
18
18
|
function solidPlugin(options = {}) {
|
|
19
19
|
let needHmr = false;
|
|
20
|
+
let replaceDev = false;
|
|
21
|
+
let projectRoot = process.cwd();
|
|
20
22
|
return {
|
|
21
23
|
name: 'solid',
|
|
22
24
|
enforce: 'pre',
|
|
@@ -27,16 +29,18 @@ function solidPlugin(options = {}) {
|
|
|
27
29
|
var _userConfig$resolve;
|
|
28
30
|
|
|
29
31
|
// We inject the dev mode only if the user explicitely wants it or if we are in dev (serve) mode
|
|
30
|
-
|
|
32
|
+
replaceDev = options.dev === true || options.dev !== false && command === 'serve';
|
|
33
|
+
projectRoot = userConfig.root; // TODO: remove when fully removed from vite
|
|
31
34
|
|
|
32
35
|
const legacyAlias = normalizeAliases(userConfig.alias);
|
|
33
36
|
if (!userConfig.resolve) userConfig.resolve = {};
|
|
34
|
-
userConfig.resolve.alias = [...legacyAlias, ...normalizeAliases((_userConfig$resolve = userConfig.resolve) === null || _userConfig$resolve === void 0 ? void 0 : _userConfig$resolve.alias)];
|
|
35
|
-
|
|
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
|
|
38
|
+
|
|
39
|
+
const nestedDeps = replaceDev ? ['solid-js', 'solid-js/web', 'solid-js/store', 'solid-js/html', 'solid-js/h'] : [];
|
|
36
40
|
return {
|
|
37
|
-
/**
|
|
38
|
-
* We only need esbuild on .ts or .js files.
|
|
39
|
-
* .tsx & .jsx files are handled by us
|
|
41
|
+
/**
|
|
42
|
+
* We only need esbuild on .ts or .js files.
|
|
43
|
+
* .tsx & .jsx files are handled by us
|
|
40
44
|
*/
|
|
41
45
|
esbuild: {
|
|
42
46
|
include: /\.ts$/
|
|
@@ -67,8 +71,12 @@ function solidPlugin(options = {}) {
|
|
|
67
71
|
if (id === runtimePublicPath) return runtimeCode;
|
|
68
72
|
},
|
|
69
73
|
|
|
70
|
-
async transform(source, id,
|
|
74
|
+
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);
|
|
71
78
|
if (!/\.[jt]sx/.test(id)) return null;
|
|
79
|
+
const inNodeModules = /node_modules/.test(id);
|
|
72
80
|
let solidOptions;
|
|
73
81
|
|
|
74
82
|
if (options.ssr) {
|
|
@@ -91,13 +99,20 @@ function solidPlugin(options = {}) {
|
|
|
91
99
|
}
|
|
92
100
|
|
|
93
101
|
const opts = {
|
|
102
|
+
babelrc: false,
|
|
103
|
+
configFile: false,
|
|
104
|
+
root: projectRoot,
|
|
94
105
|
filename: id,
|
|
106
|
+
sourceFileName: id,
|
|
95
107
|
presets: [[solid, { ...solidOptions,
|
|
96
108
|
...(options.solid || {})
|
|
97
109
|
}]],
|
|
98
|
-
plugins: needHmr ? [[solidRefresh, {
|
|
110
|
+
plugins: needHmr && !inNodeModules ? [[solidRefresh, {
|
|
99
111
|
bundler: 'vite'
|
|
100
|
-
}]] : []
|
|
112
|
+
}]] : [],
|
|
113
|
+
sourceMaps: true,
|
|
114
|
+
// Vite handles sourcemap flattening
|
|
115
|
+
inputSourceMap: false
|
|
101
116
|
};
|
|
102
117
|
|
|
103
118
|
if (id.includes('tsx')) {
|
|
@@ -129,11 +144,11 @@ function solidPlugin(options = {}) {
|
|
|
129
144
|
|
|
130
145
|
};
|
|
131
146
|
}
|
|
132
|
-
/**
|
|
133
|
-
* This basically normalize all aliases of the config into
|
|
134
|
-
* the array format of the alias.
|
|
135
|
-
*
|
|
136
|
-
* eg: alias: { '@': 'src/' } => [{ find: '@', replacement: 'src/' }]
|
|
147
|
+
/**
|
|
148
|
+
* This basically normalize all aliases of the config into
|
|
149
|
+
* the array format of the alias.
|
|
150
|
+
*
|
|
151
|
+
* eg: alias: { '@': 'src/' } => [{ find: '@', replacement: 'src/' }]
|
|
137
152
|
*/
|
|
138
153
|
|
|
139
154
|
function normalizeAliases(alias = []) {
|
package/dist/esm/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../../src/index.ts"],"sourcesContent":["import { transformAsync, TransformOptions } from '@babel/core';\r\nimport ts from '@babel/preset-typescript';\r\nimport solid from 'babel-preset-solid';\r\nimport { readFileSync } from 'fs';\r\nimport { mergeAndConcat } from 'merge-anything';\r\nimport { createRequire } from 'module';\r\nimport solidRefresh from 'solid-refresh/babel.js';\r\nimport type { Alias, AliasOptions, Plugin, UserConfig } from 'vite';\r\n\r\nconst require = createRequire(import.meta.url);\r\n\r\nconst runtimePublicPath = '/@solid-refresh';\r\nconst runtimeFilePath = require.resolve('solid-refresh/dist/solid-refresh.mjs');\r\nconst runtimeCode = readFileSync(runtimeFilePath, 'utf-8');\r\n\r\n/** Configuration options for vite-plugin-solid. */\r\nexport interface Options {\r\n /**\r\n * This will inject solid-js/dev in place of solid-js in dev mode. Has no\r\n * effect in prod. If set to `false`, it won't inject it in dev. This is\r\n * useful for extra logs and debugging.\r\n *\r\n * @default true\r\n */\r\n dev: boolean;\r\n /**\r\n * This will force SSR code in the produced files. This is experiemental\r\n * and mostly not working yet.\r\n *\r\n * @default false\r\n */\r\n ssr: boolean;\r\n /**\r\n * This will inject HMR runtime in dev mode. Has no effect in prod. If\r\n * set to `false`, it won't inject the runtime in dev.\r\n *\r\n * @default true\r\n */\r\n hot: boolean;\r\n /**\r\n * Pass any additional babel transform options. They will be merged with\r\n * the transformations required by Solid.\r\n *\r\n * @default {}\r\n */\r\n babel:\r\n | TransformOptions\r\n | ((source: string, id: string, ssr: boolean) => TransformOptions)\r\n | ((source: string, id: string, ssr: boolean) => Promise<TransformOptions>);\r\n typescript: {\r\n /**\r\n * Forcibly enables jsx parsing. Otherwise angle brackets will be treated as\r\n * typescript's legacy type assertion var foo = <string>bar;. Also, isTSX:\r\n * true requires allExtensions: true.\r\n *\r\n * @default false\r\n */\r\n isTSX?: boolean;\r\n\r\n /**\r\n * Replace the function used when compiling JSX expressions. This is so that\r\n * we know that the import is not a type import, and should not be removed.\r\n *\r\n * @default React\r\n */\r\n jsxPragma?: string;\r\n\r\n /**\r\n * Replace the function used when compiling JSX fragment expressions. This\r\n * is so that we know that the import is not a type import, and should not\r\n * be removed.\r\n *\r\n * @default React.Fragment\r\n */\r\n jsxPragmaFrag?: string;\r\n\r\n /**\r\n * Indicates that every file should be parsed as TS or TSX (depending on the\r\n * isTSX option).\r\n *\r\n * @default false\r\n */\r\n allExtensions?: boolean;\r\n\r\n /**\r\n * Enables compilation of TypeScript namespaces.\r\n *\r\n * @default uses the default set by @babel/plugin-transform-typescript.\r\n */\r\n allowNamespaces?: boolean;\r\n\r\n /**\r\n * When enabled, type-only class fields are only removed if they are\r\n * prefixed with the declare modifier:\r\n *\r\n * > NOTE: This will be enabled by default in Babel 8\r\n *\r\n * @default false\r\n *\r\n * @example\r\n * ```ts\r\n * class A {\r\n * declare foo: string; // Removed\r\n * bar: string; // Initialized to undefined\r\n * prop?: string; // Initialized to undefined\r\n * prop1!: string // Initialized to undefined\r\n * }\r\n * ```\r\n */\r\n allowDeclareFields?: boolean;\r\n\r\n /**\r\n * When set to true, the transform will only remove type-only imports\r\n * (introduced in TypeScript 3.8). This should only be used if you are using\r\n * TypeScript >= 3.8.\r\n *\r\n * @default false\r\n */\r\n onlyRemoveTypeImports?: boolean;\r\n\r\n /**\r\n * When set to true, Babel will inline enum values rather than using the\r\n * usual enum output:\r\n *\r\n * This option differs from TypeScript's --isolatedModules behavior, which\r\n * ignores the const modifier and compiles them as normal enums, and aligns\r\n * Babel's behavior with TypeScript's default behavior.\r\n *\r\n * ```ts\r\n * // Input\r\n * const enum Animals {\r\n * Fish\r\n * }\r\n * console.log(Animals.Fish);\r\n *\r\n * // Default output\r\n * var Animals;\r\n *\r\n * (function (Animals) {\r\n * Animals[Animals[\"Fish\"] = 0] = \"Fish\";\r\n * })(Animals || (Animals = {}));\r\n *\r\n * console.log(Animals.Fish);\r\n *\r\n * // `optimizeConstEnums` output\r\n * console.log(0);\r\n * ```\r\n *\r\n * However, when exporting a const enum Babel will compile it to a plain\r\n * object literal so that it doesn't need to rely on cross-file analysis\r\n * when compiling it:\r\n *\r\n * ```ts\r\n * // Input\r\n * export const enum Animals {\r\n * Fish,\r\n * }\r\n *\r\n * // `optimizeConstEnums` output\r\n * export var Animals = {\r\n * Fish: 0,\r\n * };\r\n * ```\r\n *\r\n * @default false\r\n */\r\n optimizeConstEnums?: boolean;\r\n };\r\n /**\r\n * Pass any additional [babel-plugin-jsx-dom-expressions](https://github.com/ryansolid/dom-expressions/tree/main/packages/babel-plugin-jsx-dom-expressions#plugin-options).\r\n * They will be merged with the defaults sets by [babel-preset-solid](https://github.com/solidjs/solid/blob/main/packages/babel-preset-solid/index.js#L8-L25).\r\n *\r\n * @default {}\r\n */\r\n solid: {\r\n /**\r\n * The name of the runtime module to import the methods from.\r\n *\r\n * @default \"solid-js/web\"\r\n */\r\n moduleName?: string;\r\n\r\n /**\r\n * The output mode of the compiler.\r\n * Can be:\r\n * - \"dom\" is standard output\r\n * - \"ssr\" is for server side rendering of strings.\r\n *\r\n * @default \"dom\"\r\n */\r\n generate?: 'ssr' | 'dom';\r\n\r\n /**\r\n * Indicate whether the output should contain hydratable markers.\r\n *\r\n * @default false\r\n */\r\n hydratable?: boolean;\r\n\r\n /**\r\n * Boolean to indicate whether to enable automatic event delegation on camelCase.\r\n *\r\n * @default true\r\n */\r\n delegateEvents?: boolean;\r\n\r\n /**\r\n * Boolean indicates whether smart conditional detection should be used.\r\n * This optimizes simple boolean expressions and ternaries in JSX.\r\n *\r\n * @default true\r\n */\r\n wrapConditionals?: boolean;\r\n\r\n /**\r\n * Boolean indicates whether to set current render context on Custom Elements and slots.\r\n * Useful for seemless Context API with Web Components.\r\n *\r\n * @default true\r\n */\r\n contextToCustomElements?: boolean;\r\n\r\n /**\r\n * Array of Component exports from module, that aren't included by default with the library.\r\n * This plugin will automatically import them if it comes across them in the JSX.\r\n *\r\n * @default [\"For\",\"Show\",\"Switch\",\"Match\",\"Suspense\",\"SuspenseList\",\"Portal\",\"Index\",\"Dynamic\",\"ErrorBoundary\"]\r\n */\r\n builtIns?: string[];\r\n };\r\n}\r\n\r\nexport default function solidPlugin(options: Partial<Options> = {}): Plugin {\r\n let needHmr = false;\r\n\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 const replaceDev = options.dev === true || (options.dev !== false && command === 'serve');\r\n\r\n // TODO: remove when fully removed from vite\r\n const legacyAlias = normalizeAliases(userConfig.alias);\r\n\r\n if (!userConfig.resolve) userConfig.resolve = {};\r\n userConfig.resolve.alias = [...legacyAlias, ...normalizeAliases(userConfig.resolve?.alias)];\r\n\r\n const nestedDeps = [\r\n 'solid-js',\r\n 'solid-js/web',\r\n 'solid-js/store',\r\n 'solid-js/html',\r\n 'solid-js/h',\r\n ];\r\n\r\n return {\r\n /**\r\n * We only need esbuild on .ts or .js files.\r\n * .tsx & .jsx files are handled by us\r\n */\r\n esbuild: { include: /\\.ts$/ },\r\n resolve: {\r\n conditions: ['solid', ...(replaceDev ? ['development'] : [])],\r\n dedupe: nestedDeps,\r\n alias: [{ find: /^solid-refresh$/, replacement: runtimePublicPath }],\r\n },\r\n optimizeDeps: {\r\n include: nestedDeps,\r\n },\r\n } as UserConfig;\r\n },\r\n\r\n configResolved(config) {\r\n needHmr = config.command === 'serve' && !config.isProduction && options.hot !== false;\r\n },\r\n\r\n resolveId(id) {\r\n if (id === runtimePublicPath) return id;\r\n },\r\n\r\n load(id) {\r\n if (id === runtimePublicPath) return runtimeCode;\r\n },\r\n\r\n async transform(source, id, ssr) {\r\n if (!/\\.[jt]sx/.test(id)) return null;\r\n\r\n let solidOptions: { generate: 'ssr' | 'dom'; hydratable: boolean };\r\n\r\n if (options.ssr) {\r\n if (ssr) {\r\n solidOptions = { generate: 'ssr', hydratable: true };\r\n } else {\r\n solidOptions = { generate: 'dom', hydratable: true };\r\n }\r\n } else {\r\n solidOptions = { generate: 'dom', hydratable: false };\r\n }\r\n\r\n const opts: TransformOptions = {\r\n filename: id,\r\n presets: [[solid, { ...solidOptions, ...(options.solid || {}) }]],\r\n plugins: needHmr ? [[solidRefresh, { bundler: 'vite' }]] : [],\r\n };\r\n\r\n if (id.includes('tsx')) {\r\n opts.presets.push([ts, options.typescript || {}]);\r\n }\r\n\r\n // Default value for babel user options\r\n let babelUserOptions: TransformOptions = {};\r\n\r\n if (options.babel) {\r\n if (typeof options.babel === 'function') {\r\n const babelOptions = options.babel(source, id, ssr);\r\n babelUserOptions = babelOptions instanceof Promise ? await babelOptions : babelOptions;\r\n } else {\r\n babelUserOptions = options.babel;\r\n }\r\n }\r\n\r\n const babelOptions = mergeAndConcat(babelUserOptions, opts) as TransformOptions;\r\n\r\n const { code, map } = await transformAsync(source, babelOptions);\r\n\r\n return { code, map };\r\n },\r\n };\r\n}\r\n\r\n/**\r\n * This basically normalize all aliases of the config into\r\n * the array format of the alias.\r\n *\r\n * eg: alias: { '@': 'src/' } => [{ find: '@', replacement: 'src/' }]\r\n */\r\nfunction normalizeAliases(alias: AliasOptions = []): Alias[] {\r\n return Array.isArray(alias)\r\n ? alias\r\n : Object.entries(alias).map(([find, replacement]) => ({ find, replacement }));\r\n}\r\n"],"names":["require","createRequire","import","meta","url","runtimePublicPath","runtimeFilePath","resolve","runtimeCode","readFileSync","solidPlugin","options","needHmr","name","enforce","config","userConfig","command","replaceDev","dev","legacyAlias","normalizeAliases","alias","nestedDeps","esbuild","include","conditions","dedupe","find","replacement","optimizeDeps","configResolved","isProduction","hot","resolveId","id","load","transform","source","ssr","test","solidOptions","generate","hydratable","opts","filename","presets","solid","plugins","solidRefresh","bundler","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;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;AACA,YAAMC,UAAU,GAAGP,OAAO,CAACQ,GAAR,KAAgB,IAAhB,IAAyBR,OAAO,CAACQ,GAAR,KAAgB,KAAhB,IAAyBF,OAAO,KAAK,OAAjF,CAF0C;;AAK1C,YAAMG,WAAW,GAAGC,gBAAgB,CAACL,UAAU,CAACM,KAAZ,CAApC;AAEA,UAAI,CAACN,UAAU,CAACT,OAAhB,EAAyBS,UAAU,CAACT,OAAX,GAAqB,EAArB;AACzBS,MAAAA,UAAU,CAACT,OAAX,CAAmBe,KAAnB,GAA2B,CAAC,GAAGF,WAAJ,EAAiB,GAAGC,gBAAgB,wBAACL,UAAU,CAACT,OAAZ,wDAAC,oBAAoBe,KAArB,CAApC,CAA3B;AAEA,YAAMC,UAAU,GAAG,CACjB,UADiB,EAEjB,cAFiB,EAGjB,gBAHiB,EAIjB,eAJiB,EAKjB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Ac,CAACJ,gBAAD,EAAmBX,IAAnB,CAAnC;AAEA,YAAM;AAAEgB,QAAAA,IAAF;AAAQC,QAAAA;AAAR,UAAgB,MAAMC,cAAc,CAACxB,MAAD,EAASmB,YAAT,CAA1C;AAEA,aAAO;AAAEG,QAAAA,IAAF;AAAQC,QAAAA;AAAR,OAAP;AACD;;AA7FI,GAAP;AA+FD;AAED;AACA;AACA;AACA;AACA;AACA;;AACA,SAASxC,gBAAT,CAA0BC,KAAmB,GAAG,EAAhD,EAA6D;AAC3D,SAAOyC,KAAK,CAACC,OAAN,CAAc1C,KAAd,IACHA,KADG,GAEH2C,MAAM,CAACC,OAAP,CAAe5C,KAAf,EAAsBuC,GAAtB,CAA0B,CAAC,CAACjC,IAAD,EAAOC,WAAP,CAAD,MAA0B;AAAED,IAAAA,IAAF;AAAQC,IAAAA;AAAR,GAA1B,CAA1B,CAFJ;AAGD;;;;"}
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../../src/index.ts"],"sourcesContent":["import { transformAsync, TransformOptions } from '@babel/core';\nimport ts from '@babel/preset-typescript';\nimport solid from 'babel-preset-solid';\nimport { readFileSync } from 'fs';\nimport { mergeAndConcat } from 'merge-anything';\nimport { createRequire } from 'module';\nimport solidRefresh from 'solid-refresh/babel.js';\nimport type { Alias, AliasOptions, Plugin, UserConfig } from 'vite';\n\nconst require = createRequire(import.meta.url);\n\nconst runtimePublicPath = '/@solid-refresh';\nconst runtimeFilePath = require.resolve('solid-refresh/dist/solid-refresh.mjs');\nconst runtimeCode = readFileSync(runtimeFilePath, 'utf-8');\n\n/** 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","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C5C,UAAIC,gBAAkC,GAAG,EAAzC;;AAEA,UAAIvD,OAAO,CAACwD,KAAZ,EAAmB;AACjB,YAAI,OAAOxD,OAAO,CAACwD,KAAf,KAAyB,UAA7B,EAAyC;AACvC,gBAAMC,YAAY,GAAGzD,OAAO,CAACwD,KAAR,CAAczB,MAAd,EAAsBH,EAAtB,EAA0BK,GAA1B,CAArB;AACAsB,UAAAA,gBAAgB,GAAGE,YAAY,YAAYC,OAAxB,GAAkC,MAAMD,YAAxC,GAAuDA,YAA1E;AACD,SAHD,MAGO;AACLF,UAAAA,gBAAgB,GAAGvD,OAAO,CAACwD,KAA3B;AACD;AACF;;AAED,YAAMC,YAAY,GAAGE,cAAc,CAACJ,gBAAD,EAAmBhB,IAAnB,CAAnC;AAEA,YAAM;AAAEqB,QAAAA,IAAF;AAAQC,QAAAA;AAAR,UAAgB,MAAMC,cAAc,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;;;;"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,203 +1,203 @@
|
|
|
1
|
-
import { TransformOptions } from '@babel/core';
|
|
2
|
-
import type { Plugin } from 'vite';
|
|
3
|
-
/** Configuration options for vite-plugin-solid. */
|
|
4
|
-
export interface Options {
|
|
5
|
-
/**
|
|
6
|
-
* This will inject solid-js/dev in place of solid-js in dev mode. Has no
|
|
7
|
-
* effect in prod. If set to `false`, it won't inject it in dev. This is
|
|
8
|
-
* useful for extra logs and debugging.
|
|
9
|
-
*
|
|
10
|
-
* @default true
|
|
11
|
-
*/
|
|
12
|
-
dev: boolean;
|
|
13
|
-
/**
|
|
14
|
-
* This will force SSR code in the produced files. This is experiemental
|
|
15
|
-
* and mostly not working yet.
|
|
16
|
-
*
|
|
17
|
-
* @default false
|
|
18
|
-
*/
|
|
19
|
-
ssr: boolean;
|
|
20
|
-
/**
|
|
21
|
-
* This will inject HMR runtime in dev mode. Has no effect in prod. If
|
|
22
|
-
* set to `false`, it won't inject the runtime in dev.
|
|
23
|
-
*
|
|
24
|
-
* @default true
|
|
25
|
-
*/
|
|
26
|
-
hot: boolean;
|
|
27
|
-
/**
|
|
28
|
-
* Pass any additional babel transform options. They will be merged with
|
|
29
|
-
* the transformations required by Solid.
|
|
30
|
-
*
|
|
31
|
-
* @default {}
|
|
32
|
-
*/
|
|
33
|
-
babel: TransformOptions | ((source: string, id: string, ssr: boolean) => TransformOptions) | ((source: string, id: string, ssr: boolean) => Promise<TransformOptions>);
|
|
34
|
-
typescript: {
|
|
35
|
-
/**
|
|
36
|
-
* Forcibly enables jsx parsing. Otherwise angle brackets will be treated as
|
|
37
|
-
* typescript's legacy type assertion var foo = <string>bar;. Also, isTSX:
|
|
38
|
-
* true requires allExtensions: true.
|
|
39
|
-
*
|
|
40
|
-
* @default false
|
|
41
|
-
*/
|
|
42
|
-
isTSX?: boolean;
|
|
43
|
-
/**
|
|
44
|
-
* Replace the function used when compiling JSX expressions. This is so that
|
|
45
|
-
* we know that the import is not a type import, and should not be removed.
|
|
46
|
-
*
|
|
47
|
-
* @default React
|
|
48
|
-
*/
|
|
49
|
-
jsxPragma?: string;
|
|
50
|
-
/**
|
|
51
|
-
* Replace the function used when compiling JSX fragment expressions. This
|
|
52
|
-
* is so that we know that the import is not a type import, and should not
|
|
53
|
-
* be removed.
|
|
54
|
-
*
|
|
55
|
-
* @default React.Fragment
|
|
56
|
-
*/
|
|
57
|
-
jsxPragmaFrag?: string;
|
|
58
|
-
/**
|
|
59
|
-
* Indicates that every file should be parsed as TS or TSX (depending on the
|
|
60
|
-
* isTSX option).
|
|
61
|
-
*
|
|
62
|
-
* @default false
|
|
63
|
-
*/
|
|
64
|
-
allExtensions?: boolean;
|
|
65
|
-
/**
|
|
66
|
-
* Enables compilation of TypeScript namespaces.
|
|
67
|
-
*
|
|
68
|
-
* @default uses the default set by @babel/plugin-transform-typescript.
|
|
69
|
-
*/
|
|
70
|
-
allowNamespaces?: boolean;
|
|
71
|
-
/**
|
|
72
|
-
* When enabled, type-only class fields are only removed if they are
|
|
73
|
-
* prefixed with the declare modifier:
|
|
74
|
-
*
|
|
75
|
-
* > NOTE: This will be enabled by default in Babel 8
|
|
76
|
-
*
|
|
77
|
-
* @default false
|
|
78
|
-
*
|
|
79
|
-
* @example
|
|
80
|
-
* ```ts
|
|
81
|
-
* class A {
|
|
82
|
-
* declare foo: string; // Removed
|
|
83
|
-
* bar: string; // Initialized to undefined
|
|
84
|
-
* prop?: string; // Initialized to undefined
|
|
85
|
-
* prop1!: string // Initialized to undefined
|
|
86
|
-
* }
|
|
87
|
-
* ```
|
|
88
|
-
*/
|
|
89
|
-
allowDeclareFields?: boolean;
|
|
90
|
-
/**
|
|
91
|
-
* When set to true, the transform will only remove type-only imports
|
|
92
|
-
* (introduced in TypeScript 3.8). This should only be used if you are using
|
|
93
|
-
* TypeScript >= 3.8.
|
|
94
|
-
*
|
|
95
|
-
* @default false
|
|
96
|
-
*/
|
|
97
|
-
onlyRemoveTypeImports?: boolean;
|
|
98
|
-
/**
|
|
99
|
-
* When set to true, Babel will inline enum values rather than using the
|
|
100
|
-
* usual enum output:
|
|
101
|
-
*
|
|
102
|
-
* This option differs from TypeScript's --isolatedModules behavior, which
|
|
103
|
-
* ignores the const modifier and compiles them as normal enums, and aligns
|
|
104
|
-
* Babel's behavior with TypeScript's default behavior.
|
|
105
|
-
*
|
|
106
|
-
* ```ts
|
|
107
|
-
* // Input
|
|
108
|
-
* const enum Animals {
|
|
109
|
-
* Fish
|
|
110
|
-
* }
|
|
111
|
-
* console.log(Animals.Fish);
|
|
112
|
-
*
|
|
113
|
-
* // Default output
|
|
114
|
-
* var Animals;
|
|
115
|
-
*
|
|
116
|
-
* (function (Animals) {
|
|
117
|
-
* Animals[Animals["Fish"] = 0] = "Fish";
|
|
118
|
-
* })(Animals || (Animals = {}));
|
|
119
|
-
*
|
|
120
|
-
* console.log(Animals.Fish);
|
|
121
|
-
*
|
|
122
|
-
* // `optimizeConstEnums` output
|
|
123
|
-
* console.log(0);
|
|
124
|
-
* ```
|
|
125
|
-
*
|
|
126
|
-
* However, when exporting a const enum Babel will compile it to a plain
|
|
127
|
-
* object literal so that it doesn't need to rely on cross-file analysis
|
|
128
|
-
* when compiling it:
|
|
129
|
-
*
|
|
130
|
-
* ```ts
|
|
131
|
-
* // Input
|
|
132
|
-
* export const enum Animals {
|
|
133
|
-
* Fish,
|
|
134
|
-
* }
|
|
135
|
-
*
|
|
136
|
-
* // `optimizeConstEnums` output
|
|
137
|
-
* export var Animals = {
|
|
138
|
-
* Fish: 0,
|
|
139
|
-
* };
|
|
140
|
-
* ```
|
|
141
|
-
*
|
|
142
|
-
* @default false
|
|
143
|
-
*/
|
|
144
|
-
optimizeConstEnums?: boolean;
|
|
145
|
-
};
|
|
146
|
-
/**
|
|
147
|
-
* Pass any additional [babel-plugin-jsx-dom-expressions](https://github.com/ryansolid/dom-expressions/tree/main/packages/babel-plugin-jsx-dom-expressions#plugin-options).
|
|
148
|
-
* They will be merged with the defaults sets by [babel-preset-solid](https://github.com/solidjs/solid/blob/main/packages/babel-preset-solid/index.js#L8-L25).
|
|
149
|
-
*
|
|
150
|
-
* @default {}
|
|
151
|
-
*/
|
|
152
|
-
solid: {
|
|
153
|
-
/**
|
|
154
|
-
* The name of the runtime module to import the methods from.
|
|
155
|
-
*
|
|
156
|
-
* @default "solid-js/web"
|
|
157
|
-
*/
|
|
158
|
-
moduleName?: string;
|
|
159
|
-
/**
|
|
160
|
-
* The output mode of the compiler.
|
|
161
|
-
* Can be:
|
|
162
|
-
* - "dom" is standard output
|
|
163
|
-
* - "ssr" is for server side rendering of strings.
|
|
164
|
-
*
|
|
165
|
-
* @default "dom"
|
|
166
|
-
*/
|
|
167
|
-
generate?: 'ssr' | 'dom';
|
|
168
|
-
/**
|
|
169
|
-
* Indicate whether the output should contain hydratable markers.
|
|
170
|
-
*
|
|
171
|
-
* @default false
|
|
172
|
-
*/
|
|
173
|
-
hydratable?: boolean;
|
|
174
|
-
/**
|
|
175
|
-
* Boolean to indicate whether to enable automatic event delegation on camelCase.
|
|
176
|
-
*
|
|
177
|
-
* @default true
|
|
178
|
-
*/
|
|
179
|
-
delegateEvents?: boolean;
|
|
180
|
-
/**
|
|
181
|
-
* Boolean indicates whether smart conditional detection should be used.
|
|
182
|
-
* This optimizes simple boolean expressions and ternaries in JSX.
|
|
183
|
-
*
|
|
184
|
-
* @default true
|
|
185
|
-
*/
|
|
186
|
-
wrapConditionals?: boolean;
|
|
187
|
-
/**
|
|
188
|
-
* Boolean indicates whether to set current render context on Custom Elements and slots.
|
|
189
|
-
* Useful for seemless Context API with Web Components.
|
|
190
|
-
*
|
|
191
|
-
* @default true
|
|
192
|
-
*/
|
|
193
|
-
contextToCustomElements?: boolean;
|
|
194
|
-
/**
|
|
195
|
-
* Array of Component exports from module, that aren't included by default with the library.
|
|
196
|
-
* This plugin will automatically import them if it comes across them in the JSX.
|
|
197
|
-
*
|
|
198
|
-
* @default ["For","Show","Switch","Match","Suspense","SuspenseList","Portal","Index","Dynamic","ErrorBoundary"]
|
|
199
|
-
*/
|
|
200
|
-
builtIns?: string[];
|
|
201
|
-
};
|
|
202
|
-
}
|
|
203
|
-
export default function solidPlugin(options?: Partial<Options>): Plugin;
|
|
1
|
+
import { TransformOptions } from '@babel/core';
|
|
2
|
+
import type { Plugin } from 'vite';
|
|
3
|
+
/** Configuration options for vite-plugin-solid. */
|
|
4
|
+
export interface Options {
|
|
5
|
+
/**
|
|
6
|
+
* This will inject solid-js/dev in place of solid-js in dev mode. Has no
|
|
7
|
+
* effect in prod. If set to `false`, it won't inject it in dev. This is
|
|
8
|
+
* useful for extra logs and debugging.
|
|
9
|
+
*
|
|
10
|
+
* @default true
|
|
11
|
+
*/
|
|
12
|
+
dev: boolean;
|
|
13
|
+
/**
|
|
14
|
+
* This will force SSR code in the produced files. This is experiemental
|
|
15
|
+
* and mostly not working yet.
|
|
16
|
+
*
|
|
17
|
+
* @default false
|
|
18
|
+
*/
|
|
19
|
+
ssr: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* This will inject HMR runtime in dev mode. Has no effect in prod. If
|
|
22
|
+
* set to `false`, it won't inject the runtime in dev.
|
|
23
|
+
*
|
|
24
|
+
* @default true
|
|
25
|
+
*/
|
|
26
|
+
hot: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Pass any additional babel transform options. They will be merged with
|
|
29
|
+
* the transformations required by Solid.
|
|
30
|
+
*
|
|
31
|
+
* @default {}
|
|
32
|
+
*/
|
|
33
|
+
babel: TransformOptions | ((source: string, id: string, ssr: boolean) => TransformOptions) | ((source: string, id: string, ssr: boolean) => Promise<TransformOptions>);
|
|
34
|
+
typescript: {
|
|
35
|
+
/**
|
|
36
|
+
* Forcibly enables jsx parsing. Otherwise angle brackets will be treated as
|
|
37
|
+
* typescript's legacy type assertion var foo = <string>bar;. Also, isTSX:
|
|
38
|
+
* true requires allExtensions: true.
|
|
39
|
+
*
|
|
40
|
+
* @default false
|
|
41
|
+
*/
|
|
42
|
+
isTSX?: boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Replace the function used when compiling JSX expressions. This is so that
|
|
45
|
+
* we know that the import is not a type import, and should not be removed.
|
|
46
|
+
*
|
|
47
|
+
* @default React
|
|
48
|
+
*/
|
|
49
|
+
jsxPragma?: string;
|
|
50
|
+
/**
|
|
51
|
+
* Replace the function used when compiling JSX fragment expressions. This
|
|
52
|
+
* is so that we know that the import is not a type import, and should not
|
|
53
|
+
* be removed.
|
|
54
|
+
*
|
|
55
|
+
* @default React.Fragment
|
|
56
|
+
*/
|
|
57
|
+
jsxPragmaFrag?: string;
|
|
58
|
+
/**
|
|
59
|
+
* Indicates that every file should be parsed as TS or TSX (depending on the
|
|
60
|
+
* isTSX option).
|
|
61
|
+
*
|
|
62
|
+
* @default false
|
|
63
|
+
*/
|
|
64
|
+
allExtensions?: boolean;
|
|
65
|
+
/**
|
|
66
|
+
* Enables compilation of TypeScript namespaces.
|
|
67
|
+
*
|
|
68
|
+
* @default uses the default set by @babel/plugin-transform-typescript.
|
|
69
|
+
*/
|
|
70
|
+
allowNamespaces?: boolean;
|
|
71
|
+
/**
|
|
72
|
+
* When enabled, type-only class fields are only removed if they are
|
|
73
|
+
* prefixed with the declare modifier:
|
|
74
|
+
*
|
|
75
|
+
* > NOTE: This will be enabled by default in Babel 8
|
|
76
|
+
*
|
|
77
|
+
* @default false
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* ```ts
|
|
81
|
+
* class A {
|
|
82
|
+
* declare foo: string; // Removed
|
|
83
|
+
* bar: string; // Initialized to undefined
|
|
84
|
+
* prop?: string; // Initialized to undefined
|
|
85
|
+
* prop1!: string // Initialized to undefined
|
|
86
|
+
* }
|
|
87
|
+
* ```
|
|
88
|
+
*/
|
|
89
|
+
allowDeclareFields?: boolean;
|
|
90
|
+
/**
|
|
91
|
+
* When set to true, the transform will only remove type-only imports
|
|
92
|
+
* (introduced in TypeScript 3.8). This should only be used if you are using
|
|
93
|
+
* TypeScript >= 3.8.
|
|
94
|
+
*
|
|
95
|
+
* @default false
|
|
96
|
+
*/
|
|
97
|
+
onlyRemoveTypeImports?: boolean;
|
|
98
|
+
/**
|
|
99
|
+
* When set to true, Babel will inline enum values rather than using the
|
|
100
|
+
* usual enum output:
|
|
101
|
+
*
|
|
102
|
+
* This option differs from TypeScript's --isolatedModules behavior, which
|
|
103
|
+
* ignores the const modifier and compiles them as normal enums, and aligns
|
|
104
|
+
* Babel's behavior with TypeScript's default behavior.
|
|
105
|
+
*
|
|
106
|
+
* ```ts
|
|
107
|
+
* // Input
|
|
108
|
+
* const enum Animals {
|
|
109
|
+
* Fish
|
|
110
|
+
* }
|
|
111
|
+
* console.log(Animals.Fish);
|
|
112
|
+
*
|
|
113
|
+
* // Default output
|
|
114
|
+
* var Animals;
|
|
115
|
+
*
|
|
116
|
+
* (function (Animals) {
|
|
117
|
+
* Animals[Animals["Fish"] = 0] = "Fish";
|
|
118
|
+
* })(Animals || (Animals = {}));
|
|
119
|
+
*
|
|
120
|
+
* console.log(Animals.Fish);
|
|
121
|
+
*
|
|
122
|
+
* // `optimizeConstEnums` output
|
|
123
|
+
* console.log(0);
|
|
124
|
+
* ```
|
|
125
|
+
*
|
|
126
|
+
* However, when exporting a const enum Babel will compile it to a plain
|
|
127
|
+
* object literal so that it doesn't need to rely on cross-file analysis
|
|
128
|
+
* when compiling it:
|
|
129
|
+
*
|
|
130
|
+
* ```ts
|
|
131
|
+
* // Input
|
|
132
|
+
* export const enum Animals {
|
|
133
|
+
* Fish,
|
|
134
|
+
* }
|
|
135
|
+
*
|
|
136
|
+
* // `optimizeConstEnums` output
|
|
137
|
+
* export var Animals = {
|
|
138
|
+
* Fish: 0,
|
|
139
|
+
* };
|
|
140
|
+
* ```
|
|
141
|
+
*
|
|
142
|
+
* @default false
|
|
143
|
+
*/
|
|
144
|
+
optimizeConstEnums?: boolean;
|
|
145
|
+
};
|
|
146
|
+
/**
|
|
147
|
+
* Pass any additional [babel-plugin-jsx-dom-expressions](https://github.com/ryansolid/dom-expressions/tree/main/packages/babel-plugin-jsx-dom-expressions#plugin-options).
|
|
148
|
+
* They will be merged with the defaults sets by [babel-preset-solid](https://github.com/solidjs/solid/blob/main/packages/babel-preset-solid/index.js#L8-L25).
|
|
149
|
+
*
|
|
150
|
+
* @default {}
|
|
151
|
+
*/
|
|
152
|
+
solid: {
|
|
153
|
+
/**
|
|
154
|
+
* The name of the runtime module to import the methods from.
|
|
155
|
+
*
|
|
156
|
+
* @default "solid-js/web"
|
|
157
|
+
*/
|
|
158
|
+
moduleName?: string;
|
|
159
|
+
/**
|
|
160
|
+
* The output mode of the compiler.
|
|
161
|
+
* Can be:
|
|
162
|
+
* - "dom" is standard output
|
|
163
|
+
* - "ssr" is for server side rendering of strings.
|
|
164
|
+
*
|
|
165
|
+
* @default "dom"
|
|
166
|
+
*/
|
|
167
|
+
generate?: 'ssr' | 'dom';
|
|
168
|
+
/**
|
|
169
|
+
* Indicate whether the output should contain hydratable markers.
|
|
170
|
+
*
|
|
171
|
+
* @default false
|
|
172
|
+
*/
|
|
173
|
+
hydratable?: boolean;
|
|
174
|
+
/**
|
|
175
|
+
* Boolean to indicate whether to enable automatic event delegation on camelCase.
|
|
176
|
+
*
|
|
177
|
+
* @default true
|
|
178
|
+
*/
|
|
179
|
+
delegateEvents?: boolean;
|
|
180
|
+
/**
|
|
181
|
+
* Boolean indicates whether smart conditional detection should be used.
|
|
182
|
+
* This optimizes simple boolean expressions and ternaries in JSX.
|
|
183
|
+
*
|
|
184
|
+
* @default true
|
|
185
|
+
*/
|
|
186
|
+
wrapConditionals?: boolean;
|
|
187
|
+
/**
|
|
188
|
+
* Boolean indicates whether to set current render context on Custom Elements and slots.
|
|
189
|
+
* Useful for seemless Context API with Web Components.
|
|
190
|
+
*
|
|
191
|
+
* @default true
|
|
192
|
+
*/
|
|
193
|
+
contextToCustomElements?: boolean;
|
|
194
|
+
/**
|
|
195
|
+
* Array of Component exports from module, that aren't included by default with the library.
|
|
196
|
+
* This plugin will automatically import them if it comes across them in the JSX.
|
|
197
|
+
*
|
|
198
|
+
* @default ["For","Show","Switch","Match","Suspense","SuspenseList","Portal","Index","Dynamic","ErrorBoundary"]
|
|
199
|
+
*/
|
|
200
|
+
builtIns?: string[];
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
export default function solidPlugin(options?: Partial<Options>): Plugin;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-plugin-solid",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.4",
|
|
4
4
|
"description": "solid-js integration plugin for vite 2",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
@@ -15,6 +15,12 @@
|
|
|
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
|
+
},
|
|
18
24
|
"repository": {
|
|
19
25
|
"type": "git",
|
|
20
26
|
"url": "git+https://github.com/solidjs/vite-plugin-solid.git"
|
|
@@ -34,31 +40,26 @@
|
|
|
34
40
|
},
|
|
35
41
|
"homepage": "https://github.com/solidjs/vite-plugin-solid#readme",
|
|
36
42
|
"dependencies": {
|
|
37
|
-
"@babel/core": "^7.
|
|
38
|
-
"@babel/preset-typescript": "^7.
|
|
39
|
-
"babel-preset-solid": "^1.
|
|
43
|
+
"@babel/core": "^7.16.0",
|
|
44
|
+
"@babel/preset-typescript": "^7.16.0",
|
|
45
|
+
"babel-preset-solid": "^1.2.6",
|
|
40
46
|
"merge-anything": "^4.0.1",
|
|
41
|
-
"solid-js": "^1.
|
|
42
|
-
"solid-refresh": "^0.
|
|
43
|
-
"vite": "^2.
|
|
47
|
+
"solid-js": "^1.2.6",
|
|
48
|
+
"solid-refresh": "^0.3.2",
|
|
49
|
+
"vite": "^2.7.1"
|
|
44
50
|
},
|
|
45
51
|
"devDependencies": {
|
|
46
|
-
"@babel/plugin-transform-typescript": "^7.
|
|
47
|
-
"@babel/preset-env": "^7.
|
|
52
|
+
"@babel/plugin-transform-typescript": "^7.16.1",
|
|
53
|
+
"@babel/preset-env": "^7.16.0",
|
|
48
54
|
"@rollup/plugin-babel": "^5.3.0",
|
|
49
|
-
"@rollup/plugin-commonjs": "^21.0.
|
|
50
|
-
"@rollup/plugin-node-resolve": "^13.0.
|
|
55
|
+
"@rollup/plugin-commonjs": "^21.0.1",
|
|
56
|
+
"@rollup/plugin-node-resolve": "^13.0.6",
|
|
51
57
|
"@skypack/package-check": "^0.2.2",
|
|
52
58
|
"@types/babel__core": "^7.1.16",
|
|
53
|
-
"@types/node": "^16.
|
|
59
|
+
"@types/node": "^16.11.6",
|
|
54
60
|
"prettier": "^2.4.1",
|
|
55
|
-
"rollup": "^2.
|
|
61
|
+
"rollup": "^2.59.0",
|
|
56
62
|
"rollup-plugin-cleaner": "^1.0.0",
|
|
57
|
-
"typescript": "^4.4.
|
|
58
|
-
},
|
|
59
|
-
"scripts": {
|
|
60
|
-
"build": "rollup -c && tsc --emitDeclarationOnly",
|
|
61
|
-
"dev": "rollup -c -w",
|
|
62
|
-
"check": "package-check"
|
|
63
|
+
"typescript": "^4.4.4"
|
|
63
64
|
}
|
|
64
|
-
}
|
|
65
|
+
}
|