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

Why don't you use deps.ts for React and so on? #41

Closed
sudokzt opened this issue Jul 13, 2020 · 2 comments
Closed

Why don't you use deps.ts for React and so on? #41

sudokzt opened this issue Jul 13, 2020 · 2 comments
Assignees
Labels
examples question Further information is requested

Comments

@sudokzt
Copy link

sudokzt commented Jul 13, 2020

Issue

This issue is question.

Why don't you use deps.ts for React and so on?

Details

I looked at Craig's nice entry.
Then I looked at this source in the repo. https://github.com/asos-craigmorten/opine/blob/main/examples/react/server.tsx

If the deps.ts seems to have the role of package.json, you can write following into deps.ts.

import { renderFileToString } from "https://deno.land/x/dejs@0.7.0/mod.ts";
import React from "https://dev.jspm.io/react@16.13.1";

Am I wrong?

@asos-craigmorten asos-craigmorten added the question Further information is requested label Jul 13, 2020
@asos-craigmorten asos-craigmorten self-assigned this Jul 13, 2020
@asos-craigmorten
Copy link
Collaborator

asos-craigmorten commented Jul 13, 2020

Hi @sudokzt 👋

You are correct - the current Deno precedent is to use a file called deps.ts as a place to write all of your imports of third-party modules so they can be managed from a central location. This can have benefits such as being a single place to upgrade dependencies (instead of all over your code), and is also support by tools such as the nest.land eggs CLI.

However, you don't have to be limited to this style of doing imports - it is simply something the community has adopted, likely because they are used to having a single place from Node.

As an alternative, some people are instead making use of Deno's import maps which is probably even more like using a package.json!

In the case of these examples, given they were relatively simple I did not worry with creating a deps.ts, instead just inlining the imports into the files that they are needed. If you prefer the deps.ts way of doing things then by all means use that in your code 😄 In fact, we use a deps.ts in the main Opine code!

If you're interested in a different perspective, there is also a good article by @wongjiahau which raises valid concerns on how a single mod.ts and deps.ts could actually be bad for your project. Specifically, it can really hurt start-up performance because although a file may only want to import a single module, Deno will end up compiling all modules referenced in the file!

For now I don't intend to spend the time updating the examples to use a deps.ts, but am very open to pull requests if you feel strongly that the examples should be using one 😄

@asos-craigmorten
Copy link
Collaborator

Going to close for now - happy to re-open if have further questions / feel strongly etc. 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
examples question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants