Skip to content

Commit

Permalink
Merge pull request #10 from Bisstocuz/feat/user-defined-pollyfill
Browse files Browse the repository at this point in the history
feat: user defined pollyfill's url and dependencies
  • Loading branch information
JayaKrishnaNamburu authored Aug 2, 2023
2 parents e3de1cd + 3e9c5df commit 5218d23
Show file tree
Hide file tree
Showing 5 changed files with 631 additions and 627 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ When passed, downloads the dependencies and bundles them with the build. But in

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

### pollyfillProvider

`pollyfillProvider` allow users to define their own pollyfill provider instead of `ga.jspm.io`, it can be a function `(version: string) => string` or a `string`. For function, the parameter `version` is `es-module-shims`'s version, user should return a complete url like `https://ga.jspm.io/npm:[email protected]/dist/es-module-shims.js`.

# 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:
Expand Down
4 changes: 4 additions & 0 deletions plugin/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ When passed, downloads the dependencies and bundles them with the build. But in

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

### pollyfillProvider

`pollyfillProvider` allow users to define their own pollyfill provider instead of `ga.jspm.io`, it can be a function `(version: string) => string` or a `string`. For function, the parameter `version` is `es-module-shims`'s version, user should return a complete url like `https://ga.jspm.io/npm:[email protected]/dist/es-module-shims.js`.

# 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:
Expand Down
2 changes: 1 addition & 1 deletion plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"@vue/compiler-dom": "^3.2.31"
},
"dependencies": {
"@jspm/generator": "1.1.1"
"@jspm/generator": "^1.1.1"
},
"peerDependencies": {
"vite": "*"
Expand Down
10 changes: 9 additions & 1 deletion plugin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type { HtmlTagDescriptor, Plugin } from "vite";
type PluginOptions = GeneratorOptions & {
downloadDeps?: boolean;
debug?: boolean;
pollyfillProvider?: ((version: string) => string) | string;
};

const getDefaultOptions = (): PluginOptions => ({
Expand Down Expand Up @@ -182,11 +183,18 @@ async function plugin(pluginOptions?: PluginOptions): Promise<Plugin[]> {
async transform(html) {
resolvedDeps.clear();
const esModuleShims = await getLatestVersionOfShims();
let srcUrl = `https://ga.jspm.io/npm:es-module-shims@${esModuleShims}/dist/es-module-shims.js`
if (options.pollyfillProvider) {
if (typeof options.pollyfillProvider === 'function')
srcUrl = options.pollyfillProvider(esModuleShims)
else if (typeof options.pollyfillProvider === 'string')
srcUrl = options.pollyfillProvider
}
const tags: HtmlTagDescriptor[] = [
{
tag: "script",
attrs: {
src: `https://ga.jspm.io/npm:es-module-shims@${esModuleShims}/dist/es-module-shims.js`,
src: srcUrl,
async: true,
},
injectTo: "head-prepend",
Expand Down
Loading

0 comments on commit 5218d23

Please sign in to comment.