Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Installing npm packages via jspm with dependencies

I understand that I can install npm packages with jspm by running: jspm install npm:<pkg-name> and this will allow me to use it in development (e.g. within my JS file: import myPackage from 'myPackage';).

If the package.json file of the npm package contains dependencies, I would like it to install those too within the package. So within that package folder, I would expect a node_modules folder with packages. However, when I run the command to install the npm package, it does not install the node_modules and I would have to manually go to the folder and run npm install for these to appear. This means I cannot reference the other files/dependencies within the package itself without manually running this command. Is there anything I can run via jspm to ensure these install?

like image 818
30secondstosam Avatar asked Aug 11 '16 09:08

30secondstosam


People also ask

How do I automatically install npm dependencies?

to install the dependencies automatically , first of all list them manually in package. json file and run the npm install (sometimes sudo npm install ) command.

What is JSPM in npm?

- jspm allows you to configure arbitrary registries to get your dependencies from (github and npm are configured by default)

Will npm install install all dependencies?

By default, npm install will install all modules listed as dependencies in package.


2 Answers

No you cannot do the currently in JSPM and I believe JSPM doesn't really resolve NPM packages yet. I think there is work on this but not available as I speak.

What I suggest is you take a look at is the following maven plugin:

Front end plugin

We have used this in several projects and it allows you run several different installation flavours so that you can bind your project together.

You will need to install maven 3 from here:

Maven download

You will then need a basic pom.xml to run jspm install as well as a npm install. You can then run your Karma tests and compile from this set-up too.

From the docs:

<execution>     <id>jspm install</id>     <goals>         <goal>jspm</goal>     </goals>      <configuration>         <!-- optional: The default argument is actually         "install", so unless you need to run some other jspm command,         you can remove this whole <configuration> section.         -->         <arguments>install</arguments>     </configuration> </execution> 

Will start the jspm install and finally:

<execution>     <id>npm install</id>     <goals>         <goal>npm</goal>     </goals>      <!-- optional: default phase is "generate-resources" -->     <phase>generate-resources</phase>      <configuration>         <!-- optional: The default argument is actually         "install", so unless you need to run some other npm command,         you can remove this whole <configuration> section.         -->         <arguments>install</arguments>     </configuration> </execution> 

Will provide you with the npm install. This will install everything for you and provide you with an all in one stop shop for your environment. We've been using this tool for a while now and it has always been found to be reliable, flexible and binds the various tooling together - it is also well supported.

like image 106
PeterS Avatar answered Oct 04 '22 07:10

PeterS


Here is a list of command you can run :

jspm install npm:myDependency jspm install --no-optionnal jspm install github:authorGithubAccount/myDependency npm install myDependency 

Some dependency are available on both, but not always and not in the same structure. Though jspm can handle node.js module system. Maybe the dependencie you try to add has no node_modules.

like image 25
Sandwell Avatar answered Oct 04 '22 07:10

Sandwell