Replies: 1 comment 1 reply
-
|
An import map is an additional tool which can address the "issue" of "wanting to use abbreviated, non-relative specifiers in place of relative URLs". Example:
export function add (numbers: number[]): number {
return numbers.reduce((sum, n) => sum + n);
}
{
"imports": {
"common/": "../../common-utils/"
}
}
import {add} from 'common/add/mod.ts';
export function average (numbers: number[]): number {
return add(numbers) / numbers.length;
}
import {assertStrictEquals} from 'https://deno.land/std@0.122.0/testing/asserts.ts';
import {average} from './mod.ts';
Deno.test('averages integers', () => {
const numbers = [1, 2, 3, 4];
const actual = average(numbers);
assertStrictEquals(actual, 2.5);
}); |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Use Case
a local private common utils module that used by multiple independent other projects.
Currently, I think of two ways: 1. import localhost URL. 2. import files
import localhost URL
import {...} from "http://localhost:port/a-common-module/mod.ts"deno run -r main.tsNote:
import file directly
For example,
import {...} from "../../some-path/all-local-modules/a-module".But local projects in different locations need to use different relative import path.
Question
Is this the best practice for private local common modules?
Beta Was this translation helpful? Give feedback.
All reactions