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

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

问题描述

我有一个 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.coffee中,我在require其他咖啡文件中.喜欢:

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时遇到问题,并说:You may need an appropriate loader to handle this file type.

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 rel ="nofollow noreferrer"> 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,请在Webpack配置中使用以下方法扩展module.rules数组:

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中加载coffee脚本模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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