diff --git a/package.json b/package.json index 9b77432..2cc6fcb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "vite-plugin-solid", - "version": "0.7.0", + "version": "0.7.1", "description": "solid-js integration plugin for vite 2", "files": [ "dist" @@ -46,18 +46,19 @@ "@babel/core": "^7.12.7", "@babel/preset-typescript": "^7.12.7", "babel-preset-solid": "^0.23", + "resolve.exports": "^1.0.2", "solid-js": "^0.23.11", - "vite": "^2.0.0-beta.44" + "vite": "^2.0.0-beta.59" }, "devDependencies": { "@babel/plugin-transform-typescript": "^7.12.1", - "@rollup/plugin-babel": "^5.2.2", - "@rollup/plugin-node-resolve": "^11.1.0", + "@rollup/plugin-babel": "^5.2.3", + "@rollup/plugin-node-resolve": "^11.1.1", "@skypack/package-check": "^0.2.2", "@types/babel__core": "^7.1.12", "@types/node": "^14.14.22", "prettier": "^2.2.1", - "rollup": "^2.38.0", + "rollup": "^2.38.1", "rollup-plugin-cleaner": "^1.0.0", "typescript": "^4.1.2" } diff --git a/playground/index.tsx b/playground/index.tsx index c0e18be..0fed6f0 100644 --- a/playground/index.tsx +++ b/playground/index.tsx @@ -1,19 +1,21 @@ +import { lazy } from 'solid-js'; +import { render } from 'solid-js/web'; +import { Link } from 'solid-app-router'; import { MetaProvider } from 'solid-meta'; import { Router, Route, RouteDefinition } from 'solid-app-router'; -import { Link } from 'solid-app-router'; -import { render } from 'solid-js/web'; -import { createApp } from 'solid-utils'; - -const pages = import.meta.globEager('./pages/*.tsx'); -const routes = Object.entries(pages).map(([file, { default: component }]) => { - const path = file - .replace('./pages', '') - .replace('index', '') - .replace(/\.[tj]sx?/gi, ''); +import Home from './pages'; - return { component, path } as RouteDefinition; -}); +const routes: RouteDefinition[] = [ + { + path: '/', + component: Home, + }, + { + path: '/about', + component: lazy(() => import('./pages/about')), + }, +]; const App = () => ( <> diff --git a/playground/package.json b/playground/package.json index afca6be..7ff7d42 100644 --- a/playground/package.json +++ b/playground/package.json @@ -11,12 +11,12 @@ "author": "Alexandre Mouton-Brady", "license": "ISC", "devDependencies": { - "vite": "^2.0.0-beta.44" + "vite": "^2.0.0-beta.59" }, "dependencies": { "solid-app-router": "^0.0.19", "solid-js": "^0.23.11", "solid-meta": "^0.23.11", - "solid-utils": "^0.2.0" + "solid-utils": "^0.2.1" } } diff --git a/playground/pages/about.tsx b/playground/pages/about.tsx index 535c7bb..f58b3a8 100644 --- a/playground/pages/about.tsx +++ b/playground/pages/about.tsx @@ -1,3 +1,3 @@ -export default () => { +export default function About() { return

Hello about

; -}; +} diff --git a/playground/pages/index.tsx b/playground/pages/index.tsx index 24cf047..c6007bb 100644 --- a/playground/pages/index.tsx +++ b/playground/pages/index.tsx @@ -1,10 +1,10 @@ import { Title } from 'solid-meta'; -export default () => { +export default function Home() { return ( <> Home!!!

Hello home

); -}; +} diff --git a/playground/pnpm-lock.yaml b/playground/pnpm-lock.yaml index 4f75774..db5d50c 100644 --- a/playground/pnpm-lock.yaml +++ b/playground/pnpm-lock.yaml @@ -2,21 +2,21 @@ dependencies: solid-app-router: 0.0.19_solid-js@0.23.11 solid-js: 0.23.11 solid-meta: 0.23.11_solid-js@0.23.11 - solid-utils: 0.2.0 + solid-utils: 0.2.1 devDependencies: - vite: 2.0.0-beta.44 + vite: 2.0.0-beta.59 lockfileVersion: 5.2 packages: /colorette/1.2.1: dev: true resolution: integrity: sha512-puCDz0CzydiSYOrnXpz/PKd69zRrribezjtE9yd4zvytoRc8+RY/KJPvtPFKZS3E3wP6neGyMe0vOTlHO5L3Pw== - /esbuild/0.8.34: + /esbuild/0.8.37: dev: true hasBin: true requiresBuild: true resolution: - integrity: sha512-tnr0V1ooakYr1aRLXQLzCn2GVG1kBTW3FWpRyC+NgrR3ntsouVpJOlTOV0BS4YLATx3/c+x3h/uBq9lWJlUAtQ== + integrity: sha512-F8kPr56HZmmKy0mHOXyStvEXEIvaluHlXJTYiLrwdDh1cnl/RhLp6F/dnR+mOsoKLLt3O9qYZfaAPBtm1e8Pfw== /fsevents/2.1.3: deprecated: '"Please update to latest v2.3 or v2.2"' dev: true @@ -73,7 +73,7 @@ packages: dev: true resolution: integrity: sha512-rArEXAgsBG4UgRGcynxWIWKFvh/XZCcS8UJdHhwy91zwAvCZIbcs+vAbflgBnNjYMs/i/i+/Ux6IZhML1yPvxg== - /rollup/2.38.0: + /rollup/2.38.1: dev: true engines: node: '>=10.0.0' @@ -81,7 +81,7 @@ packages: optionalDependencies: fsevents: 2.1.3 resolution: - integrity: sha512-ay9zDiNitZK/LNE/EM2+v5CZ7drkB2xyDljvb1fQJCGnq43ZWRkhxN145oV8GmoW1YNi4sA/1Jdkr2LfawJoXw== + integrity: sha512-q07T6vU/V1kqM8rGRRyCgEvIQcIAXoKIE5CpkYAlHhfiWM1Iuh4dIPWpIbqFngCK6lwAB2aYHiUVhIbSWHQWhw== /solid-app-router/0.0.19_solid-js@0.23.11: dependencies: solid-js: 0.23.11 @@ -102,24 +102,24 @@ packages: solid-js: ^0.23.0 resolution: integrity: sha512-J2L9smSBYJipXMmMWIRlZxt+CKt6JA3npGYoSbVMppN7B1OMmMXaU9XGM2QNc+1JMo2G6hEd41JJ2+tTPOMa6A== - /solid-utils/0.2.0: + /solid-utils/0.2.1: dependencies: solid-js: 0.23.11 dev: false resolution: - integrity: sha512-A7vdzRw+1vV2olLg/wYP7+U+fy8hL8m/4aSlem9sRQa5KVSPAtwB+2gMMdLbQi90fiXwrRC6uFLY1gxqrMos2g== + integrity: sha512-lKezri98G+5HRVD+ctsI8RJSivhLiy/50/9XW1IsPwIpwWq3zreR40DvkCTyX9xiY8OG36RgRbtXtUCcVP/4Pw== /source-map/0.6.1: dev: true engines: node: '>=0.10.0' resolution: integrity: sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g== - /vite/2.0.0-beta.44: + /vite/2.0.0-beta.59: dependencies: - esbuild: 0.8.34 + esbuild: 0.8.37 postcss: 8.2.4 resolve: 1.19.0 - rollup: 2.38.0 + rollup: 2.38.1 dev: true engines: node: '>=12.0.0' @@ -127,10 +127,10 @@ packages: optionalDependencies: fsevents: 2.1.3 resolution: - integrity: sha512-NTzmP7HEKDg3J5r3I22f87jK3ugPVEU81BQ8hWn3hNWU0msCziUlj7aHwItSUEbQA+ymqO3TBO2fN7Aa+OKckQ== + integrity: sha512-tlxEPFpVI1wV+vk+t/ypwBZfNmxKcorok8YF82MrQIqCDeRXnHvp33oWPIsRrO0V7UdnnlkKQOJJiIi3AIUFOA== specifiers: solid-app-router: ^0.0.19 solid-js: ^0.23.11 solid-meta: ^0.23.11 - solid-utils: ^0.2.0 - vite: ^2.0.0-beta.44 + solid-utils: ^0.2.1 + vite: ^2.0.0-beta.59 diff --git a/playground/vite.config.ts b/playground/vite.config.ts index 72c988d..f32f91b 100644 --- a/playground/vite.config.ts +++ b/playground/vite.config.ts @@ -1,8 +1,6 @@ -import solid from '..'; -import type { UserConfig } from 'vite'; +import solid from '../src'; +import { defineConfig } from 'vite'; -const config: UserConfig = { +export default defineConfig({ plugins: [solid()], -}; - -export default config; +}); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 3bd9887..a634e10 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -2,18 +2,19 @@ dependencies: '@babel/core': 7.12.10 '@babel/preset-typescript': 7.12.7_@babel+core@7.12.10 babel-preset-solid: 0.23.8_@babel+core@7.12.10 + resolve.exports: 1.0.2 solid-js: 0.23.11 - vite: 2.0.0-beta.44 + vite: 2.0.0-beta.59 devDependencies: '@babel/plugin-transform-typescript': 7.12.1_@babel+core@7.12.10 - '@rollup/plugin-babel': 5.2.2_c3350e562b9c7998f506ec4b4cea4354 - '@rollup/plugin-node-resolve': 11.1.0_rollup@2.38.0 + '@rollup/plugin-babel': 5.2.3_382ab38cb5074cd8ab108fa5b3e2f72b + '@rollup/plugin-node-resolve': 11.1.1_rollup@2.38.1 '@skypack/package-check': 0.2.2 '@types/babel__core': 7.1.12 '@types/node': 14.14.22 prettier: 2.2.1 - rollup: 2.38.0 - rollup-plugin-cleaner: 1.0.0_rollup@2.38.0 + rollup: 2.38.1 + rollup-plugin-cleaner: 1.0.0_rollup@2.38.1 typescript: 4.1.3 lockfileVersion: 5.2 packages: @@ -219,13 +220,13 @@ packages: to-fast-properties: 2.0.0 resolution: integrity: sha512-lnIX7piTxOH22xE7fDXDbSHg9MM1/6ORnafpJmov5rs0kX5g4BZxeXNJLXsMRiO0U5Rb8/FvMS6xlTnTHvxonQ== - /@rollup/plugin-babel/5.2.2_c3350e562b9c7998f506ec4b4cea4354: + /@rollup/plugin-babel/5.2.3_382ab38cb5074cd8ab108fa5b3e2f72b: dependencies: '@babel/core': 7.12.10 '@babel/helper-module-imports': 7.12.5 - '@rollup/pluginutils': 3.1.0_rollup@2.38.0 + '@rollup/pluginutils': 3.1.0_rollup@2.38.1 '@types/babel__core': 7.1.12 - rollup: 2.38.0 + rollup: 2.38.1 dev: true engines: node: '>= 10.0.0' @@ -237,29 +238,29 @@ packages: '@types/babel__core': optional: true resolution: - integrity: sha512-MjmH7GvFT4TW8xFdIeFS3wqIX646y5tACdxkTO+khbHvS3ZcVJL6vkAHLw2wqPmkhwCfWHoNsp15VYNwW6JEJA== - /@rollup/plugin-node-resolve/11.1.0_rollup@2.38.0: + integrity: sha512-DOMc7nx6y5xFi86AotrFssQqCen6CxYn+zts5KSI879d4n1hggSb4TH3mjVgG17Vc3lZziWWfcXzrEmVdzPMdw== + /@rollup/plugin-node-resolve/11.1.1_rollup@2.38.1: dependencies: - '@rollup/pluginutils': 3.1.0_rollup@2.38.0 + '@rollup/pluginutils': 3.1.0_rollup@2.38.1 '@types/resolve': 1.17.1 builtin-modules: 3.2.0 deepmerge: 4.2.2 is-module: 1.0.0 resolve: 1.19.0 - rollup: 2.38.0 + rollup: 2.38.1 dev: true engines: node: '>= 10.0.0' peerDependencies: rollup: ^1.20.0||^2.0.0 resolution: - integrity: sha512-ouBBppRdWJKCllDXGzJ7ZIkYbaq+5TmyP0smt1vdJCFfoZhLi31vhpmjLhyo8lreHf4RoeSNllaWrvSqHpHRog== - /@rollup/pluginutils/3.1.0_rollup@2.38.0: + integrity: sha512-zlBXR4eRS+2m79TsUZWhsd0slrHUYdRx4JF+aVQm+MI0wsKdlpC2vlDVjmlGvtZY1vsefOT9w3JxvmWSBei+Lg== + /@rollup/pluginutils/3.1.0_rollup@2.38.1: dependencies: '@types/estree': 0.0.39 estree-walker: 1.0.1 picomatch: 2.2.2 - rollup: 2.38.0 + rollup: 2.38.1 dev: true engines: node: '>= 8.0.0' @@ -409,12 +410,12 @@ packages: node: '>=0.10.0' resolution: integrity: sha512-FJ3UgI4gIl+PHZm53knsuSFpE+nESMr7M4v9QcgB7S63Kj/6WqMiFQJpBBYz1Pt+66bZpP3Q7Lye0Oo9MPKEdg== - /esbuild/0.8.34: + /esbuild/0.8.37: dev: false hasBin: true requiresBuild: true resolution: - integrity: sha512-tnr0V1ooakYr1aRLXQLzCn2GVG1kBTW3FWpRyC+NgrR3ntsouVpJOlTOV0BS4YLATx3/c+x3h/uBq9lWJlUAtQ== + integrity: sha512-F8kPr56HZmmKy0mHOXyStvEXEIvaluHlXJTYiLrwdDh1cnl/RhLp6F/dnR+mOsoKLLt3O9qYZfaAPBtm1e8Pfw== /escape-string-regexp/1.0.5: engines: node: '>=0.8.0' @@ -579,6 +580,12 @@ packages: hasBin: true resolution: integrity: sha512-PqyhM2yCjg/oKkFPtTGUojv7gnZAoG80ttl45O6x2Ug/rMJw4wcc9k6aaf2hibP7BGVCCM33gZoGjyvt9mm16Q== + /resolve.exports/1.0.2: + dev: false + engines: + node: '>=10' + resolution: + integrity: sha512-1+PDdTR3xrGWB/NzXLkzS1+PQlJ+BOR2baBGJSVat4HasiY1mnkyAQws3FUTmBDB79oK54QFaDM8Ig9nUtJwvQ== /resolve/1.19.0: dependencies: is-core-module: 2.2.0 @@ -592,10 +599,10 @@ packages: hasBin: true resolution: integrity: sha512-uWjbaKIK3T1OSVptzX7Nl6PvQ3qAGtKEtVRjRuazjfL3Bx5eI409VZSqgND+4UNnmzLVdPj9FqFJNPqBZFve4w== - /rollup-plugin-cleaner/1.0.0_rollup@2.38.0: + /rollup-plugin-cleaner/1.0.0_rollup@2.38.1: dependencies: rimraf: 2.7.1 - rollup: 2.38.0 + rollup: 2.38.1 dev: true engines: node: '>= 8.0' @@ -603,14 +610,14 @@ packages: rollup: '> 1.0' resolution: integrity: sha512-q+Zf9estkFwGede9QzmbkhKeuXzlliOvcICVNzBHAs5xYPPs1XLtfin5TMU2tC2EYjmfaF97saY9MnQM6Og4eA== - /rollup/2.38.0: + /rollup/2.38.1: engines: node: '>=10.0.0' hasBin: true optionalDependencies: fsevents: 2.1.3 resolution: - integrity: sha512-ay9zDiNitZK/LNE/EM2+v5CZ7drkB2xyDljvb1fQJCGnq43ZWRkhxN145oV8GmoW1YNi4sA/1Jdkr2LfawJoXw== + integrity: sha512-q07T6vU/V1kqM8rGRRyCgEvIQcIAXoKIE5CpkYAlHhfiWM1Iuh4dIPWpIbqFngCK6lwAB2aYHiUVhIbSWHQWhw== /safe-buffer/5.1.2: dev: false resolution: @@ -654,12 +661,12 @@ packages: hasBin: true resolution: integrity: sha512-B3ZIOf1IKeH2ixgHhj6la6xdwR9QrLC5d1VKeCSY4tvkqhF2eqd9O7txNlS0PO3GrBAFIdr3L1ndNwteUbZLYg== - /vite/2.0.0-beta.44: + /vite/2.0.0-beta.59: dependencies: - esbuild: 0.8.34 + esbuild: 0.8.37 postcss: 8.2.4 resolve: 1.19.0 - rollup: 2.38.0 + rollup: 2.38.1 dev: false engines: node: '>=12.0.0' @@ -667,7 +674,7 @@ packages: optionalDependencies: fsevents: 2.1.3 resolution: - integrity: sha512-NTzmP7HEKDg3J5r3I22f87jK3ugPVEU81BQ8hWn3hNWU0msCziUlj7aHwItSUEbQA+ymqO3TBO2fN7Aa+OKckQ== + integrity: sha512-tlxEPFpVI1wV+vk+t/ypwBZfNmxKcorok8YF82MrQIqCDeRXnHvp33oWPIsRrO0V7UdnnlkKQOJJiIi3AIUFOA== /wrappy/1.0.2: dev: true resolution: @@ -682,15 +689,16 @@ specifiers: '@babel/core': ^7.12.7 '@babel/plugin-transform-typescript': ^7.12.1 '@babel/preset-typescript': ^7.12.7 - '@rollup/plugin-babel': ^5.2.2 - '@rollup/plugin-node-resolve': ^11.1.0 + '@rollup/plugin-babel': ^5.2.3 + '@rollup/plugin-node-resolve': ^11.1.1 '@skypack/package-check': ^0.2.2 '@types/babel__core': ^7.1.12 '@types/node': ^14.14.22 babel-preset-solid: ^0.23 prettier: ^2.2.1 - rollup: ^2.38.0 + resolve.exports: ^1.0.2 + rollup: ^2.38.1 rollup-plugin-cleaner: ^1.0.0 solid-js: ^0.23.11 typescript: ^4.1.2 - vite: ^2.0.0-beta.44 + vite: ^2.0.0-beta.59 diff --git a/src/index.ts b/src/index.ts index 47ecd32..331dfaa 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,6 +1,8 @@ import { Plugin } from 'vite'; import solid from 'babel-preset-solid'; import { transformAsync, TransformOptions } from '@babel/core'; +import { readFileSync } from 'fs'; +import { join } from 'path'; interface Options { moduleName: string; @@ -21,6 +23,16 @@ export default function solidPlugin(options?: Partial): Plugin { name: 'solid', config() { + // HACK: This is a temporary hack while I find a better to either + // transform JSX dependencies via Babel or find a better automated way + // to exclude JSX dependencies from deps optimization + const pkgPath = join(process.cwd(), 'package.json'); + const pkgContent = readFileSync(pkgPath, { encoding: 'utf-8' }); + const pkgParsed = JSON.parse(pkgContent); + const deps = Object.keys(pkgParsed.dependencies); + + const exclude = deps.filter((dep) => dep !== 'solid-js' && dep.includes('solid')); + return { /** * We only need esbuild on .ts or .js files. @@ -28,7 +40,10 @@ export default function solidPlugin(options?: Partial): Plugin { */ esbuild: { include: /\.ts$/ }, dedupe: ['solid-js', 'solid-js/web'], - optimizeDeps: { include: ['solid-js/web'] }, + optimizeDeps: { + include: ['solid-js/web'], + exclude, + }, }; }, @@ -44,7 +59,7 @@ export default function solidPlugin(options?: Partial): Plugin { presets: [[solid, options]], }; - if (id.endsWith('tsx')) { + if (id.includes('tsx')) { opts.presets.push(require('@babel/preset-typescript')); } diff --git a/tsconfig.json b/tsconfig.json index dafc220..9debd73 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -8,6 +8,7 @@ "strict": false, "declaration": true, "noUnusedLocals": true, + "skipLibCheck": true, "esModuleInterop": true, "allowSyntheticDefaultImports": true, "declarationDir": "dist/types",