为什么我不能使用导入语法从typescript导入coffeescript文件

时间:2017-07-05 15:49:02

标签: node.js typescript coffeescript

我有一个打字稿文件,我正在导入各种打字稿文件,如下所示:

import ThingAMajig from '../../../libs/stuffs/ThingAMajig'; // a typescript file

但我必须以这种方式导入我的coffeescript文件:

const CoolThing = require('../../../libs/coolDir/CoolThing');

当我尝试使用导入语法时,出现错误error TS2307: Cannot find module

1 个答案:

答案 0 :(得分:0)

我可以半回答这个问题。我对babel,webpack和打字稿有所了解 您需要更多地研究咖啡装载机 https://github.com/webpack-contrib/coffee-loader

我以前习惯在Mac上使用brew 你也可以sudo npm安装webpack,
或者在Windows机器上以管理员身份执行。

  • 首先在新的空项目文件夹
  • 中运行npm init
  • npm install -g webpack
  • brew install webpack
  • npm install --save-dev babel-loader

webpack.config.js

module.exports =  {
    entry: '/scripts.js'
    output: {filename 'bundle.js'}
    module: {
       loaders: [
        {test: /\.js?/, loader: 'babel-loader', exclude: /node_modules}
    ]
    }
}
  • webpack - > bundle.js
  • 将bundle.js添加到脚本标记
  • 中的index.html
  • 您可能需要在webpack.config.js
  • 中添加咖啡脚本的加载器