在 Angular 中加载咖啡脚本模块 [英] Load coffee script module in Angular

查看:23
本文介绍了在 Angular 中加载咖啡脚本模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Angular-CLI 应用程序,我尝试引入第三方依赖项,该依赖项是用 Coffee Script 编写的.这就是我在组件中所做的:

I'm having a Angular-CLI application and I try to bring in a third party dependency in, which is written in Coffee Script. This is what I do in my component:

const CoffeeWidget = require('coffee-loader!CoffeeWidget');

我认为使用咖啡装载机会奏效.但不是真的.现在我可以读取 index.coffee,但是在我的 index.coffeerequire 其他咖啡文件.喜欢:

I thought using a coffee loader would work. But not really. Now I'm able to read the index.coffee, but in my index.coffee I require other coffee files. Like:

Cup = require '../tools/cup.coffee'

但是它在准备 cup.coffee 时遇到问题并说:你可能需要一个合适的加载器来处理这种文件类型.

But it has problems to ready the cup.coffee and says: You may need an appropriate loader to handle this file type.

有没有其他人遇到过这个问题?

Has anyone else faced this problem?

推荐答案

因为你使用 coffee-loader 直接进入你的 require 语句,webpack 将只在需要的文件上使用加载器.

Since you use coffee-loader directly into your require statement, webpack will use the loader just on the required file.

为了让 webpack 在任何深度找到的任何 .coffee 文件上使用 coffee-loader,扩展 module.rules 数组在你的webpack 配置:

In order let webpack use coffee-loader on any .coffee file found at any depth, extend the module.rules array in your webpack configuration with:

// Webpack 2 syntax

module.exports = {
  module: {
    rules: [
      {
        test: /\.coffee$/,
        use: [ 'coffee-loader' ]
      }
    ]
  }
}

这篇关于在 Angular 中加载咖啡脚本模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆