admin管理员组文章数量:1279241
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 mand 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 mand. Is there anything I can run via jspm
to ensure these install?
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 mand 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 mand. Is there anything I can run via jspm
to ensure these install?
3 Answers
Reset to default 1No 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 pile 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 mand,
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 mand,
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.
Here is a list of mand 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.
✌ An alternative
As alternative I can suggest dynamic-cdn-webpack-plugin, the trick is on development environment you will have node_modules
folder in your project, and for production it will inject the dependency from cdn servers.
本文标签: javascriptInstalling npm packages via jspm with dependenciesStack Overflow
版权声明:本文标题:javascript - Installing npm packages via jspm with dependencies - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741301787a2371130.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论