Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: user defined pollyfill's url and dependencies #10

Merged
merged 2 commits into from
Aug 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading