vite-plugin-solid 2.1.1 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,203 +1,214 @@
1
- import { TransformOptions } from '@babel/core';
2
- import type { Plugin } from 'vite';
3
- /** Configuration options for vite-plugin-solid. */
4
- export interface Options {
5
- /**
6
- * This will inject solid-js/dev in place of solid-js in dev mode. Has no
7
- * effect in prod. If set to `false`, it won't inject it in dev. This is
8
- * useful for extra logs and debugging.
9
- *
10
- * @default true
11
- */
12
- dev: boolean;
13
- /**
14
- * This will force SSR code in the produced files. This is experiemental
15
- * and mostly not working yet.
16
- *
17
- * @default false
18
- */
19
- ssr: boolean;
20
- /**
21
- * This will inject HMR runtime in dev mode. Has no effect in prod. If
22
- * set to `false`, it won't inject the runtime in dev.
23
- *
24
- * @default true
25
- */
26
- hot: boolean;
27
- /**
28
- * Pass any additional babel transform options. They will be merged with
29
- * the transformations required by Solid.
30
- *
31
- * @default {}
32
- */
33
- babel: TransformOptions | ((source: string, id: string, ssr: boolean) => TransformOptions) | ((source: string, id: string, ssr: boolean) => Promise<TransformOptions>);
34
- typescript: {
35
- /**
36
- * Forcibly enables jsx parsing. Otherwise angle brackets will be treated as
37
- * typescript's legacy type assertion var foo = <string>bar;. Also, isTSX:
38
- * true requires allExtensions: true.
39
- *
40
- * @default false
41
- */
42
- isTSX?: boolean;
43
- /**
44
- * Replace the function used when compiling JSX expressions. This is so that
45
- * we know that the import is not a type import, and should not be removed.
46
- *
47
- * @default React
48
- */
49
- jsxPragma?: string;
50
- /**
51
- * Replace the function used when compiling JSX fragment expressions. This
52
- * is so that we know that the import is not a type import, and should not
53
- * be removed.
54
- *
55
- * @default React.Fragment
56
- */
57
- jsxPragmaFrag?: string;
58
- /**
59
- * Indicates that every file should be parsed as TS or TSX (depending on the
60
- * isTSX option).
61
- *
62
- * @default false
63
- */
64
- allExtensions?: boolean;
65
- /**
66
- * Enables compilation of TypeScript namespaces.
67
- *
68
- * @default uses the default set by @babel/plugin-transform-typescript.
69
- */
70
- allowNamespaces?: boolean;
71
- /**
72
- * When enabled, type-only class fields are only removed if they are
73
- * prefixed with the declare modifier:
74
- *
75
- * > NOTE: This will be enabled by default in Babel 8
76
- *
77
- * @default false
78
- *
79
- * @example
80
- * ```ts
81
- * class A {
82
- * declare foo: string; // Removed
83
- * bar: string; // Initialized to undefined
84
- * prop?: string; // Initialized to undefined
85
- * prop1!: string // Initialized to undefined
86
- * }
87
- * ```
88
- */
89
- allowDeclareFields?: boolean;
90
- /**
91
- * When set to true, the transform will only remove type-only imports
92
- * (introduced in TypeScript 3.8). This should only be used if you are using
93
- * TypeScript >= 3.8.
94
- *
95
- * @default false
96
- */
97
- onlyRemoveTypeImports?: boolean;
98
- /**
99
- * When set to true, Babel will inline enum values rather than using the
100
- * usual enum output:
101
- *
102
- * This option differs from TypeScript's --isolatedModules behavior, which
103
- * ignores the const modifier and compiles them as normal enums, and aligns
104
- * Babel's behavior with TypeScript's default behavior.
105
- *
106
- * ```ts
107
- * // Input
108
- * const enum Animals {
109
- * Fish
110
- * }
111
- * console.log(Animals.Fish);
112
- *
113
- * // Default output
114
- * var Animals;
115
- *
116
- * (function (Animals) {
117
- * Animals[Animals["Fish"] = 0] = "Fish";
118
- * })(Animals || (Animals = {}));
119
- *
120
- * console.log(Animals.Fish);
121
- *
122
- * // `optimizeConstEnums` output
123
- * console.log(0);
124
- * ```
125
- *
126
- * However, when exporting a const enum Babel will compile it to a plain
127
- * object literal so that it doesn't need to rely on cross-file analysis
128
- * when compiling it:
129
- *
130
- * ```ts
131
- * // Input
132
- * export const enum Animals {
133
- * Fish,
134
- * }
135
- *
136
- * // `optimizeConstEnums` output
137
- * export var Animals = {
138
- * Fish: 0,
139
- * };
140
- * ```
141
- *
142
- * @default false
143
- */
144
- optimizeConstEnums?: boolean;
145
- };
146
- /**
147
- * Pass any additional [babel-plugin-jsx-dom-expressions](https://github.com/ryansolid/dom-expressions/tree/main/packages/babel-plugin-jsx-dom-expressions#plugin-options).
148
- * They will be merged with the defaults sets by [babel-preset-solid](https://github.com/solidjs/solid/blob/main/packages/babel-preset-solid/index.js#L8-L25).
149
- *
150
- * @default {}
151
- */
152
- solid: {
153
- /**
154
- * The name of the runtime module to import the methods from.
155
- *
156
- * @default "solid-js/web"
157
- */
158
- moduleName?: string;
159
- /**
160
- * The output mode of the compiler.
161
- * Can be:
162
- * - "dom" is standard output
163
- * - "ssr" is for server side rendering of strings.
164
- *
165
- * @default "dom"
166
- */
167
- generate?: 'ssr' | 'dom';
168
- /**
169
- * Indicate whether the output should contain hydratable markers.
170
- *
171
- * @default false
172
- */
173
- hydratable?: boolean;
174
- /**
175
- * Boolean to indicate whether to enable automatic event delegation on camelCase.
176
- *
177
- * @default true
178
- */
179
- delegateEvents?: boolean;
180
- /**
181
- * Boolean indicates whether smart conditional detection should be used.
182
- * This optimizes simple boolean expressions and ternaries in JSX.
183
- *
184
- * @default true
185
- */
186
- wrapConditionals?: boolean;
187
- /**
188
- * Boolean indicates whether to set current render context on Custom Elements and slots.
189
- * Useful for seemless Context API with Web Components.
190
- *
191
- * @default true
192
- */
193
- contextToCustomElements?: boolean;
194
- /**
195
- * Array of Component exports from module, that aren't included by default with the library.
196
- * This plugin will automatically import them if it comes across them in the JSX.
197
- *
198
- * @default ["For","Show","Switch","Match","Suspense","SuspenseList","Portal","Index","Dynamic","ErrorBoundary"]
199
- */
200
- builtIns?: string[];
201
- };
202
- }
203
- export default function solidPlugin(options?: Partial<Options>): Plugin;
1
+ import { TransformOptions } from '@babel/core';
2
+ import type { Plugin } from 'vite';
3
+ /** Possible options for the extensions property */
4
+ export interface ExtensionOptions {
5
+ typescript?: boolean;
6
+ }
7
+ /** Configuration options for vite-plugin-solid. */
8
+ export interface Options {
9
+ /**
10
+ * This will inject solid-js/dev in place of solid-js in dev mode. Has no
11
+ * effect in prod. If set to `false`, it won't inject it in dev. This is
12
+ * useful for extra logs and debugging.
13
+ *
14
+ * @default true
15
+ */
16
+ dev: boolean;
17
+ /**
18
+ * This will force SSR code in the produced files. This is experiemental
19
+ * and mostly not working yet.
20
+ *
21
+ * @default false
22
+ */
23
+ ssr: boolean;
24
+ /**
25
+ * This will inject HMR runtime in dev mode. Has no effect in prod. If
26
+ * set to `false`, it won't inject the runtime in dev.
27
+ *
28
+ * @default true
29
+ */
30
+ hot: boolean;
31
+ /**
32
+ * This registers additional extensions that should be processed by
33
+ * vite-plugin-solid.
34
+ *
35
+ * @default undefined
36
+ */
37
+ extensions?: (string | [string, ExtensionOptions])[];
38
+ /**
39
+ * Pass any additional babel transform options. They will be merged with
40
+ * the transformations required by Solid.
41
+ *
42
+ * @default {}
43
+ */
44
+ babel: TransformOptions | ((source: string, id: string, ssr: boolean) => TransformOptions) | ((source: string, id: string, ssr: boolean) => Promise<TransformOptions>);
45
+ typescript: {
46
+ /**
47
+ * Forcibly enables jsx parsing. Otherwise angle brackets will be treated as
48
+ * typescript's legacy type assertion var foo = <string>bar;. Also, isTSX:
49
+ * true requires allExtensions: true.
50
+ *
51
+ * @default false
52
+ */
53
+ isTSX?: boolean;
54
+ /**
55
+ * Replace the function used when compiling JSX expressions. This is so that
56
+ * we know that the import is not a type import, and should not be removed.
57
+ *
58
+ * @default React
59
+ */
60
+ jsxPragma?: string;
61
+ /**
62
+ * Replace the function used when compiling JSX fragment expressions. This
63
+ * is so that we know that the import is not a type import, and should not
64
+ * be removed.
65
+ *
66
+ * @default React.Fragment
67
+ */
68
+ jsxPragmaFrag?: string;
69
+ /**
70
+ * Indicates that every file should be parsed as TS or TSX (depending on the
71
+ * isTSX option).
72
+ *
73
+ * @default false
74
+ */
75
+ allExtensions?: boolean;
76
+ /**
77
+ * Enables compilation of TypeScript namespaces.
78
+ *
79
+ * @default uses the default set by @babel/plugin-transform-typescript.
80
+ */
81
+ allowNamespaces?: boolean;
82
+ /**
83
+ * When enabled, type-only class fields are only removed if they are
84
+ * prefixed with the declare modifier:
85
+ *
86
+ * > NOTE: This will be enabled by default in Babel 8
87
+ *
88
+ * @default false
89
+ *
90
+ * @example
91
+ * ```ts
92
+ * class A {
93
+ * declare foo: string; // Removed
94
+ * bar: string; // Initialized to undefined
95
+ * prop?: string; // Initialized to undefined
96
+ * prop1!: string // Initialized to undefined
97
+ * }
98
+ * ```
99
+ */
100
+ allowDeclareFields?: boolean;
101
+ /**
102
+ * When set to true, the transform will only remove type-only imports
103
+ * (introduced in TypeScript 3.8). This should only be used if you are using
104
+ * TypeScript >= 3.8.
105
+ *
106
+ * @default false
107
+ */
108
+ onlyRemoveTypeImports?: boolean;
109
+ /**
110
+ * When set to true, Babel will inline enum values rather than using the
111
+ * usual enum output:
112
+ *
113
+ * This option differs from TypeScript's --isolatedModules behavior, which
114
+ * ignores the const modifier and compiles them as normal enums, and aligns
115
+ * Babel's behavior with TypeScript's default behavior.
116
+ *
117
+ * ```ts
118
+ * // Input
119
+ * const enum Animals {
120
+ * Fish
121
+ * }
122
+ * console.log(Animals.Fish);
123
+ *
124
+ * // Default output
125
+ * var Animals;
126
+ *
127
+ * (function (Animals) {
128
+ * Animals[Animals["Fish"] = 0] = "Fish";
129
+ * })(Animals || (Animals = {}));
130
+ *
131
+ * console.log(Animals.Fish);
132
+ *
133
+ * // `optimizeConstEnums` output
134
+ * console.log(0);
135
+ * ```
136
+ *
137
+ * However, when exporting a const enum Babel will compile it to a plain
138
+ * object literal so that it doesn't need to rely on cross-file analysis
139
+ * when compiling it:
140
+ *
141
+ * ```ts
142
+ * // Input
143
+ * export const enum Animals {
144
+ * Fish,
145
+ * }
146
+ *
147
+ * // `optimizeConstEnums` output
148
+ * export var Animals = {
149
+ * Fish: 0,
150
+ * };
151
+ * ```
152
+ *
153
+ * @default false
154
+ */
155
+ optimizeConstEnums?: boolean;
156
+ };
157
+ /**
158
+ * Pass any additional [babel-plugin-jsx-dom-expressions](https://github.com/ryansolid/dom-expressions/tree/main/packages/babel-plugin-jsx-dom-expressions#plugin-options).
159
+ * They will be merged with the defaults sets by [babel-preset-solid](https://github.com/solidjs/solid/blob/main/packages/babel-preset-solid/index.js#L8-L25).
160
+ *
161
+ * @default {}
162
+ */
163
+ solid: {
164
+ /**
165
+ * The name of the runtime module to import the methods from.
166
+ *
167
+ * @default "solid-js/web"
168
+ */
169
+ moduleName?: string;
170
+ /**
171
+ * The output mode of the compiler.
172
+ * Can be:
173
+ * - "dom" is standard output
174
+ * - "ssr" is for server side rendering of strings.
175
+ *
176
+ * @default "dom"
177
+ */
178
+ generate?: 'ssr' | 'dom';
179
+ /**
180
+ * Indicate whether the output should contain hydratable markers.
181
+ *
182
+ * @default false
183
+ */
184
+ hydratable?: boolean;
185
+ /**
186
+ * Boolean to indicate whether to enable automatic event delegation on camelCase.
187
+ *
188
+ * @default true
189
+ */
190
+ delegateEvents?: boolean;
191
+ /**
192
+ * Boolean indicates whether smart conditional detection should be used.
193
+ * This optimizes simple boolean expressions and ternaries in JSX.
194
+ *
195
+ * @default true
196
+ */
197
+ wrapConditionals?: boolean;
198
+ /**
199
+ * Boolean indicates whether to set current render context on Custom Elements and slots.
200
+ * Useful for seemless Context API with Web Components.
201
+ *
202
+ * @default true
203
+ */
204
+ contextToCustomElements?: boolean;
205
+ /**
206
+ * Array of Component exports from module, that aren't included by default with the library.
207
+ * This plugin will automatically import them if it comes across them in the JSX.
208
+ *
209
+ * @default ["For","Show","Switch","Match","Suspense","SuspenseList","Portal","Index","Dynamic","ErrorBoundary"]
210
+ */
211
+ builtIns?: string[];
212
+ };
213
+ }
214
+ export default function solidPlugin(options?: Partial<Options>): Plugin;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-solid",
3
- "version": "2.1.1",
3
+ "version": "2.2.0",
4
4
  "description": "solid-js integration plugin for vite 2",
5
5
  "type": "module",
6
6
  "files": [
@@ -34,31 +34,33 @@
34
34
  },
35
35
  "homepage": "https://github.com/solidjs/vite-plugin-solid#readme",
36
36
  "dependencies": {
37
- "@babel/core": "^7.15.8",
38
- "@babel/preset-typescript": "^7.15.0",
39
- "babel-preset-solid": "^1.1.5",
40
- "merge-anything": "^4.0.1",
41
- "solid-js": "^1.1.6",
42
- "solid-refresh": "^0.2.2",
43
- "vite": "^2.6.7"
37
+ "@babel/core": "^7.16.7",
38
+ "@babel/preset-typescript": "^7.16.7",
39
+ "babel-preset-solid": "^1.2.6",
40
+ "merge-anything": "^4.0.2",
41
+ "solid-js": "^1.2.6",
42
+ "solid-refresh": "^0.3.2",
43
+ "vite": "^2.7.10"
44
44
  },
45
45
  "devDependencies": {
46
- "@babel/plugin-transform-typescript": "^7.15.8",
47
- "@babel/preset-env": "^7.15.8",
46
+ "@babel/plugin-transform-typescript": "^7.16.7",
47
+ "@babel/preset-env": "^7.16.7",
48
48
  "@rollup/plugin-babel": "^5.3.0",
49
- "@rollup/plugin-commonjs": "^21.0.0",
50
- "@rollup/plugin-node-resolve": "^13.0.5",
49
+ "@rollup/plugin-commonjs": "^21.0.1",
50
+ "@rollup/plugin-node-resolve": "^13.1.2",
51
51
  "@skypack/package-check": "^0.2.2",
52
- "@types/babel__core": "^7.1.16",
53
- "@types/node": "^16.11.0",
54
- "prettier": "^2.4.1",
55
- "rollup": "^2.58.0",
52
+ "@types/babel__core": "^7.1.18",
53
+ "@types/node": "^17.0.7",
54
+ "prettier": "^2.5.1",
55
+ "rollup": "^2.62.0",
56
56
  "rollup-plugin-cleaner": "^1.0.0",
57
- "typescript": "^4.4.4"
57
+ "typescript": "^4.5.4"
58
58
  },
59
+ "packageManager": "pnpm@6.24.4",
59
60
  "scripts": {
60
61
  "build": "rollup -c && tsc --emitDeclarationOnly",
61
62
  "dev": "rollup -c -w",
62
63
  "check": "package-check"
63
- }
64
+ },
65
+ "readme": "<p>\n <img width=\"100%\" src=\"https://raw.githubusercontent.com/solidjs/vite-plugin-solid/master/banner.png\" alt=\"Solid Vite Plugin\">\n</p>\n\n# ⚡ vite-plugin-solid\n\nA simple integration to run [solid-js](https://github.com/solidjs/solid) with [vite](https://github.com/vitejs/vite)\n\n<img alt=\"HMR gif demonstrationdemodemodemo\" src=\".github/hmr.gif\">\n\n# Got a question? / Need help?\n\nJoin [solid discord](https://discord.com/invite/solidjs) and check the [troubleshooting section](#troubleshooting) to see if your question hasn't been already answered.\n\n## Features\n\n- HMR with no configuration needed\n- Drop-in installation as a vite plugin\n- Minimal bundle size\n- Support typescript (`.tsx`) out of the box\n- Support code splitting out of the box\n\n## Requirements\n\nThis module 100% esm compatible. As per [this document](https://nodejs.org/api/esm.html) it is strongly recommended to have at least the version `14.13.0` of node installed.\n\nYou can check your current version of node by typing `node -v` in your terminal. If your version is below that one version I'd encourage you to either do an update globally or use a node version management tool such as [volta](https://volta.sh/) or [nvm](https://github.com/nvm-sh/nvm).\n\n## Quickstart\n\nYou can use the [vite-template-solid](https://github.com/solidjs/templates) starter templates similar to CRA:\n\n```bash\n$ npx degit solidjs/templates/js my-solid-project\n$ cd my-solid-project\n$ npm install # or pnpm install or yarn install\n$ npm run start # starts dev-server with hot-module-reloading\n$ npm run build # builds to /dist\n```\n\n## Installation\n\nInstall `vite`, `vite-plugin-solid` and `babel-preset-solid` as dev dependencies.\n\nInstall `solid-js` as dependency.\n\nYou have to install those so that you are in control to which solid version is used to compile your code.\n\n```bash\n# with npm\n$ npm install -D vite vite-plugin-solid babel-preset-solid\n$ npm install solid-js\n\n# with pnpm\n$ pnpm add -D vite vite-plugin-solid babel-preset-solid\n$ pnpm add solid-js\n\n# with yarn\n$ yarn add -D vite vite-plugin-solid babel-preset-solid\n$ yarn add solid-js\n```\n\nAdd it as plugin to `vite.config.js`\n\n```js\n// vite.config.ts\nimport { defineConfig } from 'vite';\nimport solidPlugin from 'vite-plugin-solid';\n\nexport default defineConfig({\n plugins: [solidPlugin()],\n});\n```\n\n## Run\n\nJust use regular `vite` or `vite build` commands\n\n```json\n{\n \"scripts\": {\n \"dev\": \"vite\",\n \"build\": \"vite build\"\n }\n}\n```\n\n## API\n\n### options\n\n- Type: Object\n- Default: {}\n\n#### options.dev\n\n- Type: Boolean\n- Default: true\n\nThis will inject `solid-js/dev` in place of `solid-js` in dev mode. Has no effect in prod.\nIf set to false, it won't inject it in dev.\nThis is useful for extra logs and debug.\n\n#### options.hot\n\n- Type: Boolean\n- Default: true\n\nThis will inject HMR runtime in dev mode. Has no effect in prod.\nIf set to false, it won't inject the runtime in dev.\n\n#### options.ssr\n\n- Type: Boolean\n- Default: false\n\nThis will force SSR code in the produced files. This is experiemental and mostly not working yet.\n\n#### options.babel\n\n- Type: Babel.TransformOptions\n- Default: {}\n\nPass any additional [babel transform options](https://babeljs.io/docs/en/options). Those will be merged with the transformations required by Solid.\n\n#### options.solid\n\n- Type: [babel-plugin-jsx-dom-expressions](https://github.com/ryansolid/dom-expressions/tree/main/packages/babel-plugin-jsx-dom-expressions#plugin-options)\n- Default: {}\n\nPass any additional [babel-plugin-jsx-dom-expressions](https://github.com/ryansolid/dom-expressions/tree/main/packages/babel-plugin-jsx-dom-expressions#plugin-options).\nThey will be merged with the defaults sets by [babel-preset-solid](https://github.com/solidjs/solid/blob/main/packages/babel-preset-solid/index.js#L8-L25).\n\n#### options.typescript\n\n- Type: [@babel/preset-typescript](https://babeljs.io/docs/en/babel-preset-typescript)\n- Default: {}\n\nPass any additional [@babel/preset-typescript](https://babeljs.io/docs/en/babel-preset-typescript).\n\n## Note on HMR\n\nStarting from version `1.1.0`, this plugin handle automatic HMR via [solid-refresh](https://github.com/solidjs/solid-refresh).\n\nAt this stage it's still early work but provide basic HMR. In order to get the best out of it there are couple of things to keep in mind:\n\n- When you modify a file every state below this component will be reset to default state (including the current file). The state in parent component is preserved.\n\n- The entrypoint can't benefit from HMR yet and will force a hard reload of the entire app. This is still really fast thanks to browser caching.\n\nIf at least one of this point is blocking to you, you can revert to the old behavior but [opting out the automatic HMR](#options) and placing the following snippet in your entry point:\n\n```jsx\nconst dispose = render(() => <App />, document.body);\n\nif (import.meta.hot) {\n import.meta.hot.accept();\n import.meta.hot.dispose(dispose);\n}\n```\n\n# Troubleshooting\n\n- It appears that Webstorm generate some weird triggers when saving a file. In order to prevent that you can follow [this thread](https://intellij-support.jetbrains.com/hc/en-us/community/posts/360000154544-I-m-having-a-huge-problem-with-Webstorm-and-react-hot-loader-) and disable the **\"Safe Write\"** option in **\"Settings | Appearance & Behavior | System Settings\"**.\n\n- If one of your dependency spit out React code instead of Solid that means that they don't expose JSX properly. To get around it, you might want to manually exclude it from the [dependencies optimization](https://vitejs.dev/config/#optimizedeps-exclude)\n\n- If you are trying to make [directives](https://www.solidjs.com/docs/latest/api#use%3A___) work and they somehow don't try setting the `options.typescript.onlyRemoveTypeImports` option to `true`\n\n## Migration from v1\n\nThe master branch now target vite 2.\n\nThe main breaking change from previous version is that the package has been renamed from `@amoutonbrady/vite-plugin-solid` to `vite-plugin-solid`.\n\nFor other breaking changes, check [the migration guide of vite](https://vitejs.dev/guide/migration.html).\n\n# Credits\n\n- [solid-js](https://github.com/solidjs/solid)\n- [vite](https://github.com/vitejs/vite)\n"
64
66
  }