npm package export path definitions Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 00:00UTC (8:00pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Do a “git export” (like “svn export”)?Where does npm install packages?How can I update NodeJS and NPM to the next versions?Find the version of an installed npm packagenpm throws error without sudoWhat is the difference between Bower and npm?What's the difference between dependencies, devDependencies and peerDependencies in npm package.json file?What is the --save option for npm install?NPM vs. Bower vs. Browserify vs. Gulp vs. Grunt vs. WebpackDo I commit the package-lock.json file created by npm 5?
Why do we need to use the builder design pattern when we can do the same thing with setters?
Why does the remaining Rebel fleet at the end of Rogue One seem dramatically larger than the one in A New Hope?
How fail-safe is nr as stop bytes?
Performance gap between vector<bool> and array
How much damage would a cupful of neutron star matter do to the Earth?
Is there a kind of relay only consumes power when switching?
Do I really need to have a message in a novel to appeal to readers?
How to install press fit bottom bracket into new frame
What do you call the main part of a joke?
Why aren't air breathing engines used as small first stages?
Why should I vote and accept answers?
Illegal assignment from sObject to Id
How to compare two different files line by line in unix?
Did Deadpool rescue all of the X-Force?
How do I use the new nonlinear finite element in Mathematica 12 for this equation?
What was the first language to use conditional keywords?
Sum letters are not two different
How do I find out the mythology and history of my Fortress?
Can the Great Weapon Master feat's damage bonus and accuracy penalty apply to attacks from the Spiritual Weapon spell?
SF book about people trapped in a series of worlds they imagine
What's the meaning of "fortified infraction restraint"?
Can anything be seen from the center of the Boötes void? How dark would it be?
Effects on objects due to a brief relocation of massive amounts of mass
Take 2! Is this homebrew Lady of Pain warlock patron balanced?
npm package export path definitions
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 23, 2019 at 00:00UTC (8:00pm US/Eastern)
Data science time! April 2019 and salary with experience
The Ask Question Wizard is Live!Do a “git export” (like “svn export”)?Where does npm install packages?How can I update NodeJS and NPM to the next versions?Find the version of an installed npm packagenpm throws error without sudoWhat is the difference between Bower and npm?What's the difference between dependencies, devDependencies and peerDependencies in npm package.json file?What is the --save option for npm install?NPM vs. Bower vs. Browserify vs. Gulp vs. Grunt vs. WebpackDo I commit the package-lock.json file created by npm 5?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I'm generating my first set of npm packages to support a react-native environment. I am looking to configure the packages in such a way that the contents is intrinsically organized and can be easily distinguished by import statements on the client end.
Given 4 function definitions defined in my npm package (package name: super-cool-animals):
snakes.ts
export function Boa()
export function Anaconda()
birds.ts
export function Pigeon()
export function Hawk()
I would like the consumer of the library to be able to install the library:
npm install --save super-cool-animals
And then import them as such:
import Boa, Anaconda from 'super-cool-animals/snakes'
import Pigeon, Hawk from 'super-cool-animals/birds'
Pigeon(); // direct access to the function!
I'm having a hard time identifying the proper mechanism to achieve this, and I believe I've seen this mechanism in some environments (ie. angular)
I've seen some suggestions allowing you to combine them into a single variable as a for instance by using index.ts files:
snakes/index.ts
export * from './snakes.ts'
birds/index.ts
export * from './birds.ts
./index.ts
import * as Birds from './birds'
import * as Snakes from './snakes'
export Birds, Snakes
But this has an ugly end result, you now have to reference the container to get at the function:
Consumer of the library:
import Birds from 'super-cool-animals';
Birds.Pigeon();
Any assistance is appreciated. Thank you.
react-native npm import package export
add a comment |
I'm generating my first set of npm packages to support a react-native environment. I am looking to configure the packages in such a way that the contents is intrinsically organized and can be easily distinguished by import statements on the client end.
Given 4 function definitions defined in my npm package (package name: super-cool-animals):
snakes.ts
export function Boa()
export function Anaconda()
birds.ts
export function Pigeon()
export function Hawk()
I would like the consumer of the library to be able to install the library:
npm install --save super-cool-animals
And then import them as such:
import Boa, Anaconda from 'super-cool-animals/snakes'
import Pigeon, Hawk from 'super-cool-animals/birds'
Pigeon(); // direct access to the function!
I'm having a hard time identifying the proper mechanism to achieve this, and I believe I've seen this mechanism in some environments (ie. angular)
I've seen some suggestions allowing you to combine them into a single variable as a for instance by using index.ts files:
snakes/index.ts
export * from './snakes.ts'
birds/index.ts
export * from './birds.ts
./index.ts
import * as Birds from './birds'
import * as Snakes from './snakes'
export Birds, Snakes
But this has an ugly end result, you now have to reference the container to get at the function:
Consumer of the library:
import Birds from 'super-cool-animals';
Birds.Pigeon();
Any assistance is appreciated. Thank you.
react-native npm import package export
add a comment |
I'm generating my first set of npm packages to support a react-native environment. I am looking to configure the packages in such a way that the contents is intrinsically organized and can be easily distinguished by import statements on the client end.
Given 4 function definitions defined in my npm package (package name: super-cool-animals):
snakes.ts
export function Boa()
export function Anaconda()
birds.ts
export function Pigeon()
export function Hawk()
I would like the consumer of the library to be able to install the library:
npm install --save super-cool-animals
And then import them as such:
import Boa, Anaconda from 'super-cool-animals/snakes'
import Pigeon, Hawk from 'super-cool-animals/birds'
Pigeon(); // direct access to the function!
I'm having a hard time identifying the proper mechanism to achieve this, and I believe I've seen this mechanism in some environments (ie. angular)
I've seen some suggestions allowing you to combine them into a single variable as a for instance by using index.ts files:
snakes/index.ts
export * from './snakes.ts'
birds/index.ts
export * from './birds.ts
./index.ts
import * as Birds from './birds'
import * as Snakes from './snakes'
export Birds, Snakes
But this has an ugly end result, you now have to reference the container to get at the function:
Consumer of the library:
import Birds from 'super-cool-animals';
Birds.Pigeon();
Any assistance is appreciated. Thank you.
react-native npm import package export
I'm generating my first set of npm packages to support a react-native environment. I am looking to configure the packages in such a way that the contents is intrinsically organized and can be easily distinguished by import statements on the client end.
Given 4 function definitions defined in my npm package (package name: super-cool-animals):
snakes.ts
export function Boa()
export function Anaconda()
birds.ts
export function Pigeon()
export function Hawk()
I would like the consumer of the library to be able to install the library:
npm install --save super-cool-animals
And then import them as such:
import Boa, Anaconda from 'super-cool-animals/snakes'
import Pigeon, Hawk from 'super-cool-animals/birds'
Pigeon(); // direct access to the function!
I'm having a hard time identifying the proper mechanism to achieve this, and I believe I've seen this mechanism in some environments (ie. angular)
I've seen some suggestions allowing you to combine them into a single variable as a for instance by using index.ts files:
snakes/index.ts
export * from './snakes.ts'
birds/index.ts
export * from './birds.ts
./index.ts
import * as Birds from './birds'
import * as Snakes from './snakes'
export Birds, Snakes
But this has an ugly end result, you now have to reference the container to get at the function:
Consumer of the library:
import Birds from 'super-cool-animals';
Birds.Pigeon();
Any assistance is appreciated. Thank you.
react-native npm import package export
react-native npm import package export
edited Mar 9 at 10:11
RobC
6,91792741
6,91792741
asked Mar 8 at 20:28
GlorifundelGlorifundel
201210
201210
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Turns out the answer was pretty simple, lets take our example hypothetical where you want each category broken out by animal type, but you only want one package to be installed.
> super-cool-animals
> snakes
anaconda.js
boa.js
package.json
index.js
> birds
hawk.js
pigeon.js
package.json
index.js
package.json
readme.md
index.js
each index file simply does an export of the files or functions of interest at that level
index.js
import * as Birds from './birds'
import * as Snakes from './snakes'
export Birds, Snakes
snakes/index.js
export * from './anaconda.js'
export * from './boa.js'
birds/index.js
export * from './hawk.js'
export * from './pigeon.js'
Now moving on to the package.json files: the top level package file describes any dependencies, author, name of the library to be used in importing etc. The animal - specific - package.json files simply describe the name of the library to import.
package.json
"name": "super-cool-animals",
"version": "1.0.0",
"description": "Super cool animal library",
"main": "index.js",
"author": "Kevin Quinn <glorifundel@gmail.com>",
"license": "MIT",
"dependencies": ,
"peerDependencies": ,
"devDependencies":
The package files found at the lower level (birds and snakes folder) are simply describing the available relative path.
snakes/package.json
"name": "super-cool-animals/snakes",
"main": "index.js"
birds/package.json
"name": "super-cool-animals/birds",
"main": "index.js"
With all that defined, you can now install the npm package, and the client can nicely define their imports:
import Hawk from 'super-cool-animals/birds';
const SomeBird = Hawk();
Not sure if this is the best solution, but it seemed to function for me, I hope it is helpful to someone, and if there is a better or cleaner solution please post it and I will be happy to accept a better answer, or update my own answer.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55070559%2fnpm-package-export-path-definitions%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Turns out the answer was pretty simple, lets take our example hypothetical where you want each category broken out by animal type, but you only want one package to be installed.
> super-cool-animals
> snakes
anaconda.js
boa.js
package.json
index.js
> birds
hawk.js
pigeon.js
package.json
index.js
package.json
readme.md
index.js
each index file simply does an export of the files or functions of interest at that level
index.js
import * as Birds from './birds'
import * as Snakes from './snakes'
export Birds, Snakes
snakes/index.js
export * from './anaconda.js'
export * from './boa.js'
birds/index.js
export * from './hawk.js'
export * from './pigeon.js'
Now moving on to the package.json files: the top level package file describes any dependencies, author, name of the library to be used in importing etc. The animal - specific - package.json files simply describe the name of the library to import.
package.json
"name": "super-cool-animals",
"version": "1.0.0",
"description": "Super cool animal library",
"main": "index.js",
"author": "Kevin Quinn <glorifundel@gmail.com>",
"license": "MIT",
"dependencies": ,
"peerDependencies": ,
"devDependencies":
The package files found at the lower level (birds and snakes folder) are simply describing the available relative path.
snakes/package.json
"name": "super-cool-animals/snakes",
"main": "index.js"
birds/package.json
"name": "super-cool-animals/birds",
"main": "index.js"
With all that defined, you can now install the npm package, and the client can nicely define their imports:
import Hawk from 'super-cool-animals/birds';
const SomeBird = Hawk();
Not sure if this is the best solution, but it seemed to function for me, I hope it is helpful to someone, and if there is a better or cleaner solution please post it and I will be happy to accept a better answer, or update my own answer.
add a comment |
Turns out the answer was pretty simple, lets take our example hypothetical where you want each category broken out by animal type, but you only want one package to be installed.
> super-cool-animals
> snakes
anaconda.js
boa.js
package.json
index.js
> birds
hawk.js
pigeon.js
package.json
index.js
package.json
readme.md
index.js
each index file simply does an export of the files or functions of interest at that level
index.js
import * as Birds from './birds'
import * as Snakes from './snakes'
export Birds, Snakes
snakes/index.js
export * from './anaconda.js'
export * from './boa.js'
birds/index.js
export * from './hawk.js'
export * from './pigeon.js'
Now moving on to the package.json files: the top level package file describes any dependencies, author, name of the library to be used in importing etc. The animal - specific - package.json files simply describe the name of the library to import.
package.json
"name": "super-cool-animals",
"version": "1.0.0",
"description": "Super cool animal library",
"main": "index.js",
"author": "Kevin Quinn <glorifundel@gmail.com>",
"license": "MIT",
"dependencies": ,
"peerDependencies": ,
"devDependencies":
The package files found at the lower level (birds and snakes folder) are simply describing the available relative path.
snakes/package.json
"name": "super-cool-animals/snakes",
"main": "index.js"
birds/package.json
"name": "super-cool-animals/birds",
"main": "index.js"
With all that defined, you can now install the npm package, and the client can nicely define their imports:
import Hawk from 'super-cool-animals/birds';
const SomeBird = Hawk();
Not sure if this is the best solution, but it seemed to function for me, I hope it is helpful to someone, and if there is a better or cleaner solution please post it and I will be happy to accept a better answer, or update my own answer.
add a comment |
Turns out the answer was pretty simple, lets take our example hypothetical where you want each category broken out by animal type, but you only want one package to be installed.
> super-cool-animals
> snakes
anaconda.js
boa.js
package.json
index.js
> birds
hawk.js
pigeon.js
package.json
index.js
package.json
readme.md
index.js
each index file simply does an export of the files or functions of interest at that level
index.js
import * as Birds from './birds'
import * as Snakes from './snakes'
export Birds, Snakes
snakes/index.js
export * from './anaconda.js'
export * from './boa.js'
birds/index.js
export * from './hawk.js'
export * from './pigeon.js'
Now moving on to the package.json files: the top level package file describes any dependencies, author, name of the library to be used in importing etc. The animal - specific - package.json files simply describe the name of the library to import.
package.json
"name": "super-cool-animals",
"version": "1.0.0",
"description": "Super cool animal library",
"main": "index.js",
"author": "Kevin Quinn <glorifundel@gmail.com>",
"license": "MIT",
"dependencies": ,
"peerDependencies": ,
"devDependencies":
The package files found at the lower level (birds and snakes folder) are simply describing the available relative path.
snakes/package.json
"name": "super-cool-animals/snakes",
"main": "index.js"
birds/package.json
"name": "super-cool-animals/birds",
"main": "index.js"
With all that defined, you can now install the npm package, and the client can nicely define their imports:
import Hawk from 'super-cool-animals/birds';
const SomeBird = Hawk();
Not sure if this is the best solution, but it seemed to function for me, I hope it is helpful to someone, and if there is a better or cleaner solution please post it and I will be happy to accept a better answer, or update my own answer.
Turns out the answer was pretty simple, lets take our example hypothetical where you want each category broken out by animal type, but you only want one package to be installed.
> super-cool-animals
> snakes
anaconda.js
boa.js
package.json
index.js
> birds
hawk.js
pigeon.js
package.json
index.js
package.json
readme.md
index.js
each index file simply does an export of the files or functions of interest at that level
index.js
import * as Birds from './birds'
import * as Snakes from './snakes'
export Birds, Snakes
snakes/index.js
export * from './anaconda.js'
export * from './boa.js'
birds/index.js
export * from './hawk.js'
export * from './pigeon.js'
Now moving on to the package.json files: the top level package file describes any dependencies, author, name of the library to be used in importing etc. The animal - specific - package.json files simply describe the name of the library to import.
package.json
"name": "super-cool-animals",
"version": "1.0.0",
"description": "Super cool animal library",
"main": "index.js",
"author": "Kevin Quinn <glorifundel@gmail.com>",
"license": "MIT",
"dependencies": ,
"peerDependencies": ,
"devDependencies":
The package files found at the lower level (birds and snakes folder) are simply describing the available relative path.
snakes/package.json
"name": "super-cool-animals/snakes",
"main": "index.js"
birds/package.json
"name": "super-cool-animals/birds",
"main": "index.js"
With all that defined, you can now install the npm package, and the client can nicely define their imports:
import Hawk from 'super-cool-animals/birds';
const SomeBird = Hawk();
Not sure if this is the best solution, but it seemed to function for me, I hope it is helpful to someone, and if there is a better or cleaner solution please post it and I will be happy to accept a better answer, or update my own answer.
edited Mar 9 at 10:11
RobC
6,91792741
6,91792741
answered Mar 9 at 3:53
GlorifundelGlorifundel
201210
201210
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55070559%2fnpm-package-export-path-definitions%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown