如何在Webpack中使用underscore.js

3

我希望在我的Typescript Aurelia应用程序中使用下划线。 我创建了一个typescript文件,在其中添加了以下内容:

import * as _ from 'underscore'

但是 VS Code 显示:

[ts] 找不到模块 'underscore'

我已将以下内容添加到 webpack.config 中:

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

我已经使用以下命令安装了underscore:

npm install --save underscore

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


这里有一个错别字:npm install --save undersocre。你是复制/粘贴的吗?还是只是在这里写错了? - Sergeon
我在这里写这行代码时打错了字。 - Luka
由于您已经使用npm安装了插件,因此您不需要使用provideplugin。webpack将自动将underscore打包到您的主JavaScript包中,并且您的JavaScript文件将正常运行。但是,这不应影响TypeScript。 - Andy Ray
1个回答

4

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接