【问题标题】:How to use underscore.js with webpack如何在 webpack 中使用 underscore.js
【发布时间】:2017-04-14 13:37:31
【问题描述】:

我想在我的 Typescript Aurelia 应用程序中使用下划线。 我在其中创建了一个打字稿文件:

import * as _ from 'underscore'

但是 VS Code 说:

[ts] 找不到模块“下划线”

我已经把这个放到 webpack.config 中了:

plugins:[
    new webpack.ProvidePlugin({
      underscore:'underscore'
    })  
]

我也安装了下划线:

npm install --save underscore

我还需要做什么才能让它工作?

【问题讨论】:

  • 这里有一个错字:npm install --save undersocre。你复制/粘贴了吗?还是你把错字只写在这里?
  • 我在这里写这行时的错字。
  • 你不应该需要提供插件,因为你已经用 npm 安装了它。 webpack 会自动将下划线捆绑到你的主 javascript 包中,你的 javascript 文件将运行良好。但是这不应该影响打字稿

标签: typescript webpack visual-studio-code aurelia


【解决方案1】:

由于您使用的是 TypeScript,因此您还必须为下划线安装一个 *.d.ts 类型文件。尝试运行:

npm install --save @types/underscore

这让 TS 知道下划线模块及其接口。

Here's some more information about typings management with Typescript

【讨论】:

    猜你喜欢
    • 2012-02-23
    • 1970-01-01
    • 2012-04-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-22
    • 2011-11-06
    • 2015-12-05
    • 1970-01-01
    相关资源
    最近更新 更多