Skip to content

Commit 02aaa9f

Browse files
committed
Merge branch 'master' of github.com:solidjs/vite-plugin-solid
2 parents 124e7fa + 48ca0c0 commit 02aaa9f

File tree

5 files changed

+133
-6
lines changed

5 files changed

+133
-6
lines changed

README.md

+10-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Join [solid discord](https://discord.com/invite/solidjs) and check the [troubles
2020

2121
## Requirements
2222

23-
We've recently made this module 100% esm compatible. As per [this document](https://nodejs.org/api/esm.html) it is strongly recommended to have at least version `14.13.0` of node installed.
23+
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.
2424

2525
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).
2626

@@ -129,6 +129,13 @@ Pass any additional [babel transform options](https://babeljs.io/docs/en/options
129129
Pass any additional [babel-plugin-jsx-dom-expressions](https://github.com/ryansolid/dom-expressions/tree/main/packages/babel-plugin-jsx-dom-expressions#plugin-options).
130130
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).
131131

132+
#### options.typescript
133+
134+
- Type: [@babel/preset-typescript](https://babeljs.io/docs/en/babel-preset-typescript)
135+
- Default: {}
136+
137+
Pass any additional [@babel/preset-typescript](https://babeljs.io/docs/en/babel-preset-typescript).
138+
132139
## Note on HMR
133140

134141
Starting from version `1.1.0`, this plugin handle automatic HMR via [solid-refresh](https://github.com/solidjs/solid-refresh).
@@ -165,6 +172,8 @@ if (import.meta.hot) {
165172
166173
- 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)
167174
175+
- 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`
176+
168177
## Migration from v1
169178
170179
The master branch now target vite 2.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vite-plugin-solid",
3-
"version": "2.0.2",
3+
"version": "2.0.3",
44
"description": "solid-js integration plugin for vite 2",
55
"type": "module",
66
"files": [

playground/pages/index.tsx

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { createRenderEffect, createSignal } from 'solid-js';
2-
import type { Accessor } from 'solid-js';
1+
import { Accessor, createRenderEffect, createSignal } from 'solid-js';
32

43
function model(
54
element: HTMLInputElement,

playground/vite.config.js

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const logPlugin = () => {
1414
};
1515

1616
export default defineConfig({
17+
target: 'esnext',
1718
plugins: [
1819
solid({
1920
babel: {

src/index.ts

+120-2
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,125 @@ export interface Options {
4747
| TransformOptions
4848
| ((source: string, id: string, ssr: boolean) => TransformOptions)
4949
| ((source: string, id: string, ssr: boolean) => Promise<TransformOptions>);
50+
typescript: {
51+
/**
52+
* Forcibly enables jsx parsing. Otherwise angle brackets will be treated as
53+
* typescript's legacy type assertion var foo = <string>bar;. Also, isTSX:
54+
* true requires allExtensions: true.
55+
*
56+
* @default false
57+
*/
58+
isTSX?: boolean;
59+
60+
/**
61+
* Replace the function used when compiling JSX expressions. This is so that
62+
* we know that the import is not a type import, and should not be removed.
63+
*
64+
* @default React
65+
*/
66+
jsxPragma?: string;
67+
68+
/**
69+
* Replace the function used when compiling JSX fragment expressions. This
70+
* is so that we know that the import is not a type import, and should not
71+
* be removed.
72+
*
73+
* @default React.Fragment
74+
*/
75+
jsxPragmaFrag?: string;
76+
77+
/**
78+
* Indicates that every file should be parsed as TS or TSX (depending on the
79+
* isTSX option).
80+
*
81+
* @default false
82+
*/
83+
allExtensions?: boolean;
84+
85+
/**
86+
* Enables compilation of TypeScript namespaces.
87+
*
88+
* @default uses the default set by @babel/plugin-transform-typescript.
89+
*/
90+
allowNamespaces?: boolean;
91+
92+
/**
93+
* When enabled, type-only class fields are only removed if they are
94+
* prefixed with the declare modifier:
95+
*
96+
* > NOTE: This will be enabled by default in Babel 8
97+
*
98+
* @default false
99+
*
100+
* @example
101+
* ```ts
102+
* class A {
103+
* declare foo: string; // Removed
104+
* bar: string; // Initialized to undefined
105+
* prop?: string; // Initialized to undefined
106+
* prop1!: string // Initialized to undefined
107+
* }
108+
* ```
109+
*/
110+
allowDeclareFields?: boolean;
111+
112+
/**
113+
* When set to true, the transform will only remove type-only imports
114+
* (introduced in TypeScript 3.8). This should only be used if you are using
115+
* TypeScript >= 3.8.
116+
*
117+
* @default false
118+
*/
119+
onlyRemoveTypeImports?: boolean;
120+
121+
/**
122+
* When set to true, Babel will inline enum values rather than using the
123+
* usual enum output:
124+
*
125+
* This option differs from TypeScript's --isolatedModules behavior, which
126+
* ignores the const modifier and compiles them as normal enums, and aligns
127+
* Babel's behavior with TypeScript's default behavior.
128+
*
129+
* ```ts
130+
* // Input
131+
* const enum Animals {
132+
* Fish
133+
* }
134+
* console.log(Animals.Fish);
135+
*
136+
* // Default output
137+
* var Animals;
138+
*
139+
* (function (Animals) {
140+
* Animals[Animals["Fish"] = 0] = "Fish";
141+
* })(Animals || (Animals = {}));
142+
*
143+
* console.log(Animals.Fish);
144+
*
145+
* // `optimizeConstEnums` output
146+
* console.log(0);
147+
* ```
148+
*
149+
* However, when exporting a const enum Babel will compile it to a plain
150+
* object literal so that it doesn't need to rely on cross-file analysis
151+
* when compiling it:
152+
*
153+
* ```ts
154+
* // Input
155+
* export const enum Animals {
156+
* Fish,
157+
* }
158+
*
159+
* // `optimizeConstEnums` output
160+
* export var Animals = {
161+
* Fish: 0,
162+
* };
163+
* ```
164+
*
165+
* @default false
166+
*/
167+
optimizeConstEnums?: boolean;
168+
};
50169
/**
51170
* Pass any additional [babel-plugin-jsx-dom-expressions](https://github.com/ryansolid/dom-expressions/tree/main/packages/babel-plugin-jsx-dom-expressions#plugin-options).
52171
* 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).
@@ -187,8 +306,7 @@ export default function solidPlugin(options: Partial<Options> = {}): Plugin {
187306
};
188307

189308
if (id.includes('tsx')) {
190-
// The `onlyRemoveTypeImports` prevent directives from failing
191-
opts.presets.push([ts, { onlyRemoveTypeImports: true }]);
309+
opts.presets.push([ts, options.typescript || {}]);
192310
}
193311

194312
// Default value for babel user options

0 commit comments

Comments
 (0)