【问题标题】:How to import library-generated IIEF style JavaScript file?如何导入库生成的 IIEF 样式 JavaScript 文件?
【发布时间】:2017-05-12 09:21:31
【问题描述】:

有没有办法导入一些库生成的没有export 变量的代码?应该在tsconfig.json 文件中设置哪些module 选项?

文件

环境

示例

js-routes根据@​​987654327@生成如下代码:

/*
File generated by js-routes 1.3.3
Based on Rails routes of MyApplication
 */

(function() {
    ...
    return root.Routes;
  };

  if (typeof define === "function" && define.amd) {
    define([], function() {
      return createGlobalJsRoutesObject();
    });
  } else {
    createGlobalJsRoutesObject();
  }

}).call(this);

如果您以 'module=es2015' 样式导入,

import { Routes } from '../path/to//generated/js_routes';

tsc 警告:

[ts] File '/path/to/client/generated/js_routes.js' is not a module.

【问题讨论】:

    标签: ruby-on-rails typescript js-routes


    【解决方案1】:

    你可以尝试require该文件,看看它的输出是什么:

    import Routes = require('../path/to//generated/js_routes');
    

    【讨论】:

      猜你喜欢
      • 2017-11-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-03
      • 2010-12-27
      • 2016-11-06
      • 2020-06-06
      相关资源
      最近更新 更多