繁体   English   中英

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

[英]Why can't I use the import syntax to import a coffeescript file from typescript

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

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

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

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

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

我可以回答一半。.我对babel,webpack和打字稿有点了解。
您需要进一步调查咖啡装载机。
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添加到index.html
  • 您可能需要在webpack.config.js中为咖啡脚本添加加载程序

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM