在Angular中加载咖啡脚本模块

时间:2017-04-26 06:31:10

标签: angular webpack coffeescript angular-cli

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

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

我以为使用咖啡装载机会起作用。但不是真的。现在我可以阅读index.coffee,但在我的index.coffeerequire其他咖啡文件中。像:

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

但准备好cup.coffee并说:You may need an appropriate loader to handle this file type.

时遇到问题

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

1 个答案:

答案 0 :(得分:3)

由于您coffee-loader直接使用coffee-loader,因此webpack将在所需文件上使用加载程序。

为了让webpack在任何深度找到的任何.coffee文件上使用module.rules,请使用以下命令扩展webpack配置中的// Webpack 2 syntax module.exports = { module: { rules: [ { test: /\.coffee$/, use: [ 'coffee-loader' ] } ] } } 数组:

@postconstruct