unpkg CDN as a fallback?
See original GitHub issueHi @lukejacksonn, first off, thank you so much for putting this together.
While using servor
for my prototype work, I wanted an ability to use servor
without even npm installing my dependencies 🎉 🎉
One way I was thinking to solve this, is by adding a check in servor
to see if we are serving a JS file. If a JS file is not available locally, we rewrite the URL to UNPKG CDN URL.
For Example:
Let’s say I have code like this in say index.js
:
import { patch, h } from 'superfine';
import store from '@vanillajs/store';
servor
would rewrite this to something like this (when node_modules
is not available):
import { patch, h } from 'https://unpkg.com/superfine@6.0.1?type=module';
import store from 'https://unpkg.com/@vanillajs/store@0.1.7?type=module';
To take it a step further, if I do not have package.json
, we simply rewrite the URL to something like this:
import { patch, h } from 'https://unpkg.com/superfine?type=module';
import store from 'https://unpkg.com/@vanillajs/store?type=module';
This idea has been explored before with owc-dev-server and works quite well using express-transform-bare-module-specifiers
However, I would like a no-dependency solution for this to be available in servor
thoughts/concerns?
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (5 by maintainers)
Top GitHub Comments
Awesome, I’ll try to get to this soon. We will need to explore if this can bring any unforeseen hurdles if we make it a default. Alternative would be to have a flag to disable this behavior.
Hey @osdevisnot if you figure this out then please open a PR and reference this issue. I’m very interested in what it might look like but am doing a tidy up here so am going to close for now!