diff --git a/package.json b/package.json index c33ae06..3f64fb1 100644 --- a/package.json +++ b/package.json @@ -2,16 +2,17 @@ "name": "vite-plugin-solid", "version": "1.4.0", "description": "solid-js integration plugin for vite 2", + "type": "module", "files": [ "dist" ], - "main": "dist/cjs/index.js", - "module": "dist/esm/index.js", + "main": "dist/cjs/index.cjs", + "module": "dist/esm/index.mjs", "exports": { - "import": "./dist/esm/index.js", - "node": "./dist/cjs/index.js", - "default": "./dist/cjs/index.js", - "require": "./dist/cjs/index.js" + "import": "./dist/esm/index.mjs", + "node": "./dist/cjs/index.cjs", + "default": "./dist/cjs/index.cjs", + "require": "./dist/cjs/index.cjs" }, "types": "dist/types/index.d.ts", "scripts": { @@ -52,6 +53,7 @@ "@babel/plugin-transform-typescript": "^7.13.0", "@babel/preset-env": "^7.13.12", "@rollup/plugin-babel": "^5.3.0", + "@rollup/plugin-commonjs": "^18.0.0", "@rollup/plugin-node-resolve": "^11.2.1", "@skypack/package-check": "^0.2.2", "@types/babel__core": "^7.1.14", diff --git a/playground/package.json b/playground/package.json index d988918..06bc8c1 100644 --- a/playground/package.json +++ b/playground/package.json @@ -1,6 +1,7 @@ { "name": "playground", "description": "playground", + "type": "module", "scripts": { "dev": "vite", "build": "vite build" @@ -8,7 +9,8 @@ "license": "MIT", "devDependencies": { "@babel/plugin-syntax-top-level-await": "^7.12.13", - "vite": "^2.1.5" + "vite": "^2.1.5", + "vite-plugin-solid": "link:.." }, "dependencies": { "solid-app-router": "^0.0.36", diff --git a/playground/pnpm-lock.yaml b/playground/pnpm-lock.yaml index 858ef2b..f463969 100644 --- a/playground/pnpm-lock.yaml +++ b/playground/pnpm-lock.yaml @@ -6,6 +6,7 @@ dependencies: devDependencies: '@babel/plugin-syntax-top-level-await': 7.12.13 vite: 2.1.5 + vite-plugin-solid: link:.. lockfileVersion: 5.2 packages: /@babel/helper-plugin-utils/7.13.0: @@ -149,3 +150,4 @@ specifiers: solid-meta: ^0.25.0 solid-utils: ^0.5.0 vite: ^2.1.5 + vite-plugin-solid: link:.. diff --git a/playground/vite.config.ts b/playground/vite.config.js similarity index 83% rename from playground/vite.config.ts rename to playground/vite.config.js index 3d0b8d5..83811ac 100644 --- a/playground/vite.config.ts +++ b/playground/vite.config.js @@ -1,6 +1,5 @@ -import solid from '..'; +import solid from 'vite-plugin-solid'; import { defineConfig } from 'vite'; -import { resolve } from 'path'; export default defineConfig({ plugins: [ diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 53f5bda..1c7fe40 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -11,6 +11,7 @@ devDependencies: '@babel/plugin-transform-typescript': 7.13.0_@babel+core@7.13.14 '@babel/preset-env': 7.13.12_@babel+core@7.13.14 '@rollup/plugin-babel': 5.3.0_e1bee394eba3623d7a346f145a739161 + '@rollup/plugin-commonjs': 18.0.0_rollup@2.44.0 '@rollup/plugin-node-resolve': 11.2.1_rollup@2.44.0 '@skypack/package-check': 0.2.2 '@types/babel__core': 7.1.14 @@ -990,6 +991,23 @@ packages: optional: true resolution: integrity: sha512-9uIC8HZOnVLrLHxayq/PTzw+uS25E14KPUBh5ktF+18Mjo5yK0ToMMx6epY0uEgkjwJw0aBW4x2horYXh8juWw== + /@rollup/plugin-commonjs/18.0.0_rollup@2.44.0: + dependencies: + '@rollup/pluginutils': 3.1.0_rollup@2.44.0 + commondir: 1.0.1 + estree-walker: 2.0.2 + glob: 7.1.6 + is-reference: 1.2.1 + magic-string: 0.25.7 + resolve: 1.20.0 + rollup: 2.44.0 + dev: true + engines: + node: '>= 8.0.0' + peerDependencies: + rollup: ^2.30.0 + resolution: + integrity: sha512-fj92shhg8luw7XbA0HowAqz90oo7qtLGwqTKbyZ8pmOyH8ui5e+u0wPEgeHLH3djcVma6gUCUrjY6w5R2o1u6g== /@rollup/plugin-node-resolve/11.2.1_rollup@2.44.0: dependencies: '@rollup/pluginutils': 3.1.0_rollup@2.44.0 @@ -1060,6 +1078,10 @@ packages: dev: true resolution: integrity: sha512-EYNwp3bU+98cpU4lAWYYL7Zz+2gryWH1qbdDTidVd6hkiR6weksdbMadyXKXNPEkQFhXM+hVO9ZygomHXp+AIw== + /@types/estree/0.0.47: + dev: true + resolution: + integrity: sha512-c5ciR06jK8u9BstrmJyO97m+klJrrhCf9u3rLu3DEAJBirxRqSCvDQoYKmxuYwQI5SZChAWu+tq9oVlGRuzPAg== /@types/node/14.14.37: dev: true resolution: @@ -1190,6 +1212,10 @@ packages: /colorette/1.2.2: resolution: integrity: sha512-MKGMzyfeuutC/ZJ1cba9NqcNpfeqMUcYmyF1ZFY6/Cn7CNSAKx6a+s48sqLqyAiZuaP2TcqMhoo+dlwFnVxT9w== + /commondir/1.0.1: + dev: true + resolution: + integrity: sha1-3dgA2gxmEnOTzKWVDqloo6rxJTs= /concat-map/0.0.1: dev: true resolution: @@ -1256,6 +1282,10 @@ packages: dev: true resolution: integrity: sha512-1fMXF3YP4pZZVozF8j/ZLfvnR8NSIljt56UhbZ5PeeDmmGHpgpdwQt7ITlGvYaQukCvuBRMLEiKiYC+oeIg4cg== + /estree-walker/2.0.2: + dev: true + resolution: + integrity: sha512-Rfkk/Mp/DL7JVje3u18FxFujQlTNR2q6QfMSMB7AvCBx91NGj/ba3kCfza0f6dVDbw7YlRf/nDrn7pQrCCyQ/w== /esutils/2.0.3: dev: true engines: @@ -1345,6 +1375,12 @@ packages: dev: true resolution: integrity: sha1-Mlj7afeMFNW4FdZkM2tM/7ZEFZE= + /is-reference/1.2.1: + dependencies: + '@types/estree': 0.0.47 + dev: true + resolution: + integrity: sha512-U82MsXXiFIrjCK4otLT+o2NA2Cd2g5MLoOVXUZjIOhLurrRxpEXzI8O0KZHr3IjLvlAH1kTPYSuqer5T9ZVBKQ== /is-what/3.14.1: dev: false resolution: @@ -1385,6 +1421,12 @@ packages: /lodash/4.17.21: resolution: integrity: sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg== + /magic-string/0.25.7: + dependencies: + sourcemap-codec: 1.4.8 + dev: true + resolution: + integrity: sha512-4CrMT5DOHTDk4HYDlzmwu4FVCcIYI8gauveasrdCu2IKIFOJ3f0v/8MDGJCDL9oD2ppz/Av1b0Nj345H9M+XIA== /merge-anything/4.0.1: dependencies: is-what: 3.14.1 @@ -1590,6 +1632,10 @@ packages: node: '>=0.10.0' resolution: integrity: sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g== + /sourcemap-codec/1.4.8: + dev: true + resolution: + integrity: sha512-9NykojV5Uih4lgo5So5dtw+f0JgJX30KCNI8gwhz2J9A15wD0Ml6tjHKwf6fTSa6fAdVBdZeNOs9eJ71qCk8vA== /supports-color/5.5.0: dependencies: has-flag: 3.0.0 @@ -1670,6 +1716,7 @@ specifiers: '@babel/preset-env': ^7.13.12 '@babel/preset-typescript': ^7.13.0 '@rollup/plugin-babel': ^5.3.0 + '@rollup/plugin-commonjs': ^18.0.0 '@rollup/plugin-node-resolve': ^11.2.1 '@skypack/package-check': ^0.2.2 '@types/babel__core': ^7.1.14 diff --git a/rollup.config.js b/rollup.config.js index a635fd9..0becb44 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -1,6 +1,8 @@ +// @ts-check import cleaner from 'rollup-plugin-cleaner'; import { babel } from '@rollup/plugin-babel'; import { nodeResolve } from '@rollup/plugin-node-resolve'; +import cjs from '@rollup/plugin-commonjs'; import pkg from './package.json'; const extensions = ['.js', '.ts', '.json', '.tsx', '.jsx']; @@ -13,12 +15,12 @@ const config = { output: [ { format: 'esm', - dir: 'dist/esm', + file: 'dist/esm/index.mjs', sourcemap: true, }, { format: 'cjs', - dir: 'dist/cjs', + file: 'dist/cjs/index.cjs', sourcemap: true, exports: 'default', }, @@ -34,6 +36,7 @@ const config = { '@babel/preset-typescript', ], }), + cjs({ extensions }), nodeResolve({ extensions, preferBuiltins: true, browser: false }), ], }; diff --git a/src/index.ts b/src/index.ts index ebb6630..631dd31 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,7 +1,13 @@ -import { Plugin, UserConfig, AliasOptions, Alias } from 'vite'; -import { readFileSync } from 'fs'; import { transformAsync, TransformOptions } from '@babel/core'; +import ts from '@babel/preset-typescript'; +import solid from 'babel-preset-solid'; +import { readFileSync } from 'fs'; import { mergeAndConcat } from 'merge-anything'; +import { createRequire } from 'module'; +import solidRefresh from 'solid-refresh/babel'; +import { Alias, AliasOptions, Plugin, UserConfig } from 'vite'; + +const require = createRequire(import.meta.url); const runtimePublicPath = '/@solid-refresh'; const runtimeFilePath = require.resolve('solid-refresh/dist/solid-refresh.mjs'); @@ -84,12 +90,12 @@ export default function solidPlugin(options: Partial = {}): Plugin { const opts: TransformOptions = { filename: id, - presets: [[require('babel-preset-solid'), solidOptions]], - plugins: needHmr ? [[require('solid-refresh/babel'), { bundler: 'vite' }]] : [], + presets: [[solid, solidOptions]], + plugins: needHmr ? [[solidRefresh, { bundler: 'vite' }]] : [], }; if (id.includes('tsx')) { - opts.presets.push(require('@babel/preset-typescript')); + opts.presets.push(ts); } // Default value for babel user options