Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/tidy-lions-smile.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'vite-plugin-solid': patch
---

Use per-environment Vite plugin hook APIs while retaining compatibility with Vite 3 through 5.
5 changes: 4 additions & 1 deletion examples/vite-8/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import { defineConfig } from 'vite';
import solidPlugin from 'vite-plugin-solid';

export default defineConfig({
future: {
removePluginHookSsrArgument: 'warn',
},
plugins: [
solidPlugin(),
],
});
});
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "vite-plugin-solid",
"version": "2.11.12",
"description": "solid-js integration plugin for vite 3/4/5/6",
"description": "solid-js integration plugin for Vite",
"type": "module",
"files": [
"dist"
Expand Down Expand Up @@ -73,7 +73,7 @@
"peerDependencies": {
"@testing-library/jest-dom": "^5.16.6 || ^5.17.0 || ^6.*",
"solid-js": "^1.7.2",
"vite": "^3.0.0 || ^4.0.0 || ^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0"
"vite": "^3.0.0 || ^4.0.0 || ^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0 || ^9.0.0"
},
"peerDependenciesMeta": {
"@testing-library/jest-dom": {
Expand Down
2 changes: 1 addition & 1 deletion pnpm-workspace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ packages:
- '.'
- "examples/*"
catalog:
"solid-js": ^1.9.4
"solid-js": ^1.9.4
15 changes: 12 additions & 3 deletions scripts/test-examples.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import { spawn, exec, ChildProcess } from 'node:child_process';
import { readdirSync } from 'node:fs';
import { promisify } from 'node:util';

const execAsync = promisify(exec);
const examples = ['vite-3', 'vite-4', 'vite-5', 'vite-6'];
const examples = readdirSync('examples', { withFileTypes: true })
.filter((entry) => entry.isDirectory() && /^vite-\d+$/.test(entry.name))
.map((entry) => entry.name)
.sort((a, b) => Number(a.slice(5)) - Number(b.slice(5)));
const pluginHookSsrDeprecation =
"Plugin hook `options.ssr` is replaced with `this.environment.config.consumer === 'server'`.";
const PORT = 4173;
const TEST_TIMEOUT = 5 * 60 * 1000; // 5 minutes

Expand All @@ -28,7 +34,10 @@ async function runExample(example) {
try {
// Install and build
await execAsync('pnpm install', { cwd: examplePath });
await execAsync('pnpm run build', { cwd: examplePath });
const { stdout, stderr } = await execAsync('pnpm run build', { cwd: examplePath });
if (`${stdout}\n${stderr}`.includes(pluginHookSsrDeprecation)) {
throw new Error(`Vite's deprecated plugin hook SSR argument was used in ${example}`);
}

// Start preview server with timeout
const server = spawn('pnpm', ['run', 'preview'], { cwd: examplePath });
Expand Down Expand Up @@ -75,4 +84,4 @@ runAll().catch(error => {
console.error('Unexpected error:', error);
cleanup();
process.exit(1);
});
});
16 changes: 9 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ const runtimeFilePath = require.resolve('solid-refresh/dist/solid-refresh.mjs');
const runtimeCode = readFileSync(runtimeFilePath, 'utf-8');

const viteVersionMajor = +version.split('.')[0];
const isVite6 = viteVersionMajor >= 6;
const isVite8 = viteVersionMajor >= 8;
const isVite6OrNewer = viteVersionMajor >= 6;
const isVite8OrNewer = viteVersionMajor >= 8;

/** Possible options for the extensions property */
export interface ExtensionOptions {
Expand Down Expand Up @@ -266,7 +266,7 @@ export default function solidPlugin(options: Partial<Options> = {}): Plugin {
*/
// esbuild: { include: /\.ts$/ },
resolve: {
conditions: isVite6
conditions: isVite6OrNewer
? undefined
: [
'solid',
Expand All @@ -283,11 +283,11 @@ export default function solidPlugin(options: Partial<Options> = {}): Plugin {
// React's automatic JSX runtime for .tsx files, injecting a
// react/jsx-dev-runtime import. Tell it to preserve JSX as-is since
// this plugin handles JSX transformation via babel-preset-solid.
...(isVite8
...(isVite8OrNewer
? { rolldownOptions: { transform: { jsx: 'preserve' as const } } }
: {}),
},
...(!isVite6 ? { ssr: solidPkgsConfig.ssr } : {}),
...(!isVite6OrNewer ? { ssr: solidPkgsConfig.ssr } : {}),
...(test.server ? { test } : {}),
};
},
Expand All @@ -314,7 +314,7 @@ export default function solidPlugin(options: Partial<Options> = {}): Plugin {

// Set resolve.noExternal and resolve.external for SSR environment (Vite 6+)
// Only set resolve.external if noExternal is not true (to avoid conflicts with plugins like Cloudflare)
if (isVite6 && name === 'ssr' && solidPkgsConfig) {
if (isVite6OrNewer && name === 'ssr' && solidPkgsConfig) {
if (config.resolve.noExternal !== true) {
config.resolve.noExternal = [
...(Array.isArray(config.resolve.noExternal) ? config.resolve.noExternal : []),
Expand All @@ -341,7 +341,9 @@ export default function solidPlugin(options: Partial<Options> = {}): Plugin {
},

async transform(source, id, transformOptions) {
const isSsr = transformOptions && transformOptions.ssr;
const isSsr = this.environment
? this.environment.config.consumer === 'server'
: Boolean(transformOptions?.ssr);
const currentFileExtension = getExtension(id);

const extensionsToWatch = options.extensions || [];
Expand Down
Loading