Coder Social home page Coder Social logo

unpkg CDN as a fallback? about servor HOT 5 CLOSED

lukejacksonn avatar lukejacksonn commented on May 30, 2024
unpkg CDN as a fallback?

from servor.

Comments (5)

osdevisnot avatar osdevisnot commented on May 30, 2024 1

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.

from servor.

lukejacksonn avatar lukejacksonn commented on May 30, 2024

I think this is a really interesting idea and would like to see it evolve. Currently I use servor with es module only projects (without local dependencies) and currently manage by being explicit about my import urls so doing https://unpkg.com/es-react for example.

But it would be nice not to have to write https://unpkg.com everywhere. You might be interested in a few other threads that I have been having with developers in other bundler camps (pikapkg and webpack) over in lukejacksonn/perflink#15

from servor.

osdevisnot avatar osdevisnot commented on May 30, 2024

Digging deeper on this, it seems we have 2 alternative approaches we can go with.

First approach would be to use @babel/core with babel-plugin-bare-import-rewrite and follow what express-transform-bare-module-specifiers does. Something like this:

				const result = babel.transformSync(body, {
					filename: path.resolve(rootDir, request.path.replace(/^\//, '')),
					plugins: [
						['bare-import-rewrite', {
							modulesDir: modulesUrl,
							rootBaseDir: rootDir
						}]
					],
					sourceMaps: 'inline'
				});

Second approach would be to use 😱😱 REGEX 😱😱 to replace the file content before sending a response. Something like this:

https://regex101.com/r/6mZUJu/1

Babel approach would add a dependency to servor, which kind of defeats the no-dependency constraints. However REGEX can be hard to read and add maintenance overhead.

from servor.

lukejacksonn avatar lukejacksonn commented on May 30, 2024

The regex route sounds much more adoptable at this point. I have written one like this before.. it wasn't too bad but I probably missed some edge cases.

from servor.

lukejacksonn avatar lukejacksonn commented on May 30, 2024

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!

from servor.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.