【问题标题】:Why can't I use the import syntax to import a coffeescript file from typescript为什么我不能使用导入语法从 typescript 导入咖啡脚本文件
【发布时间】:2017-07-06 00:24:52
【问题描述】:

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

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

但我必须以这种方式导入我的咖啡脚本文件:

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

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

【问题讨论】:

标签: node.js typescript coffeescript


【解决方案1】:

我可以回答一半。我对 babel、webpack 和 typescript 有点了解。
您需要进一步调查 coffee-loader。
https://github.com/webpack-contrib/coffee-loader

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

  • 首先在新的空项目文件夹中运行 npm init
  • npm install -g webpack
  • brew 安装 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 添加到 script 标签内的 index.html
  • 您可能需要在 webpack.config.js 中为您的咖啡脚本添加加载器

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-07-12
    • 1970-01-01
    • 1970-01-01
    • 2013-09-08
    • 1970-01-01
    • 1970-01-01
    • 2013-03-11
    • 2014-12-13
    相关资源
    最近更新 更多