|
Last change
on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago |
|
Fix frontend appearance
|
-
Property mode
set to
100644
|
|
File size:
671 bytes
|
| Line | |
|---|
| 1 | # import-local
|
|---|
| 2 |
|
|---|
| 3 | > Let a globally installed package use a locally installed version of itself if available
|
|---|
| 4 |
|
|---|
| 5 | Useful for CLI tools that want to defer to the user's locally installed version when available, but still work if it's not installed locally. For example, [AVA](https://avajs.dev) and [XO](https://github.com/xojs/xo) uses this method.
|
|---|
| 6 |
|
|---|
| 7 | ## Install
|
|---|
| 8 |
|
|---|
| 9 | ```sh
|
|---|
| 10 | npm install import-local
|
|---|
| 11 | ```
|
|---|
| 12 |
|
|---|
| 13 | ## Usage
|
|---|
| 14 |
|
|---|
| 15 | ```js
|
|---|
| 16 | import importLocal from 'import-local';
|
|---|
| 17 |
|
|---|
| 18 | if (importLocal(import.meta.url)) {
|
|---|
| 19 | console.log('Using local version of this package');
|
|---|
| 20 | } else {
|
|---|
| 21 | // Code for both global and local version here…
|
|---|
| 22 | }
|
|---|
| 23 | ```
|
|---|
| 24 |
|
|---|
| 25 | You can also pass in `__filename` when used in a CommonJS context.
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.