How to import RequireJS (AMD) module in Angular 4.x (Angular Cli) App?

前端 未结 1 1708
眼角桃花
眼角桃花 2021-01-02 23:52

I have a legacy JS file, written in the following RequireJS (AMD) module notation:

define(\'mymodule\', [], function(){

    // ... bla bla bla

    return {         


        
相关标签:
1条回答
  • 2021-01-03 00:35

    I am able to load amd module.

    here is TS:

    import * as MyModule from './mymodule.js';
    
    console.log('my value is', MyModule.value);
    

    mymodule.js file:

    define(["require", "exports"], function(require, exports){
       exports.value = "aaa";
    });
    

    and in tsconfig.js

    "allowJs": true
    

    UPDATE:

    You can use System.import provided by webpack.

     declare var System: any; 
    
     System.import('./mymodule.js')
         .then(MyModule=>console.log(MyModule.value));
    
    0 讨论(0)
提交回复
热议问题