通过带有依赖项的jspm安装npm软件包

问题描述 投票:16回答:2

我知道我可以通过运行:npm来安装jspm jspm install npm:<pkg-name>包,这将允许我在开发中使用它(例如在我的JS文件中:import myPackage from 'myPackage';)。

如果package.json包的npm文件包含依赖项,我希望它也能在包中安装它们。所以在那个包文件夹中,我希望有一个带有包的node_modules文件夹。但是,当我运行命令安装npm包时,它不会安装node_modules,我将不得不手动转到该文件夹​​并运行npm install以显示这些。这意味着我无法在不手动运行此命令的情况下引用包本身中的其他文件/依赖项。有没有什么我可以通过jspm运行,以确保这些安装?

javascript npm jspm
2个回答
0
投票

不,你不能做当前的JSPM,我相信JSPM还没有真正解决NPM包。我认为有关于此的工作,但在我发言时没有。

我建议你看一下下面的maven插件:

Front end plugin

我们在几个项目中使用了它,它允许您运行几种不同的安装风格,以便您可以将项目绑定在一起。

您需要从这里安装maven 3:

Maven download

然后,您将需要一个基本的pom.xml来运行jspm install以及npm install。然后,您可以运行您的Karma测试并从此设置进行编译。

来自文档:

<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>

将启动jspm安装并最终:

<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>

将为您提供npm安装。这将为您安装一切,并为您的环境提供一站式服务。我们已经使用这个工具一段时间了,它一直被发现是可靠的,灵活的并且将各种工具绑定在一起 - 它也得到很好的支持。


0
投票

以下是您可以运行的命令列表:

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

两者都有一些依赖关系,但并非总是如此,也不在同一个结构中。虽然jspm可以处理node.js模块系统。也许您尝试添加的依赖项没有node_modules。

© www.soinside.com 2019 - 2024. All rights reserved.