Skip to content

Commit

Permalink
chore: upgrade deps and refactor vite plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
guybedford authored Feb 15, 2023
2 parents 9001749 + d5a3cc7 commit 9524f9d
Show file tree
Hide file tree
Showing 21 changed files with 1,942 additions and 1,229 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
strategy:
matrix:
node-version: [16.x, 14] # 14
os: [ubuntu-latest, windows-latest, macos-latest] # mac
os: [ubuntu-latest] # mac
fail-fast: false

steps:
Expand Down
44 changes: 26 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
> CDN: A content delivery network (CDN) refers to a geographically distributed group of servers which work together to provide fast delivery of Internet content. [Cloudflare.com](https://www.cloudflare.com/en-ca/learning/cdn/what-is-a-cdn/)
A vite plugin which externalizes dependencies and resolves them independently from **CDN (Content Delivery Network) providers** using [import maps](https://github.com/WICG/import-maps) and [es-module-shims](https://github.com/guybedford/es-module-shims)!
A vite plugin which externalizes dependencies and resolves them independently from **CDN (Content Delivery Network) providers** using [import maps](https://github.com/WICG/import-maps) and [es-module-shims](https://github.com/guybedford/es-module-shims)!
This plugin generates an import map for your app automatically in both development and production, and resolves dependencies based on that.

It is based on [@jspm/generator](https://github.com/jspm/generator) which supports different providers like *jspm*, *unpkg* and *skypack*.
It is based on [@jspm/generator](https://github.com/jspm/generator) which supports different providers like _jspm_, _unpkg_ and _skypack_.

## Usage

Expand All @@ -16,40 +16,48 @@ import { defineConfig } from "vite";
import jspmPlugin from "vite-plugin-jspm";

export default defineConfig({
plugins: [
jspmPlugin({
development: true // enables the plugin in `vite dev`
// optional object for @jspm/generator options and settings, more info in https://github.com/jspm/generator
}),
],
plugins: [jspmPlugin()],
});
```

## Custom options

### `inputMap`
`inputMap` is a `@jspm/generator` option. When passed, the plugin takes it as source of truth. And resolves the imports against it.

`inputMap` is a `@jspm/generator` option. When passed, the plugin takes it as source of truth. And resolves the imports against it.

### `downloadDeps`

When passed, downloads the dependencies and bundles them with the build. But in dev mode `vite dev`, the plugin serves the dependencies from the CDN.

### env

`env` is a `@jspm/generator` option. Users don't need to pass `production` or `development` option. The env is applied according to the vite env.

### debug

`debug` let's you skim through the logs during resolution and downloading pahses.

# Bundle size

You can see the bundle size of [`test/basic`](https://github.com/jspm/vite-plugin-jspm/tree/main/test/basic) example in two cases:
```
# without this plugin
dist/index.html 0.45 KiB
dist/assets/index.75d36a39.js 0.23 KiB / gzip: 0.17 KiB
dist/assets/vendor.75a6031c.js 128.58 KiB / gzip: 41.37 KiB

```
# with this plugin
dist/index.html 0.91 KiB
dist/assets/index.b911b8a6.js 0.23 KiB / gzip: 0.16 KiB
vite v4.1.1 building for production...
✓ 16 modules transformed.
build/index.html 4.80 kB
build/assets/index-8f42e5ff.css 9.58 kB │ gzip: 1.64 kB
build/assets/index-37524fa0.js 14.11 kB │ gzip: 3.71 kB
# with downloadDeps flag in the plugin
dist/index.html 0.50 KiB
dist/assets/index.1f44e570.js 140.50 KiB / gzip: 44.96 KiB
vite v4.1.1 building for production...
✓ 45 modules transformed.
build/index.html 2.42 kB
build/assets/index-8f42e5ff.css 9.58 kB │ gzip: 1.64 kB
build/assets/index-38fd63e9.js 187.02 kB │ gzip: 59.80 kB
```

# Contribution

Feel free to open issues and PRs!
26 changes: 13 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,21 @@
"dev": "pnpm -r --filter vite-plugin-jspm run dev"
},
"devDependencies": {
"@rollup/plugin-alias": "^3.1.9",
"@rollup/plugin-commonjs": "^21.0.2",
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^13.1.3",
"@rollup/plugin-alias": "^4.0.3",
"@rollup/plugin-commonjs": "^24.0.1",
"@rollup/plugin-json": "^6.0.0",
"@rollup/plugin-node-resolve": "^15.0.1",
"@types/node": "^18.0.0",
"cross-env": "^7.0.3",
"esbuild": "^0.14.27",
"esbuild-node-loader": "^0.6.5",
"puppeteer": "^13.5.1",
"esbuild": "^0.17.8",
"esbuild-node-loader": "^0.8.0",
"puppeteer": "^19.7.0",
"rimraf": "^3.0.2",
"rollup": "2.60",
"rollup-plugin-dts": "^4.2.0",
"rollup-plugin-esbuild": "^4.8.2",
"typescript": "^4.6.2",
"vite": "^2.9.5",
"vitest": "latest"
"rollup": "~3.15.0",
"rollup-plugin-dts": "^5.2.0",
"rollup-plugin-esbuild": "^5.0.0",
"typescript": "^4.9.5",
"vite": "^4.1.1",
"vitest": "^0.28.5"
}
}
10 changes: 2 additions & 8 deletions plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,10 @@
"homepage": "https://github.com/aslemammad/vite-plugin-jspm#readme",
"devDependencies": {
"@vue/compiler-core": "^3.2.31",
"@vue/compiler-dom": "^3.2.31",
"node-fetch": "^3.2.3",
"typescript": "^4.5.3",
"vite": "^2.9.5"
"@vue/compiler-dom": "^3.2.31"
},
"dependencies": {
"@jspm/generator": "1.0.0-beta.33"
},
"peerDependencies": {
"vite": "*"
"@jspm/generator": "^1.0.2"
},
"engines": {
"node": ">=14.0.0"
Expand Down
2 changes: 1 addition & 1 deletion plugin/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import resolve from '@rollup/plugin-node-resolve'
import commonjs from '@rollup/plugin-commonjs'
import json from '@rollup/plugin-json'
import alias from '@rollup/plugin-alias'
import pkg from './package.json'
import pkg from './package.json' assert { type: 'json'}

const entry = [
'src/index.ts',
Expand Down
Loading

0 comments on commit 9524f9d

Please sign in to comment.