简体   繁体   中英

Angular-CLI for Electron app

I am developing a desktop app with Electron and Angular2 (using Angular-Cli).

I wanted to use Bootstrap so in my angular-cli.json, I added the needed script files to apps[0].scripts like the following:

  "scripts": [
    "../node_modules/jquery/dist/jquery.min.js",
    "../node_modules/bootstrap/dist/js/bootstrap.min.js",
    "../node_modules/toastr/build/toastr.min.js"
  ],

When I run the app in web (using ng serve), everything is working fine. But when I run the app with Electron(ng build first, and run Electron from /dist), I encountered the following error: Uncaught Error: Bootstrap's JavaScript requires jQuery. Angular 2 parts are working fine, routing is working, views are rendered correctly, etc.

When I investigated scripts.bundle.js, those 3rd party libraries are included. But Bootstrap codes are before JQuery. Is that the reason why I am seeing the error with Electron?

   <script>
    try {
        window.nodeRequire = require;
        delete window.require;
        delete window.exports;
        delete window.module;
    } catch (e) {
    }
</script>

add this into index.html

For me it worked to install both jquery and @types/jquery and placing them in this order.

"scripts": [
    "../node_modules/jquery/dist/jquery.min.js",
    "../node_modules/bootstrap/dist/js/bootstrap.min.js"
],

~ HTH

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