简体   繁体   中英

Can't import bundled file

I'm doing this in my application

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

This is bootstrap.js

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

I created a bundle via jspm bundle lib/bootstrap.js outfile.js .

When I try to System.import('outfile.js') the resolved Promise m is only an empty Object. What am I doing wrong here?

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

You don't want to import the bundled file. What you need to do is inject the bundle configuration to your config.js file. For example adding jspm bundle lib/bootstrap bootstrap-bundle.js --inject will add

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

to your config.js file. Then you just need to import your file as usual:

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

See the documentation here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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