Skip to content

Commit

Permalink
✨ Support "type: module"
Browse files Browse the repository at this point in the history
  • Loading branch information
amoutonbrady committed Apr 2, 2021
1 parent a70b7b7 commit 81b28a3
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 16 deletions.
14 changes: 8 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down Expand Up @@ -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",
Expand Down
4 changes: 3 additions & 1 deletion playground/package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
{
"name": "playground",
"description": "playground",
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build"
},
"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",
Expand Down
2 changes: 2 additions & 0 deletions playground/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions playground/vite.config.ts → playground/vite.config.js
Original file line number Diff line number Diff line change
@@ -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: [
Expand Down
47 changes: 47 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -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'];
Expand All @@ -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',
},
Expand All @@ -34,6 +36,7 @@ const config = {
'@babel/preset-typescript',
],
}),
cjs({ extensions }),
nodeResolve({ extensions, preferBuiltins: true, browser: false }),
],
};
Expand Down
16 changes: 11 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -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');
Expand Down Expand Up @@ -84,12 +90,12 @@ export default function solidPlugin(options: Partial<Options> = {}): 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
Expand Down

0 comments on commit 81b28a3

Please sign in to comment.