网站搜索

angular - 你可能需要一个合适的加载器来处理这种文件类型。Typescript


我正在尝试在这里使用 Typescript 类型定义来使用 YouTube Data API: https://github.com/Bolisov/typings-gapi/tree/master/gapi.client.youtube-v3

我正在使用 Ionic 框架,在使用以下代码行执行 Ionic Serve 后,我收到以下错误:

  gapi.client.load("client", "v3");

Module parse failed: /Users/yoko/Desktop/myApp/node_modules/gapi/lib/gapi.coffee Unexpected token (1:17)
You may need an appropriate loader to handle this file type.
| config = require './config'
| 
| module.exports = 

这就是 api.coffee 的样子

config = require './config'

module.exports =
  server:
    setApiKey: (apiKey) ->
      config.api.key = apiKey
    load: (apiName, apiVersion, callback) ->
      @[apiName] = require "./#{apiName}/#{apiVersion}"
      callback()

那是什么意思?

答案#1

假设你正在使用 Gulp,通过 npm 安装 CoffeeScript,然后通过以下方式将其添加到你的 package.json 中:

npm install gulp-coffee --save-dev #devDependencies

或者

npm install gulp-coffee --save #dependencies

然后将以下内容添加到你的 Gulpfile.js 中:

var coffee = require('gulp-coffee');
var paths =  { coffee: ['/Users/yoko/Desktop/myApp/node_modules/gapi/lib/*.coffee'] };

function coffeePipe(done) 
  {
  gulp.src(paths.coffee)
    .pipe(coffee({bare: true})
    .on('error', gutil.log.bind(gutil, 'Coffee Error')))
    .pipe(concat('application.js'))
    .pipe(gulp.dest('./www/js'))
    .on('end', done)
  }

gulp.task('coffee', coffeePipe);

参考文献

  • CoffeeScript-Ionic-Starter/gulpfile.js 在 master 分支 - StephenGrider/CoffeeScript-Ionic-Starter

  • Gulp.js 入门与实用示例 | Julien Renaux 博客

  • gulp-coffee

  • 05 - 使用 package.json | npm 文档

  • 快速提示:通过 leob 在 CodePen 上使用 gulp 自定义你的 Ionic 框架应用的 'serve'、'run' 和 'build' 过程

  • 修改 Ionic 2 Gulp 脚本以包含浏览器 JavaScript 文件

  • 与 Ionic 2 的 10 分钟:你好,世界 | 官方 Ionic 博客

  • 为什么你不应该在混合应用中使用 Ionic Serve