javascript - 通过 jspm 安装带有依赖项的 npm 包

标签 javascript npm jspm

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

如果package.json npm的文件包包含依赖项,我希望它也将它们安装在包内。因此,在该包文件夹中,我期望有一个 node_modules包含包的文件夹。但是,当我运行命令来安装 npm 时包,它不会安装 node_modules我必须手动转到该文件夹​​并运行 npm install为了让这些出现。这意味着如果不手动运行此命令,我无法引用包本身内的其他文件/依赖项。有什么我可以通过 jspm 运行的吗?确保安装这些?

最佳答案

不,您目前无法在 JSPM 中执行此操作,并且我相信 JSPM 尚未真正解析 NPM 包。我认为这方面有工作要做,但在我发言时尚未完成。

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

Front end plugin

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

您需要从此处安装 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 安装。这将为您安装所有内容,并为您的环境提供一站式服务。我们已经使用这个工具有一段时间了,我们总是发现它可靠、灵活,并且将各种工具绑定(bind)在一起 - 它也得到了很好的支持。

关于javascript - 通过 jspm 安装带有依赖项的 npm 包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38892823/

相关文章:

javascript - 如何在pentaho中将外部javascript变量作为sql参数传递?

javascript - 如果它在 jquery 中,重复将不起作用

javascript - 通过 JSPM 加载(自定义)模块

javascript - 将 javascript 页面级变量传递到捆绑的 Angular2 RC 1 应用程序中

node.js - 无法用 Mongoose 保存空数组

aurelia - 使用jspm和system.js导入CSS并控制<head>中的顺序

javascript - const {something} = require (something) 在 Express 中不起作用

javascript - IE 和 Safari 中的 File() 构造函数

node.js - 如何排除不安全的 package.json transient 依赖项?

javascript - 迁移到 TypeScript。为什么我的函数不被识别?