可以't导入捆绑文件

Can't import bundled file

本文关键字:文件 导入 可以      更新时间:2023-09-26

我在应用程序中执行此操作

System.import('lib/bootstrap.js').then(m => {
   this.socket = m.io("http://localhost:3000");
})

这是bootstrap.js

import io from 'socket.io-client';
export { io };

我通过jspm bundle lib/bootstrap.js outfile.js创建了一个捆绑包。

当我尝试System.import('outfile.js')时,解析的Promise m只是一个空对象。我在这里做错了什么?

System.import('outfile.js').then(m => {
   this.socket = m.io("http://localhost:3000");
})

您不希望导入捆绑文件。您需要做的是将捆绑包配置注入config.js文件。例如,添加jspm bundle lib/bootstrap bootstrap-bundle.js --inject将添加

"bundles": {
    "bootstrap-bundle": [
    "socket.io-client.js",
    "lib/bootstrap.js"
  ]
}

到您的config.js文件。然后你只需要像往常一样导入你的文件:

System.import('lib/bootstrap.js').then(m => {
   this.socket = m.io("http://localhost:3000");
})

请参阅此处的文档。